IBM COBOL Interview Questions and Answers

IBM COBOL Interview, Mainframe COBOL Interview Questions and Answers.

Can you tell me if a SEARCH be applied to a table which does not have an INDEX defined?
Answer : The table must be indexed. hence the answer is No.

Explain what is the difference between SEARCH and SEARCH ALL?
Answer : SEARCH - is a serial search used in COBOL
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.

A table has two indexes defined. Which one will be used by the SEARCH verb? 

Answer : The index named first will be used, by  the SEARCH verb..

Explain what are the different rules applicable to perform a binary SEARCH? 

Answer : The table must be sorted in ascending or descending order before the beginning of the SEARCH.
You can usse OCCURS clause with ASC/DESC KEY IS dataname1 option
The main requirement is that the table must be indexed. There is no need to set the index value. Use SEARCH ALL verb

Explain how does the binary search work?

Answer : The binary search uses a very simple approach. First, the table is split into two halves and in which half, the item need to be searched is determined. The half to which the desired item may belong is again divided into two halves and the previous procedure is followed. This continues until the item is found. SEARCH ALL is efficient for tables larger than 70 items in a binary search

Explain the differences between a binary search and a sequential search? What are the pertinent COBOL commands? 

Answer : In a binary search, the table element key values must be in ascending or descending sequence. The table is 'halved' or divided to search for equal to, greater than or less than conditions until the element is found.

In a sequential search, the table is searched from top to bottom, hence the elements do not have to be in a specific sequence. The binary search is much faster for larger tables, While sequential Search works well with smaller ones. SEARCH ALL is used for binary searches; SEARCH for sequential.

How do you sort in a COBOL program? Give sort file definition, sort statement syntax and meaning. 

Answer : Syntax:

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 workfile and must be described using SD entry in FILE SECTION.
file-2 is the input file for the SORT and must be described using an FD entry in FILE SECTION and SELECT clause in FILE CONTROL.
file-3 is the outfile from the SORT and must be described using an FD entry in FILE SECTION and SELECT clause in 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.

Explain how do you define a sort file in JCL that runs the COBOL program?Answer : We can use the SORTWK01, SORTWK02. Number of sort data-sets depends on the volume of data being sorted, but a minimum of 3 is required in this case

Can you describe the difference between an internal and an external sort. Please also explain the pros and cons, internal sort syntax .? 

Answer : An external sort is not coded as a COBOL program; it is performed through JCL and PGM=SORT. One can use IBM utility SYNCSORT for external sort process. 

It is understandable without any code reference. An internal sort can use two different syntaxes: 
1. USING, GIVING sorts are comparable to external sorts with no extra file processing; 
2. INPUT PROCEDURE, OUTPUT PROCEDURE sorts allow for data manipulation before and/or after the sort.

Explain what is the difference between performing a SECTION and a PARAGRAPH? 

Answer : 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 is the use of a REPLACING option of a copy statement?
Answer : REPLACING allows for the same copy to be used more than once in the same code by changing the replace value. COPY xxx REPLACING BY .

When does the scope terminator become mandatory?
Answer : Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements. For readability, it's recommended coding practice to always make scope terminators explicit.

Can you use REDEFINES clause in the FILE SECTION?
Answer : No

How will you define your record descriptions in the FILE SECTION if you want to use three different record descriptions for the same file?
Answer : FD filename DATA RECORDS ARE rd01, rd02, rd03. 01 rd01 PIC X(n). 01 rd02 PIC X(n). 01 rd03 PIC X(n).

When will you open a file in the EXTEND mode in COBOL?
Answer : When there is an existing file that should be appended by adding new records at its end. EXTEND mode opens the file for output, but the file is positioned following the last record on the existing file.

What does a CLOSE WITH LOCK statement do in COBOL?
Answer : The statement closes an opened file and it prevents the file from further being opened by the same program.

Which mode of opening is required when REWRITE is used in COBOL?
Answer : I-O mode is required when REWRITE is used.

Why it becomes necessary that the file be opened in I-O mode for REWRITE?
Answer : Before the REWRITE is performed, the record must be read from the file. Hence REWRITE includes an input operation and an output operation. Hence, the file must be opened in I-O mode.

Which is the clause that can be used instead of checking for FILE STATUS = 10?
Answer : FILE STATUS 10 is the end of file condition. Hence, AT END clause can be used.

Explain what is a binary search?
Answer : Binary search is a search that is to be used on a sorted array. It compares the item to be searched with the item placed at the center. If the match is found, it is okay, else repeat the process with the left half or the right half depending on where the item is placed.

Can you tell me what should be the sorting order for SEARCH ALL?
Answer : It may be either ASCENDING or DESCENDING. The default one is ASCENDING. If you want a particular search to be done on an array sorted in descending order, then while defining the array, you should use the DESCENDING KEY clause.
Related Posts

No comments:


Aired | Copyright © 2009-2014| All Rights Reserved 2014

Contact Us | About Us