Wednesday, September 17, 2008

Cobol Interview Questions Part-3

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

The serial SEARCH verb (SEARCH without ALL)

37. What would be the output, when the following code is executed?





Ans: The output will display 'AAAAA'

38. Can a SEARCH be applied to a table which does not have an INDEX defined?

Ans: No, the table must be indexed.

39. What are the different rules applicable to perform a serial SEARCH?

Ans: 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

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

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

41. What are the different rules applicable to perform a binary SEARCH?

Ans: 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

42. How does the binary search work?

Ans: 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.

43. What is the difference between a binary search and a sequential search? What are the pertinent COBOL commands?

Ans: In 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. 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. 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.

44. Explain the difference between an internal and an external sort. The pros & cons & internal sort syntax ...

Ans: 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. Syntax:

SORT file-1 ON ASCENDING/DESCENDING KEY key...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 work file 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. .How do you 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.

45. Which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement?

TEST BEFORE. By default the condition is checked before executing the instructions under Perform.

46. What is the difference between PERFORM ... WITH TEST AFTER and PERFORM ... WITH TEST BEFORE?

Ans:If TEST BEFORE is specified, the condition is tested at the beginning of each repeated execution of the specified PERFORM range. If TEST AFTER is specified, the condition is tested at the end of the each repeated execution of the PERFORM range. With TEST AFTER, the range is executed at least once.

47. How do you code an in-line PERFORM?


48. 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.

49. What is the default value(s) for an INITIALIZE and what keyword allows for an override of the default.

Ans:INITIALIZE sets spaces to alphabetic and alphanumeric fields. Initialize sets Zeroes to numeric fields. FILLER, OCCURS DEPENDING ON items are left untouched. The REPLACING option can be used to override these defaults.

50. What is SET TO TRUE all about, anyway?

Ans:In COBOL II the 88 levels can be set rather than moving their associated values to the related data item. (Web note: This change is not one of COBOL II's better specifications.) 

No comments:

My Ad