COBOL Mock Test



This section presents you various set of Mock Tests related to COBOL Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

COBOL Mock Test II

Q 1 - What is the position of Area B in COBOL program?

A - 1-6 Columns

B - 8-11 Columns

C - 12-72 Columns

D - 72-80 Columns

Answer : C

Explanation

Area B start from 12 to 72 column. All COBOL statements must begin in area B.

Q 2 - 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.

Answer : B

Explanation

Coding asterisk (*) at 7th column comments out the complete line in COBOL program.

Q 4 - Which of the alphanumeric literal is invalid?

A - 'COBOL12'

B - "COBOL12"

C - "COBOL''12"

D - 'COBOL12"

Answer : D

Explanation

'COBOL12" is invalid because inverted commas should be in pair and should be of same type.

Q 5 - 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 6 - 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 7 - Which level number we should use for RENAMES clause?

A - 77

B - 49

C - 66

D - 88

Answer : C

Explanation

66 level number is used for RENAMES.

Q 8 - Which level number we should use for conditions?

A - 77

B - 88

C - 01

D - 66

Answer : B

Explanation

88 level number is used for defining condition name entries.

Q 9 - 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 10 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-ID PIC 9(5).
   
PROCEDURE DIVISION.
   A000-FIRST-PARA.
   INITIALIZE WS-ID REPLACING NUMERIC DATA BY 12345.
   DISPLAY WS-ID.
   
STOP RUN.

A - 00000

B - 12345

C - Spaces

D - Compilation error

Answer : B

Explanation

WS-ID will be initialized and numeric data will be replaced by 12345 as mentioned in the statement.

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

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-ID PIC 9(5).
   
PROCEDURE DIVISION.
   A000-FIRST-PARA.
   INITIALIZE WS-ID REPLACING NUMERIC DATA BY 12345.
   DISPLAY WS-ID.
   
STOP RUN.

Q 11 - What is the output of the following code?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM1 PIC 9(9).
   01 WS-NUM2 PIC 9(6).
   
PROCEDURE DIVISION.
   A000-FIRST-PARA.
   MOVE 123456789 TO WS-NUM1.
   MOVE WS-NUM1(3:6) TO WS-NUM2.
   
   DISPLAY WS-NUM2
   
STOP RUN.

A - 456789

B - 000000

C - 123456

D - 345678

Answer : D

Explanation

WS-NUM1(3:6) indicates that select from 3rd column & up to 6 digits. So result will 345678.

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).
   01 WS-NUM2 PIC 9(6).
   
PROCEDURE DIVISION.
   A000-FIRST-PARA.
   MOVE 123456789 TO WS-NUM1.
   MOVE WS-NUM1(3:6) TO WS-NUM2.
   
   DISPLAY WS-NUM2
   
STOP RUN.

Q 12 - Moving a Numeric field to Alphabetic is legal?

A - Yes

B - No

Answer : B

Explanation

Moving a numeric field to alphabetic field is illegal in COBOL. It will throw error.

Q 13 - Moving a Alphabetic field to Numeric is legal?

A - Yes

B - No

Answer : B

Explanation

Moving a alphabetic field to numeric field is illegal in COBOL. It will throw error.

Q 14 - Moving a Numeric field to Alphanumeric is legal?

A - Yes

B - No

Answer : A

Explanation

Moving a numeric field to alphanumeric is legal in COBOL.

Q 15 - Moving a Alphabetic field to Alphanumeric is legal?

A - Yes

B - No

Answer : A

Explanation

Moving a alphabetic field to alphanumeric is legal in COBOL.

Q 16 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUMA PIC 9(9) VALUE 10.
   01 WS-NUMB PIC 9(9) VALUE 10.
   01 WS-NUMC PIC 9(9) VALUE 10.
   01 WS-NUMD PIC 9(9) VALUE 100.
   01 WS-NUME PIC 9(9) VALUE 10.

PROCEDURE DIVISION.
   SUBTRACT WS-NUMA WS-NUMB WS-NUMC FROM WS-NUMD GIVING WS-NUME.
   DISPLAY WS-NUME.

