Cobol and Mainframe

COBOL Interview Questions

Nowadays, the COBOL language turns to be the most effective language in the computer language prospective. Many software developers use COBOL to accomplish a lifetime project. For this, it is a very useful subject in the field of educational. Many interviewers ask different types of question to the candidate from the COBOL. Here, we discuss some important questions and their answers related to COBOL.

What Are the Data Types that Are Present in COBOL?

  • Alpha-numeric (X)
  • Alphabetic (A)
  • Numeric (9)
  • Sign (S)
  • Assumed decimal point (P / V)

What Is 77 Level Used For?

A 77 level in COBOL refers to an elementary item which is a basic unit of data that cannot be further divided or qualified.

What Is PIC 9.99?

PIC 9.99 in COBOL is a 4-digit field which is designated to store numerical values, with a decimal point included.

How Do the Performing SECTION and PARAGRAPH Differ from Each Other?

The difference between performing a SECTION and a PARAGRAPH is that a SECTION action executes all the paragraphs within the section, while a PARAGRAPH action only executes a specific paragraph.

Could You Explain the Distinction Between Subscripts and Index?

Subscripts refer to the position of an array element, while Index can only be altered through the use of perform, search, and set operations.

What Distinguishes the Static Calls and Dynamic Calls?

Static calls refer to calling a standalone program. This program can be executed on its own during runtime.

Dynamic calls refer to calling a program that is not executable on its own. It can only be executed through code in another program.

What Distinguishes the SEARCH and SEARCH ALL?

SEARCH is sequential search.

SEARCH ALL performs a binary search and requires the table to be sorted using either the ASCENDING or DESCENDING KEY clause and is loaded in that order before it can be used.

What Is the Function of the “Replace” Option in a “Copy” Statement?

Reusing the same copy in the same code can be achieved using the “Replace” function and changing the value that is being replaced. The syntax is <copy name> REPLACING BY.

What Type of Error Is Captured by the “On Size Error” Option?

  • It is impossible to divide by zero.
  • It is also not possible to raise 0 to a negative number.

What Is the Local-Storage Section?

The local storage section is a type of memory allocation that is established each time a program is executed, and is discarded once it’s no longer needed. This has to be declared in the “WORKING-STORAGE SECTION” of the “DATA DIVISION” and can be terminated using statements like “EXIT PROGRAM”, “GOBACK”, or “STOP RUN”.

How Do Global and External Variables Differ?

Global variables are only available to the current batch program and cannot be accessed by the other batch programs. External variables are variables that are accessible to multiple programs by being stored in a system library. This means that any batch program which resides within the same library as the variable can reference it, allowing it to be used by multiple programs.

Explain the Rules to Perform a Search

  • The table must have an “OCCURS” clause.
  • The table must be indexed with the “INDEXED BY” phrase.
  • The search index must have an initial value.

How Can a File be Opened?

  • Input
  • Output
  • I-O
  • Extend

Write a COBOL Program to Concatenate Two Strings and Display the Resulting Concatenated String

IDENTIFICATION DIVISION.
PROGRAM-ID. EXAMPLE1.
ENVIRONMENT DIVISION.


WORKING-STORAGE SECTION.

    01 WS-STR-CHK   PIC X (20).
    01 WS-STR-DISP  PIC X (30).

PROCEDURE DIVISION.
    MOVE 'COBOL PROGRAMMING' TO WS-STR-CHK.
    STRING 'THIS IS '
        WS-STR-CHK
        DELIMITED BY SIZE INTO WS-STR-DISP
    END-STRING.
    DISPLAY WS-STR-DISP.

STOP RUN.

Output:

papan@ubuntu:~/Desktop/cobol/inter$ cobc -xjF 1.cbl
 THIS IS COBOL PROGRAMMING

Write a COBOL Program to Add the Values of VAR-B, VAR-C, and VAR-D and Store the Result in VAR-A, Subtract the Value of VAR-C from VAR-D and Store the Result Back in VAR-D, and Display the Values of VAR-A and VAR-D

IDENTIFICATION DIVISION.
PROGRAM-ID. EXAMPLE2.
ENVIRONMENT DIVISION.


WORKING-STORAGE SECTION.

01 VAR-A    PIC 9(2).
01 VAR-B    PIC 9(2).
01 VAR-C    PIC 9(2).
01 VAR-D    PIC 9(2).

PROCEDURE DIVISION.
MOVE 10 TO VAR-B.
MOVE 15 TO VAR-C.
MOVE 20 TO VAR-D.
ADD VAR-B VAR-C VAR-D GIVING VAR-A.
SUBTRACT VAR-B VAR-C FROM VAR-D.
DISPLAY "VAR-A: " VAR-A.
DISPLAY "VAR-D: " VAR-D.

STOP RUN.

Output:

papan@ubuntu:~/Desktop/cobol/inter$ cobc -xjF 2.cbl
VAR-A: 45
VAR-D: 05

Write a COBOL Program to Use the RENAMES Statement

IDENTIFICATION DIVISION.
PROGRAM-ID. EXAMPLE3.
ENVIRONMENT DIVISION.

WORKING-STORAGE SECTION.
01 WS-DESP.
    05 WS-NO.
        10 WS-N01 PIC 9(2) VALUE 20.
        10 WS-N02 PIC 9(2) VALUE 62.
    05 WS-CHAR.
        10 WS-CTR1 PIC X(2) VALUE 'PP'.
        10 WS-STR2 PIC X(2) VALUE 'QQ'.
    66 WS-RENAME RENAMES WS-N02 THRU WS-STR2.

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

Output:

papan@ubuntu:~/Desktop/cobol/inter$ cobc -xjF 3.cbl
WS-RENAME: 62PPQQ

What Is the Purpose of this COBOL Program?

IDENTIFICATION DIVISION.
PROGRAM-ID. EXAMPLE4.
ENVIRONMENT DIVISION.
WORKING-STORAGE SECTION.
01 VAR1 PIC S9(9)V99.
01 VAR2 PIC 9(18).
   
PROCEDURE DIVISION.
MOVE 12345.99 TO VAR1.
MOVE VAR1 TO VAR2.
DISPLAY "VAR1: " VAR1.
DISPLAY "VAR2: " VAR2.
STOP RUN.

Output:

papan@ubuntu:~/Desktop/cobol/inter$ cobc -xjF 4.cbl
VAR1: +000012345.99
VAR2: 000000000000012345

Conclusion

COBOL is a vast conceptual language in the computer language prospective. Many topics are discussed from this language. We are trying to cover up the most important and famous questions that are asked by the experts in the interview to help the candidate for their preparation for the interview.

About the author

Bamdeb Ghosh

Bamdeb Ghosh is having hands-on experience in Wireless networking domain.He's an expert in Wireshark capture analysis on Wireless or Wired Networking along with knowledge of Android, Bluetooth, Linux commands and python. Follow his site: wifisharks.com