COBOL Interview Questions


Name the divisions in a COBOL program?

  • IDENTIFICATION DIVISION
  • ENVIRONMENT DIVISION
  • DATA DIVISION
  • PROCEDURE DIVISION

What is the purpose of Identification Division?

Documentation

How many sections are there in data division?.

Three sections -

  1. FILE SECTION
  2. WORKING-STORAGE SECTION
  3. LINKAGE SECTION

What divisions, sections and paragraphs are mandatory for a COBOL program?

IDENTIFICATION DIVISION and PROGRAM-ID paragraph are mandatory for a compilation error free COBOL program.

What is the linkage section?

The linkage section is part of a called program that 'links' or maps to data items in the calling program's working storage. It is the part of the called program where these share items are defined.

What is the LINKAGE SECTION used for?

The linkage section is used to pass data from one program to another program or to pass data from a PROC to a program.

What is the difference between performing a SECTION and a PARAGRAPH?

Performing a SECTION will cause all the paragraphs that are part of the section, to be performed. Performing a PARAGRAPH will cause only that paragraph to be performed.

What are the differences between COBOL and COBOL II?

COBOL II supports structured programming by using in line Performs and explicit scope terminators, It introduces new features (EVALUATE, SET. TO TRUE, CALL. BY CONTEXT, etc) It permits programs to be loaded and addressed above the 16-megabyte line It does not support many old features (READY TRACE, REPORT-WRITER, ISAM, Etc.), and It offers enhanced CICS support.

What are the differences between OS VS COBOL and VS COBOL II?

  • OS/VS Cobol pgms can only run in 24 bit addressing mode, VS Cobol II pgms can run either in 24 bit or 31 bit addressing modes.
  • Report writer is supported only in OS/VS Cobol.
  • USAGE IS POINTER is supported only in VS COBOL II.
  • Reference modification e.g.: WS-VAR(1:2) is supported only in VS COBOL II.
  • EVALUATE is supported only in VS COBOL II.
  • Scope terminators are supported only in VS COBOL II.
  • OS/VS Cobol follows ANSI 74 stds while VS COBOL II follows ANSI 85 stds.
  • Under CICS Calls between VS COBOL II programs are supported.

What was removed from COBOL in the COBOL II implementation?

REMARKS, NOMINAL KEY, PAGE-COUNTER, CURRENT-DAY, TIME-OF-DAY, STATE, FLOW, COUNT, EXAMINE, EXHIBIT, READY TRACE and RESET TRACE, etc.

What is difference between COBOL and VS COBOL II?

In using COBOL on PC we have only flat files and the programs can access only limited storage, whereas in VS COBOL II on M/F the programs can access up to 16MB or 2GB depending on the addressing and can use VSAM files to make I/O operations faster.

What are the different data types available in COBOL?

  • Alpha-numeric (X)
  • Alphabetic (A)
  • Numeric (9)

What is 77 level used for?

Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.

What is 88 level used for?

Used for condition names.

What is level 66 used for?

Used for RENAMES clause.

What does the IS NUMERIC clause establish?

IS NUMERIC can be used on alphanumeric items, signed numeric & packed decimal items and unsigned numeric & packed decimal items. IS NUMERIC returns TRUE if the item only consists of 0-9. However, if the item being tested is a signed item, then it may contain 0-9, + and - .

How is sign stored in Packed Decimal fields and Zoned Decimal fields?

Packed Decimal fields - Sign is stored as a hex value in the last nibble (4 bits ) of the storage.

Zoned Decimal fields - As a default, sign is over punched with the numeric value stored in the last bite.

What is the maximum size of a 01 level item in COBOL II?

16777215

What is the difference between PIC 9.99 and 9v99?

PIC 9.99 is a FOUR-POSITION field that actually contains a decimal point where as PIC 9v99 is THREE- POSITION numeric field with implied or assumed decimal position.

what is Pic 9v99 Indicates?

PICTURE 9v99 is a three position Numeric field with an implied or assumed decimal point after the first position; the v means an implied decimal point.

