Cobol interview questions and answers

Explain the following in CICS:
a. MDT
b. Maps

a. MDT :
- MDT stands for Modified Data Tag.
- The bit in the byte of attribute indicates modification of field on the screen. The modification happens on an input operation. Application program receives the data based on the flag of the field.
- The attributes / fields can be set or reset by using FSET and FRSET operations.

1. FSET : MDT is set to ensure that the field is transmitted. It happens only on an output operation
2. FRSET : MDT is reset. The field is continued to be sent until it is reset.

b. Maps :
- BMS : Basic Mapping Support has the ability to change the flags from 0 to 1 at the time of modification of the field. If the same map is utilized multiple times, it is mandatory that the flag must be reset to Zero.
- Data transmission may happen when PF key is pressed.
- Data transmission will not happen when PA key is pressed.
- MAPONLY is used to send the map alone, without data. Eg. used in menu screens.
- DATAONLY is used to send data alone, without resending the screen layout. Eg. used to refresh screen data.

What is multithreading in JCL?

- Job Control Language does not support multithreading inherently.
- A method of accomplishment is implemented, known as redneck way, which forks other jobs into INTRDR. This is not risk free. There is an assumption that all the jobs would be finished prior to the next program that pulls in all data processed by other threads.
- Another way of accomplishing multithreading is by using system enqueue and duplicate the job names. Use a scheduler that is able to schedule many jobs at once and leaves the next job when all the prereq’s have finished.

How to execute 2nd and 4th steps among 5 steps in JCL proc?

The following are the steps to accomplish the task:
//job1 job a123 'name' class=a
// restart=step002
//step001 exec pgm=prog1
//step002 exec pgm=prog2
//step003 exec pgm=prog3 cond=(0 le)
//step004 exec pgm=prog4
//step005 exec pgm=prog5 cond=(0 le)
//step006 exec pgm=prog6
- There are 3 duplicate records in a file.

How to remove 2 duplicate records and copy only one using Job Control Language?

The following are the steps to accomplish the task:

1. Sort the PS using JCL SORT utility and update the PS file.
2. Find the duplicates using XSUM .
3. Write the duplicates alone in a separate PS.
4. Take the separate PS
5. Give the control condition inside SYSIN DD * as , sort fields with skiprec(3), since only the 3rd one is needed to copy.

Discuss about changing Dataset name in PROC.

- Dataset name can be changed by overriding from the calling job. One of the ways of using JCL overriding is in the form of PROCSTEP.PROCDD DD DSN=[overriding dsn name]. This works pretty good, provided the same dataset is used for overriding.

- Another method of overriding DSN is by changing the proc dsn to a variable. A “&” proc pram is used by this process. The benefit is enforcing a dsn passing. In case the default is left blank and not overridden the job would crash with DSNF.

Explain about different table spaces.

- There are thee types of table spaces, namely:
1. Simple table space
2. Segmented table space
3. Partitioned table space

1. Simple table space:
- A simple table space can contain one or more tables.
- The rows from multiple tables can be interleaved on a page under the control and maintenance of DBA.

2. Segmented table space:
- It also contains one or more tables.
- Each table space is divided into 4 to 64 pages length of segments in increments of 4 pages.
- A segment is dedicated to a single table. One table can occupy multiple segments.

3. Partitioned table space:
- One table is accommodated in partitioned table space.
- Table space is divided into different parts and every part is put in a separate VSAM dataset.

How to remove the spaces at the end of each record in the output file of variable length, via COBOL program?

- Spaces at the end of the record are called trailing spaces.
- There are no functions to trim the trailing space.
- It can be done by altering the RECORD-LENGTH.
- The following is the accomplish this task
1. Assuming that a variable length file has maximum record length as 4000.
2. Move the original record length value to RECORD-LENGTH. This process enables the trimming off the entire record that is beyond the length.
3. In case the data is populated only up to 3000 bytes. Then move 3000 to RECORD-LENGTH.
4. By implementing the above process, the record would trim off the trailing 1000 bytes.

What are various search techniques in COBOL? Explain.

- There are 2 searching techniques in COBOL.

1. Serial search:
- It is a process of finding a particular value in a given list.
- The search is implemented by checking each element in the list, one at a time and in sequence.
- This process is continued until the desired element is found.
- SEARCH is used for serial search.

2. Binary Search:
- It is a process of finding a particular element in a sorted list.
- The binary search starts by comparing the middle element of the array.
- The comparison determines the element’s location – either in the first half of the list or in the second half of the list.
- This process continues until the search element is equal to the middle element of the list
- SEARCH ALL is used for binary search.
- The list must be sorted by using ASCENDING / DESCENDING KEY clause, which loads.
- The default key is ASCENDING KEY.

