COBOL Online Quiz


Following quiz provides Multiple Choice Questions (MCQs) related to COBOL Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - What is the mode in which you will OPEN a file for writing?

A - OUTPUT

B - EXTEND

C - Either OUTPUT or EXTEND

D - INPUT-OUTPUT

Answer : C

Explanation

To write into a file, the file has to be opened in either OUTPUT or EXTEND mode.

Q 2 - Which cobol verb is used for updating a file?

A - READ

B - WRITE

C - UPDATE

D - REWRITE

Answer : D

Explanation

Rewrite verb is used to update the records. File should be opened in I-O mode for rewrite operations. It can be used only after a successful Read operation. Rewrite verb overwrites the last record read.

Q 3 - Which of the numeric literal is invalid?

A - 100

B - 10.9-

C - -10.9

D - 10.9

Answer : B

Explanation

10.9- is invalid because sign can not be mentioned on the right.

Q 4 - Which of the following word cannot be a user-defined COBOL word?

A - WS-ACCEPT

B - ACCEPT

C - WS-DISPLAY

D - TUTORIAL

Answer : B

Explanation

ACCEPT cannot be a user defined COBOL word as we cannot use COBOL reserved words.

Q 5 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-DESCRIPTION.
   05 WS-DATE1 VALUE '20140831'.
   10 WS-YEAR PIC X(4).
   10 WS-MONTH PIC X(2).
   10 WS-DATE PIC X(2).
   05 WS-DATE2 REDEFINES WS-DATE1 PIC 9(8).

PROCEDURE DIVISION.
   DISPLAY WS-DATE2.

STOP RUN.

A - 00000000

B - 20140831

C - Compilation error

D - Run time error

Answer : B

Explanation

When we redefine WS-DATE1 to WS-DATE2, automatically values from WS-DATE1 will be moved to WS-DATE2.

You can try same code using Try it option available below:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-DESCRIPTION.
   05 WS-DATE1 VALUE '20140831'.
   10 WS-YEAR PIC X(4).
   10 WS-MONTH PIC X(2).
   10 WS-DATE PIC X(2).
   05 WS-DATE2 REDEFINES WS-DATE1 PIC 9(8).

PROCEDURE DIVISION.
   DISPLAY WS-DATE2.

STOP RUN.

Q 6 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-A PIC 9 VALUE 2.
   
PROCEDURE DIVISION.
   A-PARA.
   DISPLAY 'A'
   GO TO B-PARA.
   
   B-PARA.
   DISPLAY 'B'.
   GO TO C-PARA D-PARA DEPENDING ON WS-A.
   
   C-PARA.
   DISPLAY 'C'.
   
   D-PARA.
   DISPLAY 'D'.
   STOP RUN.

A - ABCD

B - ABD

C - BADC

D - DCBA

Answer : B

Explanation

This is to show how control goes from one GOTO statement to other. Go step by step you will understand the flow. From B-para control will go to D-para as value in WS-A is 2, so it will go to the 2nd para which is mentioned in the GOTO statement.

You can try same code using Try it option available below:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-A PIC 9 VALUE 2.
   
PROCEDURE DIVISION.
   A-PARA.
   DISPLAY 'A'
   GO TO B-PARA.
   
   B-PARA.
   DISPLAY 'B'.
   GO TO C-PARA D-PARA DEPENDING ON WS-A.
   
   C-PARA.
   DISPLAY 'C'.
   
   D-PARA.
   DISPLAY 'D'.
   STOP RUN.

Q 7 - Rewrite verb is used to update the records. File should be opened in I-O mode for rewrite operations. It can be used even if read operation is not successful. Is this statement true or false?

A - True

B - False

Answer : B

Explanation

This statement is incorrect as the read operation should be successful before doing rewrite operation..

Q 8 - Which option is used in Inspect verb to replace the string characters?

A - Count

B - Tallying

C - Replacing

D - Add

Answer : C

Explanation

Replacing option is used to replace the string characters.

Answer : A

Explanation

Procedure division is used to include the logic of the program. It consists of executable statements using variables defined in the data division. In this division, paragraph and section names are user-defined.

Q 10 - What is the length of PIC S9(7)V99 COMP-3?

A - 10

B - 9

C - 4

D - 5

Answer : D

Explanation

(9+1)/2 = 5 bytes.

cobol_questions_answers.htm
Advertisements