Can JUSTIFIED be used for all the data types?

No, it can be used only with alphabetic and alphanumeric data types.

Why occurs can’t not be used in 01 level?

Because, Occurs clause is there to repeat fields with same format, not the records.

How is sign stored in a comp-3 field?

It is stored in the last nibble.

How is sign stored in a COMP field?

In the most significant bit. Bit is ON if -ve, OFF if +ve.

What is the difference between COMP & COMP-3?

COMP is a binary storage format while COMP-3 is packed decimal format.

What is COMP-1? COMP-2?

COMP-1 - Single precision floating point and it uses 4 bytes.
COMP-2 - Double precision floating point and it uses 8 bytes.

How many bytes does a S9(7) COMP-3 field occupy?

Will take 4 bytes. Sign is stored as hex value in the last nibble. General formula is INT((n/2) + 1)), where n=7 in this example.

How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy?

Will occupy 8 bytes (one extra byte for sign).

How many bytes will a S9(8) COMP field occupy?

4 bytes

What is the maximum value that can be stored in S9(8) COMP?

99999999

What is COMP SYNC?

Causes the item to be aligned on natural boundaries. Can be SYNCHRONIZED LEFT or RIGHT. For binary data items, the address resolution is faster if they are located at word boundaries in the memory.

How many bytes does a S9(4) COMP-3 field occupy?

3 Bytes (formula - n/2 + 1)

What happens when we move a comp-3 field to an edited (z (9). ZZ-)

The editing characters are to be used with data items with usage clause as display which is the default. When tries displaying a data item with usage as computational it does not give the desired display format because the data item is stored as packed decimal.

So if this particular data item to be edited this should to move it into a data item whose usage is display and then have that particular data item edited in the format desired.

What is the maximum length of a field you can define using COMP-3?

10 Bytes (S9(18) COMP-3).

Why do we code s9 (4) comp? In spite of knowing comp-3 will occupy less space?

Here s9(4)comp is small integer, so two words equal to 1 byte so totally it will occupy 2 bytes(4 words).

Here in s9(4) comp-3 as one word is equal to 1/2 byte.4 words equal to 2 bytes and sign will occupy 1/2 byte so totally it will occupy 3 bytes.

What is the use of EVALUATE statement?

Evaluate is like a case statement and can be used to replace nested Ifs.

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.

In an EVALUATE statement, can a complex condition given on a when clause?

Yes.

What is a scope terminator?

Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE; IF, END-IF.

In an EVALUTE statement is the order of the WHEN clauses significant?

Yes, Evaluation of the WHEN clauses proceeds from top to bottom and their sequence can determine results.

What is SET TO TRUE?

In COBOL II, the 88 levels can be set rather than moving their associated values to the related data item.

In a COBOL II PERFORM statement, when is the conditional tested, before or after the perform execution?

In COBOL II the optional clause WITH TEST BEFORE or WITH TEST AFTER can be added to all perform statements. By default the test is performed before the perform.

How in-line PERFORM can be coded?

PERFORM ... [UNTIL] ... 
	[sentences]
END-PERFORM

What is an in line PERFORM? What is the use of it?

  • The PERFORM and END-PERFORM statements bracket all COBOL II statements between them.
  • The COBOL equivalent is to PERFORM or PERFORM THRU a paragraph.
  • In line PERFORMs work as long as there are no internal GO TOs, not even to an exit.
  • The in line PERFORM for readability should not exceed a page length - often it will reference other PERFORM paragraphs.

When is a scope terminator mandatory?

Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements.

For readability, it's recommended coding practice to always make scope terminators explicit.

What is PERFORM? What is VARYING?

The PERFORM statement transfers control to one or more specified procedures and controls as specified the number of times the procedures are executed.

After execution of the specified procedures is completed, control is transferred to the next executable statement following the PERFORM statement.

What is the difference between index and subscript?

Subscript refers to the array occurrence while index is the displacement (in no of bytes) from the beginning of the array.