Explain sorting techniques in COBOL program? Provide the sort file definition, the sort statement, its syntax and meaning

- COBOL supports 2 sorting techniques.

1. Ascending order of sorting is done by using ASCENDING KEY clause.
2. Descending order of sorting is done by using DESCENDING KEY clause.

- A sort file definition is:
The sort file is defined by using:
1. SORT verb.
2. ON order of sorting.
3. specifying key field.
4. USING source file.
5. GIVING target file.

- The SORT-EMPLOYEE file is the “work-file” that is the interface between source file and target file.
- The SORT-EMPLOYEE is not the actual file, but it is declarative file that communicates to the compiler as an external file.
- ON ASCENDING KEY EMP-ID indicates the order of sorting is ascending and the key field is EMP-ID.
- SOURCE-EMPLOYEE is the source file that is to be sorted.
- TARGET-FILE is the resultant file that will have sorted records of source file.

How is a typical DB2 batch program executed?

DB2 batch program is executed in two ways:

1. By using DSN utility from native TSO.
2. By using IKJEFT01 utility program in JCL.

How did the release of COBOL/370 version 1.3 improve the performance of release 1.1?

All features of Release 1.1 and running with LE/370 Release 3 - Improved performance over COBOL/370 version 1.3 - Code for storage and initialization for unreferenced data items is eliminated with the OPTIMIZE(FULL) option - NORENT programs with more than 16mb line are supported by RMODE option - WORKING-STORAGE variables are initialized statically for NORENT programs at compile time - CALL statement with USING phrase is provided with optimized parameter list generation - LINKAGE SECTION data items are provided with variable-length MOVE - Main entry point is provided with optimized code generation - A literal can be called dynamically using CALL - Availability of Library Routine Retention.

What do you do to resolve SOC-7 error?

- Offending data need to be corrected
- The main cause for SOC-7 error is un-initialized numeric item. Focus on examining on this.
- Lot of installations provide a dump for run time abends, and these abends provide the offset which is returned by the last instruction where the abend occurred.
- Focus on examining the compilation output XREF listing to find the verb and the line number within the source code at this offset.
- Later investigate the source code for finding the bug
- Define certain datasets(SYSABOUT etc) in JCL, for capturing runtime dumps
- At times few installations might have batch program debugging tool. Utilize them to resolve the issue.

How do you reference the following file formats from COBOL programs:
1. Fixed Block File
2. Fixed Unblock File
3. Variable Block File
4. Variable Unblock File
7. RRDS File
8. Printer File

1. Fixed Block File:
The fixed block file is referenced by using:

2. Fixed Unblock File:
The fixed unblock file is referenced by using:

3. Variable Block File:
The variable block file is referenced by using:
- Never code 4 bytes as record length in FD, as JCL record length will be max record length in program + 4

4. Variable Unblock File:
The variable block file is referenced by using:
- Never code 4 bytes as record length in FD, as JCL record length will be max record length in program + 4

5. ESDS VSAM File:
This file is referenced by using:

6. KSDS VSAM file:
This files is referenced by using:

7. RRDS File:
This file is referenced by using:

8. Printer File:
This file is referenced by using:

What is AMODE(24), AMODE(31), RMODE(24) and RMODE(ANY)? (Applicable to only
MVS/ESA Enterprise Server).

These are the options of compile/link editing:

- AMODE : Addressing Mode.

- AMODE(24) : It is a 24 bit addressing mode.

- AMODE(31) : It is a 31 bit addressing mode.

- AMODE(ANY) : Either 24 bit or 31 bit address mode depending upon RMODE.

- RMODE : Resident mode.

- RMODE(24) : It resides within virtual storage below 16 Meg line.
a Programs of 31 bit which call 24 bit programs, are preferred to use this mode.
b RMODE(ANY) : Either 24 bit or 31 bit address mode depending upon RMODE.
c OS/VS COBOL program use 24 bit address only.

- RMODE(ANY) : This mode can reside below or above 16 Meg line.

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

The following are the differences:

1. OS/VS COBOL programs run only in 24 bit addressing mode.
VS COBOL II programs run either in 24 bit or 31 bit addressing modes.

2. Report writer is supported in OS/VS COBOL.
Report writer is not supported in VS/COBOL II.

3. USAGE IS POINTER is supported in VS COBOL II.
USAGE IS POINTER is not supported in OS/VS COBOL.

4. Reference modification, ex: WS-WAR(1:2), is supported in VS COBOL II.
Reference modification is not supported in VS/OS COBOL II.

