COBOL Interview questions
Q. Explain why we can not define occurs clause at 01 level.
A. 01 is of the record level. We repeat the fields within a record not the record itself. So occurs clause can not be used at 01 level.
Q. Explain IS NUMERIC Clause.
A. IS NUMERIC Clause is used to check if any item is numeric or not. It returns TRUE when the item against which it is used contains only numbers(0 to 9). The item can be +ve or -ve. IS NUMERIC can be used against Numeric, Alpha Numeric, Packed Decimal fields whether signed or not.
Q. Explain internal Sort and External Sort.
A. Internal Sort:
SORT file-1 ON ASCENDING/DESCENDING KEY key[,key1,….] USING file-2 GIVING file-3.
USING can be substituted by INPUT PROCEDURE IS para-1 THRU para-2
GIVING can be substituted by OUTPUT PROCEDURE IS para-1 THRU para-2.
file-1 is the sort (work) file and must be defined as SD entry in FILE SECTION.
file-2 is the input file for the SORT and must be defined as FD entry in FILE SECTION
file-3 is the out file from the SORT and must be defined as FD entry in FILE SECTION.
file-1, file-2 & file-3 should not be opened explicitly.
INPUT PROCEDURE is executed before the sort and records must be RELEASED to the sort work file from the input procedure.
OUTPUT PROCEDURE is executed after all records have been sorted. Records from the sort work file must be RETURNED one at a time to the output procedure.
External sort is the one which is coded in JCL. External sort is more efficient.
Q. Explain difference between CONTINUE and NEXT SENTENCE.
A. Continue transfers the control to next statement after the scope terminator. Next sentence transfers the control to statement after the first period encountered.
Q. Can I redefine X(10) with X(20). What happens if I do so?
01 WS-1 PIC X(10).
01 WS-2 REDEFINES WS-1 PIC X(20).
MOVE ‘MY NAME IS MAINFRAME’ TO WS-2.
The above statement displays ‘MY NAME IS’
The above statement displays ‘MY NAME IS MAINFRAME’
Q. What is the difference between subscript and index?
A. Subsricpt is the occurrence in the array. Index is the displacement of the from the
beginning in the array.
Q. What is COMP COMP-1 COMP-2 and COMP-3? How do we define COMP fields? How much storage is taken for each of them?
A. COMP is Binary storage format. The COMP field can be defined as
01 WS-COMP-FIELD PIC 9(04) COMP.
The Storage taken by COMP field depends on length of the field.
0 to 4 field length – 2 bytes
5 to 9 field length – 4 bytes
10 to 18 field length – 8 bytes
COMP-1 is single precision floating point. COMP-1 uses 4 bytes of storage. No
picture clause should be given while defining the COMP-1 fields.
01 WS-COMP-1-FIELD USAGE IS COMP-1.
COMP-2 is double precision floating point. COMP-2 uses 8 bytes of storage. No
picture clause should be given while defining the COMP-2 fields.
01 WS-COMP-2-FIELD USAGE IS COMP-2.
COMP-3 is packed decimal format. COMP-3 uses storage depends on the length of
the field. Integer of ((n/2)+1). Sign is stored in the last nibble of storage.
01 WS-COMP-3-FIELD PIC S9(07) USAGE IS COMP-3.
Here WS-COMP-3-FIELD occupies (integer of (7/2) +1)) = 4 bytes.
Q. How do you code inline perform?
A. PERFORM PARAGRAPH-1 UNTIL condition
Sentence 1… [sentence 2 ….]
Q. File opening modes in COBOL.
A. INPUT, OUTPUT, I-O and EXTEND
Q. Explain SOC4 and SOC7
A. SOC4 and SOC7 are the abends.
SOC4 occurs because of the storage violation. For example SOC4 occurs when we try to access the undefined array occurrence.
SOC 7 is data violation. For example SOC7 occurs when we try to move non numeric data to a numeric field.
Q. What happens when we pass a table with index through linkage section?
A. The index is lost. The index on the table is specific to only the working storage of the calling program.
Q. Can we expect the same results after changing the order of WHEN Clause in an evaluate statements
A. No. The results may change as the EVALUATE statement executes the when clause in sequential order.
Q. Explain INITIALIZE verb
A. INITIALIZE when used moves spaces to Alphabetic and Alphanumeric fields. Moves zero to Numeric fields. Filler values are unchanged.
Q. What is Scope terminator
A. Scope terminator is one which indicates the end of a particular statement.
Example: END-IF, END-EVALUATE, END-PERFORM ….
Mandatory Scope terminators are
END-PERFORM for inline PERFORM and
END-EVALUATE for EVALUATE statement.
Q. What is the difference between SEARCH and SEARCH ALL
A. SEARCH is a sequential search and SEARCH ALL is binary Search. SEARCH ALL is more efficient.
Q. What is the maximum size of a numeric field we can define in COBOL
A. PIC 9(18).