COBOL Realtime (Scenario based) Interview Questions (41 - 50)

41. What is the output of the below code?

       ...
       WORKING-STORAGE SECTION. 
       01 WS-SALARY         PIC 9(04) VALUE 6000.
       ...
       PROCEDURE DIVISION.
           ACCEPT WS-SALARY.
           IF WS-SALARY GREATER THAN 5000
              CONTINUE
           ELSE
              COMPUTE WS-SALARY = WS-SALARY + 2000
           END-IF.
		   COMPUTE WS-SALARY = WS-SALARY + 3000.
           DISPLAY "SALARY: " WS-SALARY. 
           ...
Ans:
SALARY: 9000

42. What is the output of the below code?

       ...
       WORKING-STORAGE SECTION. 
       01 WS-SALARY         PIC 9(04) VALUE 6000.
       ...
       PROCEDURE DIVISION.
           ACCEPT WS-SALARY.
           IF WS-SALARY GREATER THAN 5000
              NEXT SENTENCE
           ELSE
              COMPUTE WS-SALARY = WS-SALARY + 2000
           END-IF 
		   COMPUTE WS-SALARY = WS-SALARY + 3000.
           DISPLAY "SALARY: " WS-SALARY. 
           ...
Ans:
SALARY: 6000

43. What is the output of the below code?

       ...
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-I         PIC 9(01) VALUE 1.

       PROCEDURE DIVISION.
           PERFORM UNTIL WS-I = 1
              DISPLAY "Iteration: " WS-I
           END-PERFORM.
		   ...

No information to display because condition validation occurs before executing the loop statements.

44. What is the output of the below code?

       ...
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-I         PIC 9(01) VALUE 1.

       PROCEDURE DIVISION.
           PERFORM UNTIL WS-I = 1
              DISPLAY "Iteration: " WS-I
           END-PERFORM.
		   ...
Iteration: 1

The condition was validated after the loop statements were executed for atleast one time.

45. What is the output of the below code?

       ...
	   DATA DIVISION. 
       WORKING-STORAGE SECTION.
       01 WS-CLASS.
          03 WS-STUDENT  OCCURS 2 TIMES INDEXED BY WS-IDX.
             05 WS-ROLL-NO      PIC X(03).
             05 WS-NAME         PIC X(10).
       ...
       PROCEDURE DIVISION.

		   SET WS-IDX          TO 1.
		   MOVE "001PAWAN Y"   TO WS-STUDENT(WS-IDX).
		   SET WS-IDX          UP BY 1.
		   MOVE "002KUMAR"     TO WS-STUDENT(WS-IDX).

           PERFORM VARYING WS-IDX FROM 1 BY 1 UNTIL WS-IDX > 3  
                   DISPLAY "STUDENT - " WS-STUDENT(WS-IDX)
           END-PERFORM.
           ...
STUDENT - 001PAWAN Y 
STUDENT - 002KUMAR

With SSRANGE enabled, the program will abend on WS-IDX = 3 (out-of-bounds). With NOSSRANGE enabled, behavior is unpredictable (may print garbage or crash).

46. What is the output of the below code?

       ...
       WORKING-STORAGE SECTION.
       01 WS-ORG.
          03 WS-EMPLOYEE OCCURS 6 TIMES 
                         INDEXED BY IDX-EMP.   
             05 WS-EMPLOYEE-NUM       PIC X(05).   
       ...
       PROCEDURE DIVISION.
           MOVE 'E0005E0002E0004E0001E0007'
  		     TO WS-ORG.

           SET IDX-EMP         TO 4.
           SEARCH WS-EMPLOYEE VARYING IDX-EMP 
               AT END DISPLAY "Employee not found"
             WHEN WS-EMPLOYEE-NUM(IDX-EMP) = 'E0002'
                  DISPLAY "Employee found"
           END-SEARCH.
		   ...
Employee not found

Search starting index (IDX-EMP = 4)

47. What is the output of the below code?

       ...
       WORKING-STORAGE SECTION.
       01 WS-ORG.
          03 WS-EMPLOYEE OCCURS 6 TIMES 
                         INDEXED BY IDX-EMP.   
             05 WS-EMPLOYEE-NUM       PIC X(05).   
       ...
       PROCEDURE DIVISION.
           MOVE 'E0001E0002E0004E0005E0007'
  		     TO WS-ORG.

           SEARCH ALL WS-EMPLOYEE
               AT END DISPLAY "Employee not found"
             WHEN WS-EMPLOYEE-NUM(IDX-EMP) = 'E0006'
                  DISPLAY "Employee found"
           END-SEARCH.
		   ...
Employee not found

48. What is the output of the below code?

01 WS-A   PIC X(15) VALUE 'MAINFRAMESTECHHELP'.
01 WS-B REDEFINES WS-A PIC X(10).
...
PROCEDURE DIVISION.
    DISPLAY WS-B.
MAINFRAMES

49. What is the output of the below code?

01 WS-A   PIC X(15) VALUE 'MAINFRAMESTECHHELP'.
01 WS-B REDEFINES WS-A PIC X(20).
...
PROCEDURE DIVISION.
    DISPLAY WS-B.
MAINFRAMESTECHHELP    

50. What are the file open modes for writing the sequential files?

OUTPUT mode for writing operations only. If a file already exists, its contents overwritten. EXTENDFor appending records to an existing file. It applies for sequential access files only.