5. EVALUATE is supported in VS COBOL II.
EVALUATE is not supported in VS/OS COBOL II.

6. Scope terminators are supported in VS COBOL II.
Scope terminators are not supported in VS/OS COBOL II.

7. OS/VS COBOL follows ANSI 74 standards.
VS COBOL II follows ANSI 85 standards.

8. Calls between VS COBOL II programs are supported under CICS.
Calls between OS/VS COBOL programs are not supported under CICS.

How to define a VSAM file in CICS getting Into CICS to define a VSAM File.

- Resources to CICS are defined by supplied transaction CEDA.

1. Define VSAM file by using the following code:

2. Move to CICS region by using the following command from ISPF panels:
\g CICS01
- Where cics01 is the name of the CICS01 region name, MYFILE is the file name and DBG is the name of the group.

What are declaratives and what are their uses in cobol?

- The declarative are used to provide special sections that are executed in case of exceptional condition occurrences.

- The declarative must be grouped and coded at the start of division of procedure. Also the entire procedure must be split into sections.

- A group of declarative always begin with DECLARATIVES and end by END DECLARATIVES in area A.

- There are three types of declaratives used in COBOL:

1. Exception: They are used for errors that occur in a file handling procedure.
2. Debugging: As their name suggests, used for debugging lines with "D" code in w-s section.
3. Label: They are used to indicate a beginning.

Explain what you understand by passing BY VALUE.

It means that the program/method passes the value of the identifier or literal. It does not imply a reference to the sending data item. The program/method called has the capability to change the parameter in the called/invoked program/method. But there is no effect on the argument value in the calling program as the subprogram/method has access to a temporary copy of the sent data item. The parameters used should always be of a particular defined data type in case the data is to be passed somewhere else. This is different as compared to BY CONTENT as it does not passes only the contents of the identifier.

What are the various section in Data Division and briefly explain them.

- There are various sections in data division:
a. File section: This section is used to describe the fields of a file the program uses.

b. Working-storage section: This defines the data names that the program needs for internal manipulation of data.

c. Communication section: This is used when one program has to communicate with other programs by the use of message passing.

d. Screen section: This is used when a program does input/output through the use of forms on the screen.

e. Report section: It consists of one or more RD entires (report description) each of which forms a complete description of a report.

f. Linkage section: As their name suggests this is used when a cobol program calls another program.

State the various causes of S0C1, S0C5 and S0C7.

S0C1 can be caused due to:
- A mis-spelt DD name.
- Read/Write to a dataset that is unopened.
- The subprogram called cannot be found.
- Read to dataset for an opened output.

S0C5 can be caused due to:
- A bad or damaged Subscript/index.
- An incorrect exit from a perform.
- The I/O area is accessed before read.
- An unopen dataset is closed.

S0C7 can be caused due to:
- A numeric operation is performed in a non-numeric data.
- Working storage is un-initialized.
- Excess coding past the max permitted dub script.

What do you understand by PSB and ACB?

- PSB stands for Program specification block.
- This block is used to define how any program is to access an IMS DB. The PSB comprises of the PCB (Program Communication Block).
- Each PSB must contain at least one PCB. These contain information such as which segment in DB can be accessed, what the program can do and how the DB can be accessed.

- ASB stands for Access control blocks.
- Basically they are a block of memory with information stored in them. These are generated by IMS.
- They serve the purpose of being an expansion of the information contained in the PSB`s. By doing so they speed up the access to the applicable DSD`s. IMS builds the ACB with the ACBGEN utility by merginf info from PSB and the DBD.
- They can be built either dynamically or can be prebuilt.

Explain the configuration section of a cobol program with examples of syntax.

- The configuration section of a cobol program contains the overall specification of the computer that will be used for the compilation and execution of the program.
- It comprises of three sub-sections:
1. Source-computer
2. Object-computer
3. Special names

1. Source computer:
- This paragraph is used to specify the name of the computer that is used for the compilation of the cobol program.
- It is displayed as :
SOURCE-COMPUTER. computer-name
2. Object computer:
- This paragraph describes the name of the computer on which the cobal program would be executed.
- This paragraph consists of some additional information about the computer such as Memory size, Segement-limit etc.
- The format of this paragraph is as follows:
OBJECT-COMPUTER. computer-name.
[,MEMORY SIZE integer-1]
[,SEGMENT-LIMIT IS integer-2]
3. Special names:
- This paragraph is primarily used to map user-specified mnemonic names to some hardware names.

What rules are to be followed while using the corresponding options?

- The following rules must be followed when a corresponding option is used:

1. In all cases the identifier 1 & 2 must refer to group items, this means the identifiers cannot be data items with level numbers such as 66,77 or 88.

