Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Consider a scenario where we have a program having an array of 20 items. When the program tries to access the 21st item, the program fails to abend. What is the reason for this?

Answer»

The DEFAULT compiler option NOSSRANGE MUST have been USED which does not allow the program to abend. If we want the program to abend WHENEVER accessing an array element that is out of bounds, we need to use the compiler option of SSRANGE. Using this option, the program abends with SOC4 error which indicates that it tried to access an invalid address by using the WRONG index.

2.

Why is S9(4) COMP needed despite knowing that Comp-3 would utilise less space?

Answer»

S9(4) COMP represents that the item is a small integer which MEANS two words of 1 byte each can occupy a total of 2 bytes. In S9(4) COMP-3, ONE word is equal to half a byte which means 4 words can occupy 2 bytes and ADDITIONALLY, the sign occupies another half byte which results in a maximum of 3 bytes usage. More can be accommodated in S9(4) COMP when COMPARES to COMP-3.

3.

What do you understand by the following terminologies?

Answer»
  1. AMODE(31)
  2. AMODE(24)
  3. RMODE(24)
  4. RMODE(ANY)

All 4 are the OPTIONS that are available in COMPILE or link editing. AMODE expands to ADDRESSING Mode. AMODE(31) and AMODE(24) REPRESENTS that the addressing mode used is 31-bit and 24-bit respectively. When we use AMODE(ANY), it indicates that either 31-bit mode or 24-bit addressing mode can be used and it is dependent on the value of RMODE.

RMODE represents Resident Mode within the virtual storage. RMODE(24) represents that the mode can reside within virtual storage below the 16 Meg line. RMODE(ANY) represents that the mode can reside below or above 16 Meg line and the ADDRESS bit can be either 24-bit or 31-bit depending on the RMODE.

4.

How is INCLUDE different from COPY?

Answer»

The main similarity between INCLUDE and COPY is that both HELP in expanding the program variables or codes. The important difference between them is that INCLUDE is used for expanding the code at the time of pre-compilation. WHEREAS the COPY expands the code at compilation time. DB2 pre-compilers won’t be ABLE to PROCESS COPY statements which is why the statements involving the validation of table attributes and DCL statements are embedded USING INCLUDE.

5.

What are the problems associated with using ordered sequential files?

Answer»

The main nature of ordered sequential files is that the records are arranged BASED on some key field(s). When a user wants to perform OPERATIONS like insert or deletion, then the order based on the field(s) should be maintained at all times. This is attained only by creating a new file where we insert or update or delete the records within the new file and then maintain the ordered nature. All these take PLACE on the disk directly and the time required to access data on disk is the main bottleneck while processing any functionality. This reduces the SPEED of computation and slows down the SYSTEM unnecessarily if we try to use ordered sequential files whenever not needed.

6.

Under what circumstances are scope terminators mandatorily needed?

Answer»

When we are using in-line PERFORMS or EVALUATE statements, we NEED to USE scope terminators. It is recommended because it HELPS to read the CODE better and is DEEMED as a good coding practice.

7.

What are the causes of S0C7, S0C5 and S0C1?

Answer»

S0C7 is caused mainly DUE to the following reasons:

  • Whenever numeric operations are performed on data of non-numeric type.
  • When we are working on the uninitialized storage.
  • When we try to code excessively that surpasses the maximum permitted dub script.

S0C5 is caused mainly due to the following reasons:

  • Damaged index or subscript.
  • Exit occurred INCORRECTLY from a PERFORM.
  • Before the READ operation, I/O is accessed.
  • When we try to close an unopened dataset.

S0C1 is caused mainly due to the following reasons:

  • Incorrectly spelt DD name.
  • When we perform a read or WRITE operation on an unopened dataset.
  • When the subprograms that are called are not found.
8.

What are the differences between Structured COBOL and Object-Oriented COBOL programming?

Answer»
STRUCTURED COBOL ProgrammingObject-Oriented COBOL Programming
All functionalities are divided into modules.This follows a logical STYLE of programming that helps to WRITE code logic in a clean manner.
Less secure as there is no data hiding feature involved.Since it follows an object-oriented APPROACH, there is encapsulation and abstraction involved which helps in data hiding.
More natural WAY of coding.Here, objects are first identified and functionalities of those are then written. Hence, it is more secure.
9.

How can we reference or make COBOL program realise that about the following file formats?

Answer»

1. Fixed Block File
2. Fixed Unblock File
3. Variable Block File
4. Variable Unblock File
5. Printer File

