Top 20 COBOL Questions to Ace in Interview

Below are some of the COBOL Interview Questions for entry-mid level Mainframe programming in COBOL. These are few common questions that you should be aware of and you may asked further questions from these topics.

Top 20 Research Analyst Interview Q...
Top 20 Research Analyst Interview Questions and Answers for 2022
COBOL Interview Questions in 2022
Photo by Alex Green on Pexels.com

COBOL Interview Questions for Mainframe Positions

Q1) Name the divisions in a COBOL program ?.
A1) There are 4 Divisions in COBOL Program IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION, PROCEDURE DIVISION.

Q2) What are the different data types available in COBOL?
A2) There are 3 Different types of data types: Alpha-numeric (X), alphabetic (A) and numeric (9).

Q3) What is INITIALIZE verb and when to use it
A3) INITIALIZE verb is used to set default values to the variables. Alphabetic, Alphanumeric fields and alphanumeric edited items will be set to SPACES. Numeric and Numeric edited items will be set to ZERO. FILLERS and OCCURS DEPENDING ON items will not be affected.

Q4) What is 77 level variable used for ?
A4) It’s called Elementary level item. so the variable cannot have subdivisions of other items (cannot be qualified) nor can they be subdivided themselves.

Q5) What is 88 level variable used for ?
A5) 88 levels are used For condition names. it’s also called as switches or flags which can be turned on or off.

Q6) What is level 66 variable used for ?
A6) 66 Levels are used For RENAMES clause.

Q7) What does IS NUMERIC clause establish ?
A7) IS NUMERIC can be used on alphanumeric variables, signed numeric, packed decimal variables and unsigned numeric / packed decimal items. IS NUMERIC returns TRUE if the variable only consists a value of 0-9. However, if the variable being tested is a signed item, then it may contain values as 0-9, + and – .

Q8) How do you define a table in COBOL?
A8) Arrays also called as internal tables in COBOL are defined using OCCURS clause.

Below is an example.

ARRAYS.
05 ARRAY-A PIC X(9) OCCURS 10 TIMES.
05 ARRAY-B PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX.

Q9) Can the OCCURS clause be at the 01-level?
A9) No, OCCURS clause cannot be defined at 01-Level.

Q10) What is the difference between index and subscript?
A10) Subscript refers to the array or table occurrence. It’s the position in the array while index is the displacement value(in no of bytes) from the beginning of the array. An index can only be modified using a PERFORM, SEARCH & SET instruction. Index for a table is mandatory if you want to use it for SEARCH, SEARCH ALL functions.

Q11) What is the difference between SEARCH and SEARCH ALL function?
‘A11) “SEARCH” is a serial search which searches the array one after the other in existing order.
SEARCH ALL” is a binary search and the table must be sorted ( ASCENDING/DESCENDING KEY clause to be used & data loaded in this order) before using SEARCH ALL.

Q12) What should be the sorting order for SEARCH ALL?
A12) It can be either sorted ASCENDING or DESCENDING but ASCENDING is the default. If you want the search to be done on an
array sorted in descending order, then while defining the array should use DESCENDING KEY clause.

Q13) What is Binary search in COBOL?
A13) Binary Search is performed on a sorted array. It Compares the item to be searched with the item at the center. If matches, it returns the result otherwise it repeat the process with the left half or the right half depending on where the item lies.

Q14) My program has an array defined with 10 items. Due to an coding error, I find that even if the program access the
11th item in this array, the program does not abend. What is wrong with it?
A14) We must use compiler option SSRANGE if you want array bounds checking to happen. Default is NOSSRANGE.

Q15) How do you SORT in a COBOL program?
A15) COBOL SORT Syntax is given below for your reference and easy understanding.

SORT File-1 ON ASCENDING/DESCENDING KEY key USING File-2 GIVING File-3.

USING can be substituted by INPUT PROCEDURE IS para-1 THRU para-2
GIVING can be substituted by OUTPUT PROCEDURE IS para-1 THRU para-2.

file-1 is the sort (work) file and must be described using SD section under FILE SECTION.
file-2 is the input file for the SORT and must be described using an FD entry under FILE SECTION and SELECT
clause under FILE CONTROL.
file-3 is the out file from the SORT and must be described using an FD entry in FILE SECTION and SELECT
clause under FILE CONTROL.
File-1, File-2 & File-3 should not be opened explicitly.

INPUT PROCEDURE is executed before the sort and records must be released to the sort work file from the input procedure.
OUTPUT PROCEDURE is executed after all records have been sorted. Records from the sort work file must be returned one at a time to the output procedure.

Q16) How do you define a sort file in JCL that runs the COBOL program?
A16) Use the SORTWK01, SORTWK02,… as dd names in the step. Number of sort datasets depends on the volume of data
being sorted, but a minimum of 3 is required.

Q17) What is the difference between performing a SECTION and a PARAGRAPH?
A17) Performing a SECTION will process all the paragraphs that are part of the section, to be performed.
Performing a PARAGRAPH will process statements only in the particular Paragraph.

Q18) What is the use of EVALUATE statement?
A18) Evaluate is like a “CASE” statement and can be used to replace multiple If Statements. The difference between EVALUATE and
case is that no ‘break’ is required for EVALUATE i.e. control comes out of the EVALUATE as soon as one match is
made.

Q19) What are the different forms of EVALUATE statement?
A19)Below are some of the examples for EVALUATE statement:

  • WHEN A=B AND C=D
  • WHEN 100 ALSO ’00’
  • WHEN (D+X)/Y = 4
  • WHEN -305 ALSO ’32’
  • EVALUATE SQLCODE ALSO A=B EVALUATE SQLCODE ALSO TRUE
  • WHEN 100 ALSO TRUE WHEN 100 ALSO A=B
  • imperative stmt imperative stmt
  • WHEN -503 ALSO FALSE WHEN -503 ALSO (A/C=4)
  • imperative stmt imperative stmt
  • END-EVALUATE END-EVALUATE

Q20) How do you come out of an EVALUATE statement?
A20) After the execution of one of the WHEN clauses, the control is automatically passed on to the next sentence immediately after the EVALUATE statement. There is no need of any additional lines of code to come out of evaluate specifically.

These are some of the important COBOL interview questions, let me know if you are looking for any specific Mainframe topic for interview questions.

Leave a Comment