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 - How is sign stored in a COMP-3 field?

A - First Bit

B - Last Bit

C - First Nibble

D - Last Nibble

Answer : D

Explanation

In COMP-3 field, sign is stored in last nibble.

Q 2 - Can I redefine an X(10) field with a field of X(20)?

A - No

B - Yes

Answer : B

Explanation

Yes we can define a X(10) to X(20) as Redefines causes both fields to start at the same location, but it is not a good coding practice.

Q 3 - What is the position of Area A in COBOL program?

A - 1-6 Columns

B - 8-11 Columns

C - 12-72 Columns

D - 72-80 Columns

Answer : B

Explanation

Area A starts from 8 to 11 column. All COBOL divisions, sections, paragraphs and some special entries must begin in Area A.

Q 4 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM1 PIC X(4) VALUE '15AB'.
   
PROCEDURE DIVISION.
   MOVE 'XXXX' TO WS-NUM1
   DISPLAY WS-NUM1.
STOP RUN.

A - 15AB

B - XXXX

C - Compilation error

D - Run time error

Answer : B

Explanation

Value of WS-NUM1 will be displayed. While declaring the WS-NUM1 variable we have set the value as '15AB' but in the procedure division we have moved 'XXXX' value in WS-NUM1. So XXXX value is displayed.

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

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM1 PIC X(4) VALUE '15AB'.
   
PROCEDURE DIVISION.
   MOVE 'XXXX' TO WS-NUM1
   DISPLAY WS-NUM1.
STOP RUN.

Q 5 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM1 PIC 9(9) VALUE 10 .
   01 WS-NUM2 PIC 9(9) VALUE 10.
   01 WS-NUM3 PIC 9(9) VALUE 10.
   01 WS-NUMA PIC 9(9) VALUE 50.
   01 WS-NUMB PIC 9(9) VALUE 10.
   01 WS-NUMC PIC 9(3).

PROCEDURE DIVISION.
   COMPUTE WS-NUMC= (WS-NUM1 * WS-NUM2) - (WS-NUMA / WS-NUMB) + WS-NUM3.
   DISPLAY WS-NUMC

STOP RUN.

A - 100

B - 105

C - Compilation error

D - Run time error

Answer : B

Explanation

This is simple example to show the use of Compute statement.

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

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM1 PIC 9(9) VALUE 10 .
   01 WS-NUM2 PIC 9(9) VALUE 10.
   01 WS-NUM3 PIC 9(9) VALUE 10.
   01 WS-NUMA PIC 9(9) VALUE 50.
   01 WS-NUMB PIC 9(9) VALUE 10.
   01 WS-NUMC PIC 9(3).

PROCEDURE DIVISION.
   COMPUTE WS-NUMC= (WS-NUM1 * WS-NUM2) - (WS-NUMA / WS-NUMB) + WS-NUM3.
   DISPLAY WS-NUMC

STOP RUN.

Q 6 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-CNT PIC 9(2) VALUE 0.
   01 WS-STRING PIC X(15) VALUE 'AABCDACDAAEAAAF'.
   
PROCEDURE DIVISION.
   INSPECT WS-STRING TALLYING WS-CNT FOR ALL 'A'.
   DISPLAY WS-CNT
   
STOP RUN.

A - 09

B - 06

C - 08

D - 10

Answer : C

Explanation

Inspect statement will count the number of 'A' in the string and will put the value in WS-CNT.

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

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-CNT PIC 9(2) VALUE 0.
   01 WS-STRING PIC X(15) VALUE 'AABCDACDAAEAAAF'.
   
PROCEDURE DIVISION.
   INSPECT WS-STRING TALLYING WS-CNT FOR ALL 'A'.
   DISPLAY WS-CNT
   
STOP RUN.

Q 7 - How records are stored & accessed in sequential file organization?

A - Relative address method

B - Sequential access method

C - Direct access method

D - Both B & C

Answer : B

Explanation

A sequential file consists of records that are stored and accessed in sequential order.

Q 8 - In which usage, data item is similar to Real or Float and is represented as a single precision floating point number and internally data is stored in hexadecimal format?

A - COMP

B - COMP-3

C - COMP-2

D - COMP-1

Answer : D

Explanation

COMP-1 is represented as a single precision floating point number and data is internally stored in hexadecimal format.

Q 9 - In which mode you will open the sequential file to append the data in the end.

A - APPEND

B - INPUT

C - OUTPUT

D - EXTEND

Answer : D

Explanation

Sequential file is opened in Extend mode to append the data at the end. If you will open the file in Output mode it will delete all the existing data and then write the data.

Q 10 - What is the length of a variable when usage is COMP-2?

A - 2

B - 16

C - 4

D - 8

Answer : D

Explanation

COMP-2 takes 8 bytes of storage.

cobol_questions_answers.htm
Advertisements