STOP RUN.

A - 000000100

B - 000000090

C - 000000070

D - 000000080

Answer : C

Explanation

The formula will be like (WS-NUME = WS-NUMD - WS-NUMA - WS-NUMB - WS-NUMC).

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

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUMA PIC 9(9) VALUE 10.
   01 WS-NUMB PIC 9(9) VALUE 10.
   01 WS-NUMC PIC 9(9) VALUE 10.
   01 WS-NUMD PIC 9(9) VALUE 100.
   01 WS-NUME PIC 9(9) VALUE 10.

PROCEDURE DIVISION.
   SUBTRACT WS-NUMA WS-NUMB WS-NUMC FROM WS-NUMD GIVING WS-NUME.
   DISPLAY WS-NUME.

STOP RUN.

Q 17 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUMA PIC 9(9) VALUE 100.
   01 WS-NUMB PIC 9(9) VALUE 15.
   01 WS-NUMC PIC 9(2).
   01 WS-REM PIC 9(2). 

PROCEDURE DIVISION.
   DIVIDE WS-NUMA BY WS-NUMB GIVING WS-NUMC REMAINDER WS-REM.
   DISPLAY WS-NUMC ', ' WS-REM
   
STOP RUN.

A - 06, 10

B - 10, 06

C - Error

D - 100, 15

Answer : A

Explanation

Formula will be like WS-NUMC = NUMA/NUMB and remainder will be stored in WS-REM.

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

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUMA PIC 9(9) VALUE 100.
   01 WS-NUMB PIC 9(9) VALUE 15.
   01 WS-NUMC PIC 9(2).
   01 WS-REM PIC 9(2). 

PROCEDURE DIVISION.
   DIVIDE WS-NUMA BY WS-NUMB GIVING WS-NUMC REMAINDER WS-REM.
   DISPLAY WS-NUMC ', ' WS-REM
   
STOP RUN.

Q 18 - 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 19 - 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 20 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-DESCRIPTION.
   05 WS-NUM.
   10 WS-NUM1 PIC 9(2) VALUE 20.
   10 WS-NUM2 PIC 9(2) VALUE 56.
   05 WS-CHAR.
   10 WS-CHAR1 PIC X(2) VALUE 'AA'.
   10 WS-CHAR2 PIC X(2) VALUE 'BB'.
   10 WS-RENAME RENAMES WS-NUM2 THRU WS-CHAR2.

PROCEDURE DIVISION.
   DISPLAY "WS-RENAME : " WS-RENAME.
   
STOP RUN.

A - 56AABB

B - Compilation Error

C - Space

D - Zeroes

Answer : B

Explanation

This program will give compilation error as Renames should be defined at 66 level number.

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-NUM.
   10 WS-NUM1 PIC 9(2) VALUE 20.
   10 WS-NUM2 PIC 9(2) VALUE 56.
   05 WS-CHAR.
   10 WS-CHAR1 PIC X(2) VALUE 'AA'.
   10 WS-CHAR2 PIC X(2) VALUE 'BB'.
   10 WS-RENAME RENAMES WS-NUM2 THRU WS-CHAR2.

PROCEDURE DIVISION.
   DISPLAY "WS-RENAME : " WS-RENAME.
   
STOP RUN.

Q 21 - How many bytes S9(6) USAGE IS COMP will take?

A - 6

B - 4

C - 3

D - 2

Answer : B

Explanation

S9(6) USAGE is COMP will take 4 bytes based on the following formula which is used to calculate when USAGE is COMP :
S9(n) USAGE is COMP
If 'n' = 1 to 4, it takes 2 bytes.
If 'n' = 5 to 9, it takes 4 bytes.
If 'n' = 10 to 18, it takes 8 bytes.

Q 22 - How many bytes S9(6) USAGE IS COMP-3 will take?

A - 6

B - 3

C - 4

D - 7

Answer : B

Explanation