An index can only be modified using PERFORM, SEARCH & SET. Need to have index for a table in order to use SEARCH, SEARCH ALL.

What is the difference between SEARCH and SEARCH ALL? What is more efficient?

SEARCH is a sequential search.

SEARCH ALL is a binary search & the table must be sorted (ASCENDING/DESCENDING KEY clause to be used & data loaded in this order) before using SEARCH ALL.

SEARCH ALL is more efficient for tables larger than 70 items.

What should be the sorting order for SEARCH ALL?

It can be either ASCENDING or DESCENDING. ASCENDING is default.

What is binary search?

Search on a sorted array. Compare the item to be searched with the item at the center.

If it matches, fine else repeat the process with the left half or the right half depending on where the item lies

Describe the difference between subscripting and indexing?

Indexing uses binary displacement.

Subscripts use the value of the occurrence

What is the difference between NEXT SENTENCE and CONTINUE?

NEXT SENTENCE gives control to the verb following the next period.

CONTINUE gives control to the next verb after the explicit scope terminator.

It's safest to use CONTINUE rather than NEXT SENTENCE in COBOL II.

What will happen if GO BACK coded instead of STOP RUN in a stand-alone COBOL program i.e. a program which is not calling any other program?

Both give the same results when a program is not calling any other program.

GO BACK will give the control to the system even though it is a single program.

What does the INITIALIZE verb do?

Alphabetic, Alphanumeric fields & alphanumeric edited items are set to SPACES.

Numeric, Numeric edited items set to ZERO. FILLER, OCCURS DEPENDING ON items left untouched.

What is LENGTH in COBOL II?

LENGTH acts like a special register to tell the length of a group or elementary item.

What is the point of the REPLACING option of a copy statement?

REPLACING allows for the same copy to be used more than once in the same code by changing the replace value.

What is Redefines clause?

Redefines clause is used to allow the same storage allocation to be referenced by different data names.

How do we get current date from system with century?

By using intrinsic function, FUNCTION CURRENT-DATE.

Can I redefine an X(100) field with a field of X(200)?

Yes. Redefines just causes both fields to start at the same location.

Can I redefine an X(200) field with a field of X(100)?

Yes.

How do reference the following file formats from COBOL programs:

For Fixed Block File - Use


ORGANIZATION IS SEQUENTIAL
RECORDING MODE IS F
BLOCK CONTAINS 0.

For Fixed Unblocked - Use


ORGANIZATION IS SEQUENTIAL 
RECORDING   MODE IS F 
do not use BLOCK CONTAINS

For Variable Block File - Use


ORGANIZATION IS SEQUENTIAL 
RECORDING MODE IS V 
BLOCK CONTAINS 0.

Do not code the 4 bytes for record length in FD ie JCL rec length will be max rec length in pgm + 4

For Variable Unblocked - Use


ORGANIZATION IS SEQUENTIAL 
RECORDING MODE IS V 
do not use BLOCK CONTAINS.

Do not code 4 bytes for record length in FD ie JCL rec length will be max rec length in pgm + 4.


For ESDS VSAM file - Use


ORGANIZATION IS SEQUENTIAL.

For KSDS VSAM file - Use


ORGANIZATION IS INDEXED 
RECORD KEY IS

For ALTERNATE RECORD KEY IS RRDS File - Use


ORGANIZATION IS RELATIVE 
RELATIVE KEY IS

For Printer File - Use


ORGANIZATION IS SEQUENTIAL 
RECORDING MODE IS F 
BLOCK CONTAINS 0.

What are different file OPEN modes available in COBOL?

Open for INPUT, OUTPUT, I-O, EXTEND.

What is the mode in which will OPEN a file for writing?

OUTPUT, EXTEND

Can we REWRITE a record in an ESDS file? Can we DELETE a record from it?

We can rewrite (record length must be same), but not delete.

What is file status 92?

Logic error. e.g., a file is opened for input and an attempt is made to write to it.

What is file status 39?

