Wednesday, September 17, 2008

Cobol Interview Questions Part-11

178. Define the structure of a COBOL subroutine.

Ans: The PROCEDURE DIVISION header must have a using a phrase, if the data needs to be passed to the program. The operands of the USING phrase must be defined in the LINKAGE SECTION as 01-level or 77-level entries. No VALUE clause is allowed unless the data defined is a condition name.

If the program needs to be returned to the CALLER, use EXIT PROGRAM statement at the end of the program. GOBACK is an alternative, but is nonstandard.

179. What is difference between next sentence and continue

Ans: NEXT SENTENCE gives control to the verb following the next period. CONTINUE gives control to the next verb after the explicit scope terminator. (This is not one of COBOL II's finer implementations). It's safest to use CONTINUE rather than NEXT SENTENCE in COBOL II. CONTINUE is like a null statement (do nothing) , while NEXT SENTENCE transfers control to the next sentence (!!) (A sentence is terminated by a period). Check out by writing the following code example, one if sentence followed by 3 display statements: If 1 > 0 then next sentence end if display 'line 1' display 'line 2'. display 'line 3'. *** Note- there is a dot (.) only at the end of the last 2 statements, see the effect by replacing Next Sentence with Continue ***

180. What is the difference between Structured Cobol Programming and Object Oriented COBOL programming?

Ans: Structured programming is a Logical way of programming using which you divide the functionality's into modules and code logically. OOP is a Natural way of programming in which you identify the objects, first then write functions and procedures around the objects. Sorry, this may not be an adequate answer, but they are two different programming paradigms, which is difficult to put in a sentence or two.

181. PIC S9(4)COMP is used in spite of COMP-3 which occupies less space why?

Ans:S9(4) COMP uses only 2 bytes. 9(4) COMP-3 uses 3 bytes. 3 bytes are more than 2 bytes. Hence COMP is preferred over COMP-3 in this case.

182. How many number of bytes and digits are involved in S9(10) COMP?

Ans: 8 bytes (double word) and 10 digits. Up to 9(9) comp use full word, up to 9(18) comp needs double word.

183. How many numbers of decimal digits are possible, when the amount of storage allocated for a USAGE COMP item is a) half word b) full word c) double word?

Ans: 2 bytes (halfword) for 1-4 Digits 4 bytes (fullword) for 5-9

8 bytes (doubleword) for 10-18

184. What is a scope terminator? Give examples.

Ans: Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE , IF, END-IF.

185. How many dimensions are allowed for a table?

Ans: 7

186. How many subscripts or indexes are allowed for an OCCURS clause?

Ans: 7

187. Why cannot Occurs be used in 01 level?

Ans: Because, Occurs clause is there to repeat fields with the same format, but not the records.

188. Can a REDEFINES clause be used along with an OCCURS clause?

Ans: Yes, if the REDEFINES clause is subordinate to OCCURS clause.

189. Can you specify PIC clause and a VALUE with an OCCURS clause? Will the following code compile without errors?



Ans: Yes, the code will compile without any errors.

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



Ans:It cannot be executed because the code will compile with error ' "VALUE" literal "'AAAA'" exceeded the length specified in the "PICTURE" definition'.

191. 01 WS-TABLE.


03 WS-EX REDEFINES WS-TABLE-EL PIC X(5). What can you expect?

Ans: Compile error. Direct Redefinition of OCCURS clause is not allowed.

192. 01 WS-TABLE.




What would be the output of DISPLAY WS-TABLE?

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

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

Ans: No, the table must be indexed.

194. What is the difference between SEARCH and SEARCH ALL?

Ans: SEARCH - is a serial search.

SEARCH ALL - is a binary search & the table must be sorted ( ASCENDING/DESCENDING KEY clause to be used & data loaded in this order) before using SEARCH ALL.

195. What should be the sorting order for SEARCH ALL?

Ans:It can be either ASCENDING or DESCENDING. ASCENDING is default. If you want the search to be done on an array sorted in descending order, then while defining the array, you should give DESCENDING KEY clause. (You must load the table in the specified order).

196. What is binary search?

Ans:Search on a sorted array. Compare the item to be searched with the item at the center. If it matches, fine else repeat the process with the left half or the right half depending on where the item lies.

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

Ans: No, the table must be indexed.

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

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

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

No comments:

My Ad