S9(6) USAGE is COMP-3 will take 3 bytes based on the following formula which is used to calculate when USAGE is COMP-3 :
S9(n) USAGE is COMP-3
Number of bytes = n/2 (If n is even)
Number of bytes = n/2 + 1(If n is odd, consider only integer part)

Q 23 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM1 PIC 9(9).
   01 WS-NUM2 PIC 9(9).
   
PROCEDURE DIVISION.
   A000-FIRST-PARA.
   MOVE 25 TO WS-NUM1 
   MOVE 15 TO WS-NUM2 
   
   IF WS-NUM1 > WS-NUM2 THEN
      DISPLAY 'IN LOOP 1 - IF BLOCK'
   ELSE
      DISPLAY 'IN LOOP 1 - ELSE BLOCK'
   END-IF.
   
STOP RUN.

A - IN LOOP 1 - ELSE BLOCK

B - IN LOOP 1 - IF BLOCK

C - Error

D - None of these

Answer : B

Explanation

WS-NUM1 is greater than WS-NUM2, so condition is satisfied and it will to IF loop.

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).
   01 WS-NUM2 PIC 9(9).
   
PROCEDURE DIVISION.
   A000-FIRST-PARA.
   MOVE 25 TO WS-NUM1 
   MOVE 15 TO WS-NUM2 
   
   IF WS-NUM1 > WS-NUM2 THEN
      DISPLAY 'IN LOOP 1 - IF BLOCK'
   ELSE
      DISPLAY 'IN LOOP 1 - ELSE BLOCK'
   END-IF.
   
STOP RUN.

Q 24 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM PIC 9(3).
   88 PASS VALUES ARE 041 THRU 100.
   88 FAIL VALUES ARE 000 THRU 40.

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   MOVE 65 TO WS-NUM.
   
   IF PASS 
      DISPLAY 'Passed with ' WS-NUM ' marks'.
      
   IF FAIL 
      DISPLAY 'FAILED with ' WS-NUM 'marks'.
      
STOP RUN.

A - Compilation error

B - Passed with 065 marks

C - FAILED with 065 marks

D - None of these

Answer : B

Explanation

WS-NUM contains 65 so PASS condition is satisfied as values lies in range of 041 to 100.

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

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM PIC 9(3).
   88 PASS VALUES ARE 041 THRU 100.
   88 FAIL VALUES ARE 000 THRU 40.

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   MOVE 65 TO WS-NUM.
   
   IF PASS 
      DISPLAY 'Passed with ' WS-NUM ' marks'.
      
   IF FAIL 
      DISPLAY 'FAILED with ' WS-NUM 'marks'.
      
STOP RUN.

Q 25 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

PROCEDURE DIVISION.
   A-PARA.
   PERFORM DISPLAY 'A'
   END-PERFORM.
   PERFORM C-PARA THRU E-PARA.
   
   B-PARA.
   DISPLAY 'B'.
   STOP RUN.
   
   C-PARA.
   DISPLAY 'C'.
   
   D-PARA.
   DISPLAY 'D'.
   
   E-PARA.
   DISPLAY 'E'.

A - ACDEB

B - ADCEB

C - DEBAC

D - DACEB

Answer : A

Explanation

This is to show how control goes from one Perform statement to other. Go step by step you will understand the flow.

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

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

PROCEDURE DIVISION.
   A-PARA.
   PERFORM DISPLAY 'A'
   END-PERFORM.
   PERFORM C-PARA THRU E-PARA.
   
   B-PARA.
   DISPLAY 'B'.
   STOP RUN.
   
   C-PARA.
   DISPLAY 'C'.
   
   D-PARA.
   DISPLAY 'D'.
   
   E-PARA.
   DISPLAY 'E'.

Answer Sheet

Question Number Answer Key
1 C
2 B
3 B
4 D
5 B
6 B
7 C
8 B
9 B
10 B
11 D
12 B
13 B
14 A
15 A
16 C
17 A
18 B
19 B
20 B
21 B
22 B
23 B
24 B
25 A
cobol_questions_answers.htm
Advertisements