COBOL Realtime (Scenario based) Interview Questions (31 - 40)
31. What is the length of variables declared as S9(06) COMP and S9(08) COMP?
S9(06) COMP occupies 4 bytes which is same as S9(08) COMP. It has the difference only in the value. i.e., S9(08) can store bigger value than S9(06).
32. I have declared a variable as shown below. What is the length of the variable?
01 WS-A USAGE IS COMP-1.
WS-A will occupy 4 bytes in memory. A COMP-1 variable always takes 4 bytes, regardless of the numeric value stored.
33. I have declared a variable as shown below. What is the length of the variable?
01 WS-A USAGE IS COMP-2.
WS-A will occupy 8 bytes in memory. A COMP-2 variable always takes 8 bytes, regardless of the numeric value stored.
34. What is the length of variables declared as 9(07) COMP-3 and 9(08) COMP-3?
9(07) COMP-3 → 4 bytes (7/2=3.5 bytes. i.e., rounded value 4 bytes) and 9(08) COMP-3 → 4 bytes (8/2=4 bytes).
35. What is the length of variable declared as S9(07) COMP-3?
S9(07) COMP-3 → 4 bytes. i.e., (7+1)/2=4 bytes. 7 bytes is for numeric and 1 byte is for sign.
36. What is the length of variable declared as S9(07) COMP-3 SIGN IS LEADING SEPARATE CHARACTER?
S9(07) COMP-3 → 4 bytes. i.e., (7+1)/2=4 bytes. 7 bytes is for numeric and 1 byte is for sign. SIGN IS LEADING SEPARATE CHARACTER makes no difference in COMP-3.
37. What is the output of the below code?
...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-NAME PIC X(20).
...
PROCEDURE DIVISION.
* Receiving name from JCL
ACCEPT WS-NAME.
...
DISPLAY WS-NAME.
//MATEPKRJ JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID //** //STEP01 EXEC PGM=ACCPTST //STEPLIB DD DSN=MATEPK.COBOL.LOADLIB,DISP=SHR //SYSIN DD * PAWAN 10 /*Ans:
PAWAN
"PAWAN" is stored in WS-NAME. The second line "10" is not read and ignored.
38. What is the output of the below code?
...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAL PIC 9(03).
...
PROCEDURE DIVISION.
MOVE 99000
TO WS-VAL.
...
DISPLAY WS-VAL.
Ans: 000
Since WS-VAL can store only 3 digits, the leftmost digits (99) are truncated, and only 000 is stored and displayed.
39. What is the output of the below code?
...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NAME PIC X(10).
...
PROCEDURE DIVISION.
MOVE "MAINFRAMES ARE LEGACY"
TO WS-NAME.
...
DISPLAY WS-NAME.
Ans: MAINFRAMES
Since WS-NAME is only 10 bytes long, the extra characters are truncated, and only "MAINFRAMES" is displayed.
40. What is the output of the below code?
...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NAME PIC X(10) JUSTIFIED RIGHT.
...
PROCEDURE DIVISION.
MOVE "MAINFRAMES IS LEGACY"
TO WS-NAME.
...
DISPLAY WS-NAME.
Ans: S IS LEGACY
Since WS-NAME is right-justified and limited to 10 characters, the rightmost 10 characters of the original string ("S IS LEGACY") are stored and displayed.