COBOL Interview Questions Answers PART 6
What is the use of EVALUATE statement?
Ans: Evaluate is like a case statement and can be used to replace nested Ifs. The difference between EVALUATE and case is that no ‘break’ is required for EVALUATE i.e. control comes out of the EVALUATE as soon as one match is made.
What is the difference between PERFORM ... WITH TEST AFTER and PERFORM ... WITH TEST BEFORE?
Ans: If TEST BEFORE is specified, the condition is tested at the beginning of each repeated execution of the specified PERFORM range. If TEST AFTER is specified, the condition is tested at the end of the each repeated execution of the PERFORM range. With TEST AFTER, the range is executed at least once.
Which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement?
Ans: TEST BEFORE
How do you code an in-line PERFORM?
Ans: PERFORM ... ... END-PERFORM.
When would you use in-line perform?
Ans: When the body of the perform will not be used in other paragraphs. If the body of the perform is a generic type of code (used from various other places in the program), it would be better to put the code in a separate Para and use PERFORM paraname rather than in-line perform.
In an EVALUTE statement is the order of the WHEN clauses significant?
Ans: Yes , evaluation of the when clause proceeds from top to bottom
How do you come out of an EVALUATE statement?
Ans: After the execution of one of the when clauses, the control is automatically passed on to the next sentence after the EVALUATE statement. There is no need of any extra code.
What is the default value(s) for an INITIALIZE and what keyword allows for an override of the default.
Ans: INITIALIZE sets spaces to alphabetic and alphanumeric fields. Initialize sets Zeroes to numeric fields. FILLER, OCCURS DEPENDING ON items are left untouched. The REPLACING option can be used to override these defaults.
What is SET TO TRUE all about, anyway?
Ans: In COBOL II the 88 levels can be set rather than moving their associated values to the related data item.
What is LENGTH in COBOL II?
Ans: LENGTH acts like a special register to tell the length of a group or an elementary item.
What is the function of a delimiter in STRING?
Ans: A delimiter in STRING causes a sending field to be ended and another to be started.
What is the function of a delimiter in UNSTRING?
Ans: A delimiter when encountered in the sending field causes the current receiving field to be switched to the next one indicated.
How will you count the number of characters in a null-terminated string?
Ans: MOVE 0 TO char-count
INSPECT null-terminated-string TALLYING char-count FOR CHARACTERS BEFORE X"00"
77 COUNTR PIC 9 VALUE ZERO.
01 DATA-2 PIC X(11). . .
INSPECT DATA-2
TALLYING COUNTR FOR LEADING "0"
REPLACING FIRST "A" BY "2" AFTER INITIAL "C"
If DATA-2 is 0000ALABAMA, what will DATA-2 and COUNTER be after the execution of INSPECT verb?
Ans: Counter=4. Data-2 will not change as the Initial 'C' is not found.
What kind of error is trapped by ON SIZE ERROR option?
Ans: Fixed-point overflow. Zero raised to the zero power.
Division by 0. Zero raised to a negative number.
A negative number raised to a fractional power.
What is the point of the REPLACING option of a copy statement?
Ans: REPLACING allows for the same copy to be used more than once in the same code by changing the replace value. COPY xxx REPLACING BY .
When is a scope terminator mandatory?
Ans: Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements. For readability, it's recommended coding practice to always make scope terminators explicit.
Can you use REDEFINES clause in the FILE SECTION?
Ans: No
Can I redefine an X(100) field with a field of X(200)?
Ans: Yes. Redefines just causes both fields to start at the same location. For example:01 WS-TOP PIC X(1)
01 WS-TOP-RED REDEFINES WS-TOP PIC X(2).
If you MOVE ‘12’ to WS-TOP-RED,
DISPLAY WS-TOP will show 1 while
DISPLAY WS-TOP-RED will show 12.
What is the use of EVALUATE statement?
Ans: Evaluate is like a case statement and can be used to replace nested Ifs. The difference between EVALUATE and case is that no ‘break’ is required for EVALUATE i.e. control comes out of the EVALUATE as soon as one match is made.
What is the difference between PERFORM ... WITH TEST AFTER and PERFORM ... WITH TEST BEFORE?
Ans: If TEST BEFORE is specified, the condition is tested at the beginning of each repeated execution of the specified PERFORM range. If TEST AFTER is specified, the condition is tested at the end of the each repeated execution of the PERFORM range. With TEST AFTER, the range is executed at least once.
Which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement?
Ans: TEST BEFORE
How do you code an in-line PERFORM?
Ans: PERFORM ... ... END-PERFORM.
When would you use in-line perform?
Ans: When the body of the perform will not be used in other paragraphs. If the body of the perform is a generic type of code (used from various other places in the program), it would be better to put the code in a separate Para and use PERFORM paraname rather than in-line perform.
In an EVALUTE statement is the order of the WHEN clauses significant?
Ans: Yes , evaluation of the when clause proceeds from top to bottom
How do you come out of an EVALUATE statement?
Ans: After the execution of one of the when clauses, the control is automatically passed on to the next sentence after the EVALUATE statement. There is no need of any extra code.
What is the default value(s) for an INITIALIZE and what keyword allows for an override of the default.
Ans: INITIALIZE sets spaces to alphabetic and alphanumeric fields. Initialize sets Zeroes to numeric fields. FILLER, OCCURS DEPENDING ON items are left untouched. The REPLACING option can be used to override these defaults.
What is SET TO TRUE all about, anyway?
Ans: In COBOL II the 88 levels can be set rather than moving their associated values to the related data item.
What is LENGTH in COBOL II?
Ans: LENGTH acts like a special register to tell the length of a group or an elementary item.
What is the function of a delimiter in STRING?
Ans: A delimiter in STRING causes a sending field to be ended and another to be started.
What is the function of a delimiter in UNSTRING?
Ans: A delimiter when encountered in the sending field causes the current receiving field to be switched to the next one indicated.
How will you count the number of characters in a null-terminated string?
Ans: MOVE 0 TO char-count
INSPECT null-terminated-string TALLYING char-count FOR CHARACTERS BEFORE X"00"
77 COUNTR PIC 9 VALUE ZERO.
01 DATA-2 PIC X(11). . .
INSPECT DATA-2
TALLYING COUNTR FOR LEADING "0"
REPLACING FIRST "A" BY "2" AFTER INITIAL "C"
If DATA-2 is 0000ALABAMA, what will DATA-2 and COUNTER be after the execution of INSPECT verb?
Ans: Counter=4. Data-2 will not change as the Initial 'C' is not found.
What kind of error is trapped by ON SIZE ERROR option?
Ans: Fixed-point overflow. Zero raised to the zero power.
Division by 0. Zero raised to a negative number.
A negative number raised to a fractional power.
What is the point of the REPLACING option of a copy statement?
Ans: REPLACING allows for the same copy to be used more than once in the same code by changing the replace value. COPY xxx REPLACING BY .
When is a scope terminator mandatory?
Ans: Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements. For readability, it's recommended coding practice to always make scope terminators explicit.
Can you use REDEFINES clause in the FILE SECTION?
Ans: No
Can I redefine an X(100) field with a field of X(200)?
Ans: Yes. Redefines just causes both fields to start at the same location. For example:01 WS-TOP PIC X(1)
01 WS-TOP-RED REDEFINES WS-TOP PIC X(2).
If you MOVE ‘12’ to WS-TOP-RED,
DISPLAY WS-TOP will show 1 while
DISPLAY WS-TOP-RED will show 12.