2. The identifiers can take part in an operation such as ( ADD, SUBTRACT ) only if the data they have, has same data name and same qualifiers upto but not including identifier -1 and identifier -2.

3. Only numeric data items are considered for ADD or SUBTRACT CORRESPONDING. This implies non numeric data are not used for arithmetic operations.

4. Any data items classified as filler are ignored.

5. The items of CORRESPONDING may have different locations within the group and the field sizes cal also be different.

6. The subordinates to identifier 1 & 2 with level number 66 or 88, or containing a REDEFINES or OCCURS clause are ignored for the operation.

Write a program to explain size error.

Identification division
Program-id. sizeerr
Environment division
Data division
Working-storage section
77 a pic s9(3) value 0
77 b pic s9(3) value 0
7 c pic s9(3) value 0
77 e-c pic +z(3)
Procedure division
Display(1 1) erase.
Display(3 5) "Enter your first number :"
Accept a
Display(5 5) "Enter your second number :"
Accept b
Add a b to c on size error
display (10 5) "Size error on c - - -Please increase size"
go to end-para
Move c to e-c
Display(15 5) "Sum = " e-c
Stop run

What are the different types of condition in cobol and write their forms.

- In cobol the various types of conditions are:
1. Relational condition
2. Sign condition
3. Class condition
4. Condition-name condition
5. Negated-simple condition
6. Compound condition

1. Relational condition:
- This condition indicates a comparison between two operands.
- The form of this condition is:
Operand-1 relational-operator operand-2
2. Sign condition:
- This condition defines if the value of an operand is positive, negative or zero.
- The format of this condition is:
{identifier} IS [NOT] {POSITIVE}
3. Class condition:
- This condition determines the value of an operand as alphabetic or numeric.
- The form is as follows:
Identifier IS [NOT] {NUMERIC}
4. Condition-name condition:
- A unique kind of condition in which the entity itself is a condition which can either be true or false.
- The form for such condition is:
88 condition-name {VALUE IS} Literal-1 ({THROUGH}literal-2)
5. Negated-simple condition:
- Any simple condition which can be preceded by a logical operator NOT.
- Such conditions are known as negated simple condition.
6. Compound condition:
- In this type of condition two simple conditions can be connected by the logical operators AND or OR.
- Such conditions are known as compound conditions.

Write a program to enter and display the names of students in a class using the occurs clause.

- The occurs clause is used to specify the table whose contents can be accessed by indexing or subscripting.
- The advantage of using the occur clause is that it does not require separate entries for data items that are repeated.
- Program:
identification division
environment division
data division
working-storage section
01 n pic 9(2) value 0
01 i pic 9(2) value 0
01 name-in
02 name pic x(20) occurs 20 times
01 key-in pic x value space
procedure division
display(1 1) erase
display(3 5) "Specify how many times?"
accept n
display(1 1) erase
perform get-para n times
display(1 1) erase
move 0 to i
perform disp-para n times
stop run
accept name(i)
add 1 to i
display name(i)
accept key-in
add 1 to i

What is the problem of ordered sequential files access?

All the records in an ordered sequential file are arranged in order on the basis of some key field or fields. Whenever a user wants to perform an operation such as insertion / deletion the order specified must be maintained. This can only be done by the creation of a new file. An insertion or update causes the new file to contain within it the records of the new insertion or update.The problem of performing these actions on an ordered sequential files is that it requires the entire file to be read. And after this procedure the fields are filled inside the new file that is created. All this operation occurs directly on the disk. The disk access times are the bottlenecks of computing. By doing such an operation unnecessary slowing down of the computer occurs.

Write a cobol program making use of the redefine clause.

- The redefine clause is used to represent different data types by the same storage locations.
- For example, a program to show the implementation of the redefine clause:
identification division
program-id. Redef
environment division
data division
working-storage section
01 a pic 9(3) value 125
01 r pic 9(2) redefines a
procedure division
display(1 1) erase
display(5 5) "The value of r is = " r
stop run
- The above code on execution would give :
The value of r is = 12.
This was done by redefining a variable.

Write the code implementing the PERFORM … VARYING.

The code for the above question would be:

Identification division
Program-id. PerfVary
Environment division
Data division
Working-storage section
01 n pic 9(2) value 0
01 i pic 9(2) value 1
01 sum pic 9(4) value 0
Procedure division
Display(1 1) erase
Display(5 5) "Enter a number of your choice "
Accept n
Perform calc-para varying i from 1 by 1 until i > n
Display(10 5) " Sum = " sum
Stop run
Compute sum = sum + i

What rules are followed by the search verb.