Following are the explanation to the POINTS one by one:

  1. Fixed Block File: We can identify that a file is a fixed block file if the following 3 conditions are met:
    • ORGANIZATION IS SEQUENTIAL
    • RECORDING MODE IS F
    • BLOCK CONTAINS 0
  2. Fixed Unblock File: We can identify that a file is a fixed unblock file if the following 2 conditions are met:
    • ORGANIZATION IS SEQUENTIAL
    • RECORDING MODE IS F
  3. Variable Block File: We can identify that a file is a variable block file if the following 4 conditions are met:
    • ORGANIZATION IS SEQUENTIAL
    • RECORDING MODE IS V
    • BLOCK CONTAINS 0
    • Record length is never CODED as 4 bytes in FD as JCL will consider the record length as the max length of record plus 4.
  4. Variable Unblock File: We can identify that a file is a variable unblock file if the following 3 conditions are met:
    • ORGANIZATION IS SEQUENTIAL
    • RECORDING MODE IS V
    • Record length is never coded as 4 bytes in FD as JCL will consider the record length as the max length of record plus 4.
  5. Printer File: We can reference that a file is a printer file if the following 3 conditions are met:
    • ORGANIZATION IS SEQUENTIAL
    • RECORDING MODE IS F
    • BLOCK CONTAIN 0
10.

How can we process two files by comparing key fields?

Answer»

There are 2 possible APPROACHES for this:

  • APPROACH 1:
    • We can read records from both files, if the key fields match, then they can be ignored.
    • If upon key comparison, the results are unequal, then we identify which FILE has missing or new records and update the file with missing records accordingly.
  • Approach 2:
    • If both files have the same records, then the work will be reduced.
    • If file 1 comes to the AT END state, then we have to move HIGH VALUES into the key field. The same goes to file 2.
    • This process needs to be repeated until both key fields are equal to HIGH VALUES.
    • For this process to work, the key fields should be in PIC(X) format and not numeric.

To make the process easier, we can avoid a lot of I-O operations by reading data to the local array table and then processing the records from there.

11.

How do we remove the spaces at end of every record in an output file that is of variable length?

Answer»

Spaces that are PRESENT at the end of the record are called trailing spaces. COBOL does not provide the functionality to remove such trailing spaces. But it can be achieved by using the RECORD-LENGTH field as FOLLOWS:
Consider a scenario where we have a file of variable length and the maximum possible record length is 4000. To remove trailing space from EVERY record, then we can alter the record length value to RECORD-LENGTH. This ensures that the records are trimmed which are beyond actual record length. Assuming that a variable-length file has a maximum record length of 4000.

  • Move the original record length value to RECORD-LENGTH. This process ENABLES the trimming of the entire record that is beyond the length.
  • In case the data is populated only up to 3000 bytes - meaning there are 1000 trailing spaces. Then move the record length value to RECORD-LENGTH.
  • By doing this, the records would be trimmed off and 1000 bytes would be freed.
12.

Why should the file be opened in I-O mode when it is being used for REWRITE purposes?

Answer»

When the file REWRITE of the RECORD needs to be performed, the file should first be OPENED and then the record must be READ from the file. This is why the file should always be opened in I-O mode.

13.

How is sorting achieved in the COBOL program?

Answer»

It is done by using the SORT command whose syntax goes as follows:

SORT file_1 ON ASCENDING/DESCENDING KEY key…USING file_2GIVING file_3.

where

  • file_1 - sort workfile that needs to be described by using SD entry in FILE SECTION.
  • file_2 - INPUT file for SORT that needs to be described using FD entry in FILE SECTION and using a SELECT clause in FILE CONTROL.
  • file_3 - output file from SORT and again needs to be described using FD entry in FILE SECTION and SELECT clause in FILE CONTROL section.

All THREE files are not supposed to be opened explicitly.

Note:

  • USING clause can be replaced by INPUT PROCEDURE IS para_1 THRU para_2. While using INPUT PROCEDURE, we need to REMEMBER that the section will be executed before sort and the records need to be released to the work file from the RESULT of the input procedure.
  • GIVING clause can be replaced by OUTPUT PROCEDURE IS para_1 THRU para_2. While using OUTPUT PROCEDURE, we need to note that the procedure will be executed once all records were sorted and the records from the sort work file should be populated one record at a time to the output procedure.
14.

What are the different divisions in COBOL programs?

Answer»

There are mainly 4 divisions in a COBOL program, they are:

  • IDENTIFICATION DIVISION: This is the most important division that is used for IDENTIFYING the program. This division is needed for any COBOL program to RUN. If this division is not included in your program, then the program cannot be compiled.
  • ENVIRONMENT DIVISION: This division is subdivided into 2 types - Configuration and Input-Output section. They define the written program’s environment.
  • DATA DIVISION: This division is used for identifying the data items, allocating proper MEMORY and defining the names within the program. It also has a file, linkage section and working storage.
  • PROCEDURE DIVISION: This division supports the main LOGIC of the program. It should consist of at least one statement for using user-defined variables.
15.

What are some of the guidelines that can be followed while developing a structured COBOL program?

Answer»

Certain guidelines need to be FOLLOWED while writing a structured COBOL PROGRAM

  • When developing the CASE construct, we can use EQUIVALENT statements. 
  • We can use Scope Terminators while using nested constructs. 
  • We can also try using IN-LINE PERFORM statements whenever possible when we want a program to perform something. 
  • To perform a proper conditional CHECK, we can also try using TEST BEFORE and TEST AFTER statements while using loop constructs to ensure DESIRED results.