Mismatch in LRECL or BLOCKSIZE or RECFM between COBOL pgm & the JCL (or the dataset label). will get file status 39 on an OPEN.

What is AMODE(24), AMODE(31), RMODE(24) and RMODE(ANY)?

These are compile/link edit options. Basically AMODE stands for Addressing mode and RMODE for Residency mode.

  • AMODE(24) - 24 bit addressing.
  • AMODE(31) - 31 bit addressing.
  • AMODE(ANY) - Either 24 bit or 31 bit addressing depending on RMODE.
  • RMODE(24) - Resides in virtual storage below 16 Meg line. Use this for 31 bit programs that call 24 bit programs.
  • RMODE(ANY) - Can reside above or below 16 Meg line.

What compiler option would use for dynamic linking?

DYNAM.

What is SSRANGE, NOSSRANGE?

These are compiler options with respect to subscript out of range checking.

NOSSRANGE is the default and if chosen, no run time error will be flagged if your index or subscript goes out of the permissible range.

What care has to be taken to force program to execute above 16 Meg line?

Make sure that link option is AMODE=31 and RMODE=ANY.

Compile option should never have SIZE(MAX). BUFSIZE can be 2K, efficient enough.

What is Static and Dynamic linking?

In static linking, the called subroutine is link-edited into the calling program, while in dynamic linking, the subroutine & the main program will exist as separate load modules.

static/dynamic linking by choosing either the DYNAM or NODYNAM link edit option.

A statically called subroutine will not be in its initial state the next time it is called unless you explicitly use INITIAL or you do a CANCEL.

A dynamically called routine will always be in its initial state.

Explain call by context?

The parameters passed in a call by context are protected from modification by the called program.

In a normal call they are able to be modified.

How can we tell if a module is being called DYNAMICALLY or STATICALLY?

The ONLY way is to look at the output of the linkage editor (IEWL)or the load module itself.

If the module is being called DYNAMICALLY then it will not exist in the main module, if it is being called STATICALLY then it will be seen in the load module.

Calling a working storage variable, containing a program name, does not make a DYNAMIC call.

This type of calling is known as IMPLICITE calling as the name of the module is implied by the contents of the working storage variable.

How do set a return code to the JCL from a COBOL program?

Move a value to RETURN-CODE register. RETURN-CODE should not be declared in program.

How can submit a job from COBOL programs?

Write JCL cards to a dataset with //xxxxxxx SYSOUT= (A,INTRDR) where 'A' is output class, and dataset should be opened for output in the program.

Define a 80 byte record layout for the file.

What are the steps go through while creating a COBOL program executable?

DB2 precompiler (if embedded SQL used), CICS translator (if CICS pgm), Cobol compiler, Link editor. If DB2 program, create plan by binding the DBRMs.

How to submit JCL via a Cobol program?

Use a file //dd1 DD sysout=(*, intrdr)write your JCL to this file.

How to execute a set of JCL statements from a COBOL program?

Using EXEC CICS SPOOL WRITE(var-name) END-EXEC command. var-name is a COBOL host structure containing JCL statements.

How to define a sort file in JCL that runs the COBOL program?

Use the SORTWK01, SORTWK02,..... dd names in the step. Number of sort datasets depends on the volume of data being sorted, but a minimum of 3 is required.

How to resolve SOC-7 error?

For figuring out the exact piece of code that caused the abend, look at the Job dump and find the offset at which this abend has occurred. Once you have the offset, search for this offset in the compiler listing and you will get the exact statement which has caused the issue.

What guidelines should be followed to write a structured Cobol program?

  • Use 'evaluate' stmt for constructing cases.
  • Use scope terminators for nesting.
  • Use in line perform statement.
  • Use test before and test after in the perform stmt for writing do-while constructions.

What makes a program as good program?

A program that follows a top down approach.

It is also one that other programmers or users can follow logically and is easy to read and understand.

What is report-item?

A Report-Item Is A Field To Be Printed That Contains Edit Symbols.