COBOL Interview Questions and Soultions

1/04/2010 No Comment

Mainframe COBOL Question Answers.

Explain what are the different rules that needs to be applied to perform a binary SEARCH?
Answer : For a binary search, the table must be sorted in ascending or descending order before the beginning of the SEARCH. Use OCCURS clause with ASC/DESC KEY IS dataname1 option
The table must be indexed. There is no need to set the index value. Use SEARCH ALL verb.

Can a SEARCH be applied to a table which does not have an INDEX defined?
Answer : No, the table must be indexed.

Can you describe the different rules applicable to perform a serial SEARCH? 

Answer : The SEARCH can be applied to only a table which has the OCCURS clause and INDEXED BY phrase, before the use of the SEARCH the index must have some initial value. To search from beginning, set the index value to 1. Use the SEARCH verb without ALL phrase

Consider a scenario where a table has two indexes defined. Which one will be used by the SEARCH verb?

Answer : The index named first will be used, by Search.

Is this allowed?
01 WS-TABLE.
03 FILLER-X PIC X(5) VALUE 'AAAAA'.
03 WS-EX REDEFINES FILLER-X OCCURS 5 TIMES PIC X(1).
 

Answer : Yes

Which SEARCH verb is equivalent to PERFORM...VARYING?

Answer : The serial SEARCH verb (SEARCH without ALL)

What would be the output, when the following code is executed?
01 WS-TABLE.
03 WS-TABLE-EL OCCURS 5 TIMES PIC X(1) VALUE 'A'.
:::
DISPLAY WS-TABLE.

Answer : The output will display 'AAAAA'

Explain how does the binary search work?

Answer : In binary search, 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 then continues until the item is found. SEARCH ALL is efficient for tables which has more than 70 items.

01 WS-TABLE.
03 WS-TABLE-EL OCCURS 5 TIMES.
04 FILLER-X PIC X(1) VALUE 'A'. 04 WS-EX REDEFINES FILLER-X PIC X(1).
What would be the output of DISPLAY WS-TABLE?

Answer : 'AAAAA'. The code will compile and execute as Redefinition of an item subordinate to OCCURS clause.

Is this allowed?
01 WS-TABLE.
03 FILLER-X PIC X(5) VALUE 'AAAAA'.
03 WS-EX REDEFINES FILLER-X.
04 WS-TABLE-EL OCCURS 5 TIMES PIC X(1).

Answer : Yes


Can you tell me which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement? 
Answer : TEST BEFORE. By default the condition is checked before executing the instructions under Perform.

Explain the main difference between a binary search and a sequential search? What are the pertinent COBOL commands used? 

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

However, in a sequential search the table is searched from top to bottom, so (ironically) the elements do not have to be in a specific sequence., Sequential Search works well with smaller tables. SEARCH ALL is used for binary searches whereas SEARCH for sequential.

Explain how do you define a sort file in JCL that runs the COBOL program? 

Answer : We have to 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.
Related Posts


No comments :

 

Aired | The content is copyrighted and may not be reproduced on other websites. | Copyright © 2009-2016 | All Rights Reserved 2016

Contact Us | About Us | Privacy Policy and Disclaimer