The rules that are applicable to the search bar verb are:

1. It can only be applied to a table containing the indexed phrase and consists of the occurs clause.

2. The index must have an initial value before the use of the search verb.

3. The at end clause is used to send the executing code after its search is over and the element is not found to run the next set of instructions.

4. When a search verb is initiated it begins with the initial index value specified of the index. Then it checks if the when clauses have been satisfied or not. In case no conditions are being satisfied the index value is incremented by 1. This is repeated till the value of index exceeds the table size.

5. The varying option is used to increment the value of the identifier2 each time the index is incremented.

Write a program that uses move corresponding.

- The move corresponding is used with group level-fields. IF the source and target group level fields have same elementary fields of exactly the same name then the field would be moved.
- Program:
identification division.
environment division
data division
working-storage section
01 rec-1
02 sno pic 9(2) value 11
02 name pic x(4) value "Test"

01 rec-2
05 sno pic z(2)
05 f pic x(10) value spaces
05 name pic x(4)
05 f pic x(10) value spaces
procedure division
display(1 1) erase
move corr rec-1 to rec-2
display rec-2
stop run

What are the rules of the move verb?

- The move verb is used to move data from one place to another in the memory.
- The movement of data with the help of this verb is limited by the following rules:

1. It is possible to have more than one receiving field but always there can only be one sending field. All the contents of the receiving fields are replaced with the value of the sending field.

2. When the sending and the receiving field are both numeric the transfer is known as numeric data transfer. During such kinds of transfers the major factor in the movement is the position of the decimal point. If it is not mentioned the decimal point is considered to be at the right of the rightmost digit. If the receiving field is not as large as the sending field then some data maybe truncated from the sender.

3. If both the sending and receiving fields are mixed then such type of transfers are known as alphanumeric data transfers. In these types of cases the receiving area is filled from left to right.

What is the compute verb? How is it used?

- The compute verb allows the user to perform compute functions such as multiply and divide without using 4 different verbs.
- The general format of a compute verb is as follows:
COMPUTE identifier-1 (ROUNDED), (identifier-2 ROUNDED) …
= arithmetic expression (;on size error imperative-statement)
- Some of the compute operators and their meaning:
**Used for exponiation
/Used for division
*Used for multiplication
-Used for subtraction
+Used for addition
- Example compute usage:
- This would have the same effect as : ADD B C GIVING A would have done.
- By the use of compute the user has to write less code and reading the code becomes much easier as computations are represented in the form of expressions that are easy to understand.

What do you understand by passing by reference and passing by content?

Passing by reference:
- When between programs data is shared or passed the subprogram always refers and processes the data items within the calling programs storage.
- It does not work on the copy of the data. Whenever a call by reference identifier is used the caller and the called share the same memory.

Passing by content:
- In this case the calling program only passes the contents of the identifier or the literal.
- When this is used the called program is unable to change the value of the identifier or the literal in the program being called. Further it cannot change the value even if it has modified the variable through which it received its literal.

How are the next sentence and continue different from each other?

Some of the differences of the next sentence and continue are as follows:

- The continue gives the control to the next verb only after explicit scope terminator whereas the next sentence gives control to the verb following the next period.

- The continue in cobol acts like a null statement whereas the next sentence is used to transfer the control to the next logical sentence.
The next sentence in broader terms is similar to the go to. It causes the transfer of protocol.

- For example, depicting the use of next sentence:
IF A = B

Write the code to count the sum of n natural numbers.

The cobol code to find the sum of n natural numbers would be:
Identification division
Program-id. PerfUntil
Environment division
Data division
Working-storage section
01 n pic 9(2) value 0
01 i pic 9(2) value 1
01 sum pic 9(4) value 0
Procedure division
Display(1 1) erase
Display(5 5) "Enter a Number"
Accept n
Perform calc-para until i > n
Display(10 5) "Sum = " sum
Stop run
Compute sum = sum + i
Add 1 to i
What is CICS?
What is CICS? - CICS stands for Customer Information Control System.....
Why do we need Integrated CICS translator?
Why do we need Integrated CICS translator? - To handle both native Cobol and embedded CICS statements in the Source Program.......
What is MDT?
What is MDT? - MDT stands for MDT Modified Data Tag. Preserves only one bit of attribute character.....
Post your comment
Discussion Board
COBOL interview questions
Good list of questions are provided on COBOl in this site.But the explanation for each question is not available any where.

Have my own blog about all mainframe interview questions including COBOL with clear explanation to help everyone.

The blog is:

Is that Ok can I mention about the blog in this site so as to help other mainframe candidates?
Thank you.
Sreenivas 04-17-2014