is INITIAL PROGRAM. Other verbs used with PROGRAM-ID are RECURSIVE and COMMON.
11. When is COMMON attribute used?
Ans:
COMMON attribute is used with nested COBOL programs. If it is not specified, other nested programs will not be able to access the program. PROGRAM-ID. Pgmname is COMMON PROGRAM.
12. In which division and section, the Special-names paragraph appears?
Ans:
Environment division and Configuration Section.
13. What is the LOCAL-STORAGE SECTION?
Ans:
Local-Storage is allocated each time the program is called and is de-allocated when the program returns via an EXIT PROGRAM, GOBACK, or STOP RUN. Any data items with a VALUE clauses are initialized to the appropriate value each time the program is called. The value in the data items is lost when the program returns. It is defined in the DATA DIVISION after WORKING-STORAGE SECTION
14. What does passing BY REFERENCE mean?
Ans:
When the data is passed between programs, the subprogram refers to and processes the data items in the calling program's storage, rather than working on a copy of the data. When
CALL . . . BY REFERENCE identifier. In this case, the caller and the called share the same memory.
15. What does passing BY CONTENT mean?
Ans:
The calling program passes only the contents of the literal, or identifier. With a CALL . . . BY CONTENT, the called program cannot change the value of the literal or identifier in the calling program, even if it modifies the variable in which it received the literal or identifier.
16. What does passing BY VALUE mean?
Ans:
The calling program or method is passing the value of the literal, or identifier, not a reference to the sending data item. The called program or invoked method can change the parameter in the called program or invoked method. However, because the subprogram or method has access only to a temporary copy of the sending data item, those changes do not affect the argument in the calling program. Use By value, If you want to pass data to C program. Parameters must be of certain data type.
17. What is the default, passing BY REFERENCE or passing BY CONTENT or passing BY VALUE?
Ans:
Passing by reference (the caller and the called share the same memory).
18. Where do you define your data in a program if the data is passed to the program from a Caller program?
Ans:
Linkage Section
19. 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.
20. 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 ***
21. 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.
22. PIC S9(4)COMP IS USED INPSPITE 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.
23. How many number of bytes and digits are involved in S9(10) COMP?
8 bytes (double word) and 10 digits. Up to 9(9) comp use full word, up to 9(18) comp needs double word.
24. Which picture clause will you use to define a hexadecimal item in a VALUE clause?
Ans:
01 ws-hexitem PIC X(2) value X'020C'.
01 ws-hex redefines PIC S9(3) comp-3.
25. 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
26. What is a scope terminator? Give examples.
Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE; IF, END-IF.
27. How many dimensions are allowed for a table?
Ans:
7
28. How many subscripts or indexes are allowed for an OCCURS clause?
Ans:
7
29. 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.
30. Can a REDEFINES clause be used along with an OCCURS clause?
Ans:
Yes, if the REDEFINES clause is subordinate to OCCURS clause.
31. Can you specify PIC clause and a VALUE with an OCCURS clause? Will the following code compile without errors?
01 WS-TABLE.
03 WS-TABLE-EL OCCURS 5 TIMES PIC X(1) VALUE SPACES.
Ans:
Yes, the code will compile without any errors.
32. 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 'AAAAA'.
Ans:
It cannot be executed because the code will compile with error ' "VALUE" literal "'AAAA'" exceeded the length specified in the "PICTURE" definition'.
33. 01 WS-TABLE.
03 WS-TABLE-EL OCCURS 5 TIMES PIC X(1) VALUE 'A'.
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.
34. 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?
Ans:
'AAAAA'. The code will compile and execute as Redefinition of an item subordinate to OCCURS clause.
35. 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).
Ans:
Yes
35. 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).
Ans:
Yes
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?
01 WS-TABLE.
03 WS-TABLE-EL OCCURS 5 TIMES PIC X(1) VALUE 'A'.
:::
DISPLAY WS-TABLE.
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 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.
.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?
Ans:
PERFORM ... ... END-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.)