Wednesday, May 23, 2012

Cobol Interview Questions 2

In an EVALUATE statement, can I give a complex condition on a when clause ?
Yes.

What is a scope terminator ?
Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE; IF, END-IF.

How do you do in-line PERFORM ?
PERFORM ... ... END-PERFORM

When would you use in-line perform ?
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 Para name rather than in-line perform.

What is the difference between CONTINUE & NEXT SENTENCE ?
They appear to be similar, that is, the control goes to the next sentence in the paragraph. But, Next Sentence would take the control to the sentence after it finds a full stop (.). Check out by writing the following code example, one if sentence followed by 3 display statements (sorry they appear one line here because of formatting restrictions) If 1 > 0 then next sentence end if display 'line 1' display 'line 2'. display 'line 3'. *** Note- there is a dot (.) only at the end of the last 2 statements, see the effect by replacing Next Sentence with Continue ***

What does EXIT do ?
Does nothing ! If used, must be the only sentence within a paragraph.

Can I redefine an X(100) field with a field of X(200) ?
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.

Can I redefine an X(200) field with a field of X(100) ?
Yes.

What do you do to resolve SOC-7 error ?
Basically you need to correcting the offending data. Many times the reason for SOC7 is an un-initialized numeric item. Examine that possibility first. Many installations provide you a dump for run time abend’s ( it can be generated also by calling some subroutines or OS services thru assembly language).
These dumps provide the offset of the last instruction at which the abend occurred. Examine the compilation output XREF listing to get the verb and the line number of the source code at this offset. Then you can look at the source code to find the bug. To get capture the runtime dumps, you will have to define some datasets (SYSABOUT etc ) in the JCL. If none of these are helpful, use judgement and DISPLAY to localize the source of error. Some installation might have batch program debugging tools. Use them.

How is sign stored in Packed Decimal fields and Zoned Decimal fields ?
Packed Decimal fields: Sign is stored as a hex value in the last nibble (4 bits ) of the storage. Zoned Decimal fields: As a default, sign is over punched with the numeric value stored in the last bite.

How is sign stored in a comp-3 field ?
It is stored in the last nibble. For example if your number is +100, it stores hex 0C in the last byte, hex 1C if your number is 101, hex 2C if your number is 102, hex 1D if the number is -101, hex 2D if the number is -102 etc...

How is sign stored in a COMP field ?
In the most significant bit. Bit is ON if -ve, OFF if +ve.

What is the difference between COMP & COMP-3 ?
COMP is a binary storage format while COMP-3 is packed decimal format.

What is COMP-1 ? COMP-2 ?
COMP-1 - Single precision floating point. Uses 4 bytes. COMP-2 - Double precision floating point. Uses 8 bytes.

How do you define a variable of COMP-1 ? COMP-2 ?
No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.

How many bytes does a S9(7) COMP-3 field occupy ?
Will take 4 bytes. Sign is stored as hex value in the last nibble. General formula is INT((n/2) + 1)), where n=7 in this example.

How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?
Will occupy 8 bytes (one extra byte for sign).

How many bytes will a S9(8) COMP field occupy ?
4 bytes.

No comments:

Post a Comment