Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 32

COBOL FAQ

REVISION LIST

Document Name: COBOL FAQ

Version Author Date Changes done Remarks


1.0 Bear Stearns 07/23/2003 - -
Relationship Team
Table of Contents

Divisions.......................................................................................................................................................1
Levels...........................................................................................................................................................2
Data Types....................................................................................................................................................4
Procedure Division Commands....................................................................................................................6
Performs.....................................................................................................................................................11
Usage..........................................................................................................................................................13
Table Handling...........................................................................................................................................16
Subscripts and Indexes...............................................................................................................................17
Sorting........................................................................................................................................................19
File Handling..............................................................................................................................................20
Subroutines.................................................................................................................................................21
Compiler Options.......................................................................................................................................23
Character Handling.....................................................................................................................................24
Misc............................................................................................................................................................27
Divisions

1. What are the Different components of COBOL


Character : Lowest component
Word : One or more characters
Clause : Words and characters specifying attribute of entry
Statement : Syntactically valid combination of words and clauses
Sentence : Sequence of one or more statements terminated by
period
Paragraph : one or more sentences
Section : one or more paragraphs
Division : One or more paragraphs or sections
Program : Made up of divisions

2. Name the divisions in a COBOL program?


Identification Division : Identifies Program

Environment Division : Defines Computer used


Defines Files

Data Division : Describes Files


Defines Variables, Constants

Procedure Division : Actual logic of program

3. HOW MANY SECTIONS ARE IN DATA DIVISION?


Three main sections
1.FILE SECTION
2.WORKING-STORAGE SECTION
3.LINKAGE SECTION

1
Levels

4. What are the different levels available in COBOL?


Level Numbers available are 01-49, 66, 77, 88
01-49 Group or elementary items
66 Renames clause
77 Independent elementary data items
88 Condition names

5. What is 77 level used for?


Elementary level item. Cannot be subdivisions of other items (cannot be
qualified), nor can they be subdivided themselves.

6. What is 88 level used for?


88 level is used for condition names.
The level 88 in the Data Division can be used to give condition names to the
values that a field contains. A condition name entry specifies either a single
value or a set of values for the condityional variable. When this level is specified
you can use the condition name instead of is equal to in the IF statement.
Condition name should be specified under Level 88 immediately following the
field description.

Example:
01 WS-MARITAL-STATUS PIC X.
88 SINGLE VALUE “Y”.
88 MARRIED VALUE ‘N’.
01 WS-REPLY PIC X.
88 REPLY-YESVALUE “Y”.
88 REPLY-N0 VALUE “N”.
01 WS-MARKS PIC 999.
88 PASSED
VALUE 40 THRU 100.
88 FAILED
VALUE 0 THRU 39.

7. What are level 66 used for?


For RENAMES clause.

8. What is the difference between level 77 and 01? And which is more
efficient?
Level 77 can be used to describe independent elementary items in the Working
Storage or Linkage Sections. Level 77 cannot use Redefines.

Level 01 can be used to describe both elementary and group items. Any item
described in Level 01, the system is putting on Double-Word boundary and
inserts slack bytes if necessary

2
9. How many different level numbers can be used in COBOL to describe a
record?
01-49.

10. Give some advantages of REDEFINES clause.


1.You can REDEFINE a Variable from one PICTURE class to another PICTURE
class by using the same memory location. Multiple REDEFINES of same area
possible
2. By REDEFINES we can INITIALISE the variable in WORKING-STORAGE Section
itself.
3. We can REDEFINE a Single Variable into many sub-variables.

Syntax:
<Level> <DataName1> REDEFINES <DataName2>

Example:

01 Sales-Record.
02 Sales-Type Pic X.
02 Sales-By-Unit.
03 Qty Pic 9(4).
03 Unit-Price Pic 9(8)V99.
02 Total-Sales REDEFINES Sales-By-Unit.
03 Amount Pic 9(10)V99.
03 Filler Pic X(2).

11. Can I redefine an X (100) field with a field of X (200)?


Yes.
Redefines just cause both fields to start at the same location. For example:
01 WS-TOP PIC X (1)
01 WS-TOP-RED REDEFINES WS-TOP PIC X (2).

If you MOVE ‘12’ to WS-TOP-RED,


DISPLAY WS-TOP will show 1 while
DISPLAY WS-TOP-RED will show 12.

12. Can I redefine an X (200) field with a field of X (100)?


Yes.

3
Data Types

13. What are the different data types available in COBOL?


Numeric,
Alphabetic ,
Alpha-numeric ,

Numeric Edited and


Alphanumeric Edited.

Symbols used
Numeric 9 PSV
Alphabetic A B
Alphanumeric X 9A
Numeric Edited 9 P V and at least one of the editing symbols
B / Z 0 + - * , . CR DB $
Alphanumeric Edited X 9AB0/

Example:,
77 WS-MESSAGE PIC X(30).
77 WS-NUMBER PIC 9999.

14. What are the permissible character sets in COBOL?


Digits 0,1,2…9
Letters A,B,…Z
Space/Blank B
Special Symbols + - * / ( ) $.“ < > =

15. What are all the figurative constants available in COBOL?


Zero, Zeroes, Zeros
Quote, Quotes
Space, Spaces
High-Value, Highest-Value
Low-Value, Lowest-Value
All

16. What are all the possible Editing Characters used in COBOL. Explain
them with examples?
Numeric Data
Z Zero Suppression
* Asterisk
$ Currency Sign
- Minus Sign
+ Plus Sign
CR DB Credit Debit Sign
Period (.)

4
Comma ,)
Blank (‘b’)
Zero (0)
Slash (/)
Blank When Zero
Inserts blanks when data value is zero
Alpha Numeric Data
Blank, Zero,Slash Insertion

Note:
Mutually Exclusive PIC Clauses
CR and DB
$+_ Z*
V.

Example:

PIC Numeric Edited


Value Value
ZZZV99 38^4 b3840
* * 999 00052 * * 052
$ * *999 985 $**985
-ZZZV99 -46^52 -b4652
+999 -382 -382
+999 382 +382
9999+ -382 0382-
ZZ,Z99 2456 b2,456
ZZZZ.ZZ 0^05 bbbb.05
$$$$9.99 342 b$342.00
99B99B99 46 00b00b46
09990 456 04560
999/999/99 3254 000/032/54

17. What is the difference between PIC 9.99 and 9v99?


PIC 9.99 is a FOUR-POSITION field that actually contains a decimal point where
as PIC 9v99 is THREE-POSITION numeric field with implied or assumed decimal
position.

18. What is PIC 9v99 Indicates?


PICTURE 9v99 is a three position Numeric field with an implied or assumed
decimal point after the first position; the v means an implied decimal point.

19. Can JUSTIFIED be used for all the data types?


No, it can be used only with alphabetic and alphanumeric data types.

5
Procedure Division Commands

20. Write a Sample Program in COBOL


IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE.
ENVIRONMENT DIVISION.
SOURCE-COMPUTER. ES-9000.
OBJECT-COMPUTER. ES-9000.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-NAME PIC X(30).
PROCEDURE DIVISION.
MAIN-LOGIC.
PERFORM DISPLAY-ACCEPT-PARA.
STOP RUN.
DISPLAY-ACCEPT-PARA.
DISPLAY “Enter your name:”.
ACCEPT WS-NAME.
DISPLAY “Welcome ”, WS-NAME.

21. Explain the four COBOL statement categories?


Imperative
Conditional
Compiler Directing
Explicit Scope Terminator

Imperative Statement
Directs program to take specific action during execution
ADD 1 TO A.
MOVE 2 TO A.
Conditional Statement
Directs program to examine the truth of a condition and take subsequent action
depending on truth
IF A > B
DISPLAY “A IS GREATER”
ELSE
DISPLAY “B IS GREATER’
END-IF.
Compiler-directing Statement
Directs COBOL compiler and no corresponding statement is generated for these
in the object program
COPY
USE
Explicit Scope Terminators
Statements used to terminate the scope of a COBOL verb explicitly
END-IF
END-PERFORM

22. What are the two types of control transfer statements?

6
1. Conditional Transfer statements
Based on result of condition check
IF
EVALUATE
GOTO..DEPENDING ON
2. Unconditional Transfer
PERFORM
GOTO

23. Explain the Syntax and Usage of GOTO DEPENDING ON STATEMENT?


Syntax:
GOTO Procedure-Name-1
[Procedure-Name-2]
Procedure-Name-N
DEPENDING ON Identifier

Control transferred depending on value of identifier


Identifier must be numeric,integral elementary item
Control transferred to next statement if value of identifier is not in range
specified

Example:
GOTO RECEIPT-PARA,
ISSUE-PARA,
ADJUSTMENT-PARA
DEPENDING ON TRAN-TYPE.
Equivalent to
IF TRAN-TYPE = 1
GOTO RECEIPT-PARA.
IF TRAN-TYPE = 2
GOTO ISSUE-PARA.
IF TRAN-TYPE = 3
GOTO ADJUSTMENT-PARA.

24. Give the syntax for ADD/SUBTRACT STATEMENTS?


ADD
[CORRESPONDING]
[Identifier-1 / Literal-1] [Identifier-2 / Literal-2]
[TO / GIVING] Identifier-3, Identifier-4, ...

SUBTRACT
[CORR]
[Identifier-1 / Literal-1] [Identifier-2 / Literal-2]
[FROM / GIVING] Identifier-3, iodentifier-4, ...

25. Give the syntax for MULTIPLY AND DIVIDE STATEMENTS?

MULTIPLY
{Identifier-1 BY Identifier-2

7
[ , Identifier-3]... Literal - 1}
[GIVING Identifier-4 [ , Identifier-5]...]
DIVIDE {Identifier-1 / Literal-1}
INTO[BY] Identifier-2 { ,Identifier-3}....
[GIVING Identifier-4 [ ,Identifier-5]...]
[REMAINDER Identifier-6].

26. Explain the applications of ROUNDED VERB in COBOL?


Rounded clause could be used to get the output rounded to specified size
Applicable only for receiving fields
Cannot be specified after Remainder
E.g.,
ADD A B GIVING C ROUNDED.

27. Explain the applications of ON SIZE ERROR in COBOL?


If after an arithmetic operation, the result exceeds the largest value that can be
accommodated in the result field, the error is called a size error. Programmers
can control Size Error in any arithmetic statement using this phrase.
E.g.,
ADD A TO B ON SIZE ERROR
GO TO ERROR-PARA.

28. Give the Syntax for COMPUTE VERB?


COMPUTE {Identifier-1 [ROUNDED]}
[Identifier-2 [ROUNDED]]
Arithmetic Expression
[ON SIZE ERROR
Imperative Statement]

29. What is the use of EVALUATE statement? -


Evaluate is like a case statement and can be used to replace nested Ifs. The
difference between EVALUATE and case is that no ‘break’ is required for
EVALUATE i.e. control comes out of the EVALUATE as soon as one match is
made.

30. What are the different forms of EVALUATE statement? Give the Syntax
and Example
Syntax:
EVALUATE Subject-1 [ALSO Subject-2]...
{WHEN Object-1 [ALSO Object-2]....
{Imperative-Statement1}...}
{WHEN OTHER
{Imperative-Statement2}...]
[END-EVALUATE.]

8
Example:
EVALUATE TRUE
WHEN MONTH = 4 OR 6 OR 9 OR 11
MOVE 30 TO NO-OF-DAYS
WHEN MONTH = 2
MOVE 28 TO NO-OF-DAYS
WHEN OTHER
MOVE 31 TO NO-OF-DAYS
END-EVALUATE.

EVALUATE PRODUCT-TYPE ALSO CUSTOMER-TYPE


WHEN 1 ALSO ANY
MOVE 0 TO COMMISSION
WHEN 2 ALSO 1 THRU 5
MOVE 10 TO COMMISSION
WHEN 3 ALSO 1 THRU 5
MOVE 5 TO COMMISSION
WHEN OTHER
MOVE 20 TO COMMISSION
END-EVALUATE.

31. How do you come out of an EVALUATE statement? -


After the execution of one of the when clauses, the control is automatically
passed on to the next sentence after the EVALUATE statement. There is no need
of any extra code.

32. In an EVALUATE statement, can I give a complex condition on a when


clause?
Yes.

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

34. What does the INITIALIZE verb does?


Alphabetic, Alphanumeric fields & alphanumeric edited items are set to SPACES.
Numeric, Numeric edited items set to ZERO. FILLER and OCCURS DEPENDING
ON items left untouched.

35. What does the IS NUMERIC clause establish?


IS NUMERIC can be used on alphanumeric items, signed numeric & packed
decimal items and unsigned numeric & packed decimal items. IS NUMERIC
returns TRUE if the item only consists of 0-9. However, if the item being tested
is a signed item, then it may contain 0-9, + and -.

36. What are all the arithmetic Verbs and Arithmetic Operations?
Arithmetic Verbs

9
Add
Subtract
Multiply
Divide
Compute

ARITHMETIC OPERATORS
Addition +
Subtraction -
Multiplication *
Division /
Exponentiation **
HIERARCHY
( ) ** * OR / + OR - From Left to Right

37. What is difference between next sentence and continue?


CONTINUE is like a null statement (do nothing), while NEXT SENTENCE transfers
control to the next sentence. (A sentence is terminated by a period)

38. What does EXIT do?


Does nothing. If used, must be the only sentence within a paragraph.

10
Performs

39. Name the different PERFORM statement?


PERFORM
PERFORM THRU
PERFORM 'n' TIMES
PERFORM UNTIL
PERFORM VARYING with UNTIL Option.

PERFORM
PERFORM [Procedure-Name-1
END-PERFORM.

PERFORM THRU
PERFORM [Procedure-Name-1
[{Thru} Procedure-Name-2]]
[Imperative-Statement-1
END-PERFORM.]

PERFORM 'n' TIMES


PERFORM [Procedure-Name-1
[{Thru} Procedure-Name-2]]
{Identifier-1/Integer} TIMES
[Imperative-Statement-1]
END-PERFORM.]

PERFORM UNTIL
PERFORM [Procedure-Name-1
[{THRU} Procedure-Name-2]]
[WITH TEST {BEFORE AFTER} UNTIL cond-1]
[Imperative-Statement-1
END-PERFORM.]
E.g.,
PERFORM COUNT-PARA
WITH TEST AFTER
UNTIL WS-COUNT > 10.

40. How do you do in-line PERFORM? -


PERFORM ... <UNTIL> ...
<sentences>
END PERFORM

41. When would you use in-line perform?


When the body of the perform will not be used in other paragraphs. If the body
of the perform is a generic type of code (used from various other places in the
program), it would be better to put the code in a separate PARA and use
PERFORM para-name rather than in-line perform.

11
42. Read the following code and tell how many times will B-PARA be
executed ?
01 ws-n pic 9(2) value zero.

a-para
Move 5 to ws-n.
perform b-para ws-n times.

B-PARA.
move 10 to ws-n.

5 times only. it will not take the value 10 that is initialised in


the loop.

12
Usage

43. How many different data USAGEs can be used in COBOL?


DISPLAY, COMP, COMP-3, INDEX, POINTER.

44. Explain the USAGE of COMP/COMP1/COMP2/COMP3


USAGE COMP
Maintained in binary
Only integral numbers
Depending on the size of the data item, stored either in half word or full word
Should be numeric only

PIC Length in bytes


1 TO 4 2
5 TO 9 4
10 TO 18 8

USAGE COMP1
One word in floating point form
Number represented in hexadecimal
Picture clause cannot be specified
Suitable for arithmetic operations
COMP-2 USAGE
Same as COMP-1 except that data represented internally in two words
Increases precision of the data. Picture clause cannot be specified.
COMP-3 USAGE
Internal Representation In Packed Decimal Form
Each digit and sign occupy 1/2 byte
Hexadecimal number C or F denotes positive sign
Hexadecimal number D denotes negative sign

45. What is a USAGE IS INDEX?


USAGE IS INDEX represents an index data item which is Full-Word binary and is
used to save the value of the index. That Index Data Item can be set to the
value of the Index thru the SET statement, ex. SET WS-IND-SAVE-FLD TO ITEM-
IND. Index data item is not directly related to any table.

46. PIC S9(4)COMP IS USED INSPITE OF COMP-3 WHICH OCCUPIES LESS


SPACE for this particular case and WHY?
9(4) COMP uses only 2 bytes.
9(4) COMP-3 uses 3 bytes.
3 bytes is more than 2 bytes. Hence COMP is preferred over COMP-3 in this
case.

47. How to display the fields whose usage is COMP?


When we try to display a data item with usage as computational it does not give
the desired display format because the data item is stored as packed decimal. So
if we want this particular data item to be displayed, we have to move it into a

13
data item whose usage is display and then have that particular data item edited
in the format desired.

48. What is the maximum length of a field you can define using COMP-3?
10 Bytes (S9(18) COMP-3).

49. How is sign stored in Packed Decimal fields and Zoned Decimal fields?
Packed Decimal fields: Sign is stored as a hex value in the last nibble (4 bits )
of the storage.
Zoned Decimal fields: As a default, sign is over punched with the numeric
value stored in the last bite.

50. How is sign stored in a comp-3 field? -


It is stored in the last nibble. For example if your number is +100, it stores hex
0C in the last byte, hex 1C if your number is 101, hex 2C if your number is 102,
hex 1D if the number is -101, hex 2D if the number is -102 etc...

51. How is sign stored in a COMP field ? -


In the most significant bit. Bit is on if -ve, off if +ve.

52. What is the difference between COMP & COMP-3 ?


COMP is a binary storage format while COMP-3 is packed decimal format.

53. How do you define a variable of COMP-1? COMP-2?


No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.

54. How many bytes does a S9(7) COMP-3 field occupy ?


Will take 4 bytes. Sign is stored as hex value in the last nibble.
General formula is INT((n/2) + 1)), where n=7 in this example.

55. How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?
Will occupy 8 bytes (one extra byte for sign).

56. How many bytes will a S9(8) COMP field occupy ?


4 bytes.

57. What is the maximum value that can be stored in S9(8) COMP?
99999999

58. What is the maximum size of a 01 level item in COBOL I? in COBOL II?
In COBOL II: 16777215

59. What is COMP SYNC?

14
Causes the item to be aligned on natural boundaries. Can be SYNCHRONIZED
LEFT or RIGHT.
For binary data items, the address resolution is faster if they are located at word
boundaries in the memory. For example, on main frame the memory word size
is 4 bytes. This means that each word will start from an address divisible by 4.
If my first variable is x(3) and next
one is s9(4) comp, then if you do not specify the SYNC clause, S9(4) COMP will
start from byte 3 ( assuming that it starts from 0 ). If you specify SYNC, then
the binary data item will start from address 4. You might see some wastage of
memory, but the access to this
computational field is faster.

60. Explain the usage of SIGN CLAUSE?


[SIGN IS] [LEADING] [SEPARATE CHAR ] [TRAILING]

Specifies position and mode of representation


Picture string should contain ‘S’
Any input field for negative value should contain ‘SEPARATE CHAR’
Only for numeric elementary items Usage should be DISPLAY
Default TRAILING without separate character

PIC VALUE SIGN REPRESENTATION


S9(3) -243 LEADING K 4 3
S9(3) -243 TRAILING 2 4 L

15
Table Handling

61. Why occurs can not be used in 01 level?


Occurs clause is there to repeat fields with same format, not the records.

62. What is the maximum number of dimensions that an array can have in
COBOL?.
SEVEN in COBOL - 85 and THREE in COBOL - 84

63. How do you define a table/array in COBOL?


01 ARRAYS.
05 ARRAY1 pic X(9) OCCURS 10 TIMES.
05 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX.

16
Subscripts and Indexes

64. What is a subscript?


Subscript represents occurrence # of the Table Entry. Subscript can be
represented explicitly and implicitly. Explicitly means thru occurrence # of the
table entry; implicitly means thru a data name. That data name should be
defined as an independent item in the Working-Storage Section. The most
efficient definition of Subscript is Full-Word binary.

65. What is an index?


Index is assigned to specific table thru INDEXED BY clause. Internally is
represented by Index register, which is Full-Word binary. Specific index name
can be used to reference a field from the table to which that index is assigned to
index represents displacement value of the table entry from the beginning of the
table.

66. What is the difference between Subscript and Index?


Index represent displacement value of the table entry from the beginning of the
table,
subscript - occurrence # of the table entry. To calculate the displacement of the
table entry from its beginning when subscript is used takes 16 additional
instructions from the system because of that the usage of the index is more
efficient.
An index can only be modified using PERFORM, SEARCH & SET.
Need to have index for a table in order to use SEARCH, SEARCH ALL.

67. What are the different ways of an internal table search?


a. Sequential Search statement. (SEARCH)
b. Binary search statement. (SEARCH ALL)

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


Serial search (SEARCH) examines each table entry starting at the beginning,
whereas a binary search (SEARCH ALL) starts looking at the mid-point of the
table and works its way toward the argument depending upon if its too high or
too low. A serial search can be used for unsorted tables, while a binary search is
only useful if the tables are sorted.

SEARCH ALL is more efficient for tables larger than 70 items.

69. What should be the sorting order for SEARCH ALL? -


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

17
70. What is binary search?
Search on a sorted array. Compare the item to be searched with the item at the
middle. If it matches, fine else repeat the process with the left half or the right
half depending on where the item lies.

71. My program has an array defined to have 10 items. Due to a bug, I find
that even if the program access the 11th item in this array, the program
does not ABEND. What is wrong with it?
Must use compiler option SSRANGE if you want array bounds checking. Default
is NOSSRANGE.

72. How to change the value of an index in a COBOL programs?


A SET statement.

18
Sorting

73. What is the different types of sorting available?


Internal sort and external sort.

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

SORT file-1 ON ASCENDING/DESCENDING 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 out-file 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.

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

76. What is the difference between performing a SECTION and a


PARAGRAPH? -
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.

19
File Handling

77. How do you reference the following file formats from COBOL programs:
Fixed Block File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING
MODE IS F, BLOCK CONTAINS 0 .
Fixed Unblocked - Use ORGANISATION IS SEQUENTIAL. Use RECORDING
MODE IS F, do not use BLOCK CONTAINS
Variable Block File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING
MODE IS V, BLOCK CONTAINS 0. Do not code the 4 bytes for record length in FD
i.e. JCL REC length will be max rec. length in pgm + 4
Variable Unblocked - Use ORGANISATION IS SEQUENTIAL. Use RECORDING
MODE IS V, do not use BLOCK CONTAINS. Do not code 4 bytes for record length
in FD i.e. JCL rec length will be max rec length in pgm + 4.
ESDS VSAM file - Use ORGANISATION IS SEQUENTIAL.
KSDS VSAM file - Use ORGANISATION IS INDEXED, RECORD KEY IS,
ALTERNATE RECORD KEY IS
RRDS File - Use ORGANISATION IS RELATIVE, RELATIVE KEY IS
Printer File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS
F, BLOCK CONTAINS 0. (Use RECFM=FBA in JCL DCB).

78. What are different file OPEN modes available in COBOL?


INPUT,
OUTPUT,
I-O,
EXTEND.

79. What is the mode in which you will OPEN a file for writing? -
OUTPUT, EXTEND

80. In the JCL, how do you define the files referred to in a subroutine ?
Supply the DD cards just as you would for files referred to in the main program.

81. Can you REWRITE a record in an ESDS file? Can you DELETE a record
from it?
Can rewrite(record length must be same), but not delete.

82. What is file status 92? -


Logic error. e.g., a file is opened for input and an attempt is made to write to it.

83. What is file status 39 ?


Mismatch in LRECL or BLOCKSIZE or RECFM between your COBOL pgm & the JCL
(or the Dataset label). You will get file status 39 on an OPEN.

20
Subroutines

84. What is the LINKAGE SECTION used for?


The linkage section is used to pass data from one program to another program
or to pass data from a PROC to a program.

85. What is the difference between static call and dynamic call in COBOL?
A statically called program is link-edited into the same load module as the calling
program; a static call is faster than a dynamic call. A static call is the preferred
method if your application does not require the services of the dynamic call.

Statically called programs cannot be deleted (using CANCEL), so static calls


might take more main storage. If storage is a concern, think about using
dynamic calls. Storage usage of calls depends on whetherThe subprogram is
called only a few times. Regardless of whether it is called, a statically called
program is loaded into storage; a dynamically called program is loaded only
when it is called.

You subsequently delete the dynamically called subprogram with a CANCEL


statement.

You cannot delete a statically called program, but you can delete a dynamically
called program. Using a dynamic call and then a CANCEL statement to delete the
dynamically called program after it is no longer needed in the application (and
not after each call to it) might require less storage than using a static call.

Dynamically called modules are those that are not bound with the calling
program at link edit time (IEWL for IBM) and so are loaded from the program
library (job lib or step lib) associated with the job. For DYNAMIC calling of a
module the DYNAM compiler option must be chosen, else the linkage editor will
not generate an executable as it will expect null address resolution of all called
modules. A Statically called module is one that is bound with the calling module
at link edit, and therefore becomes part of the executable load module.

86. How can I tell if a module is being called DYNAMICALLY or STATICALLY?


The ONLY way is to look at the output of the linkage editor (IEWL) or the load
module itself. If the module is being called DYNAMICALLY then it will not exist in
the main module, if it is being called STATICALLY then it will be seen in the load
module.
Calling a working storage variable, containing a program name, does not make a
DYNAMIC call. This type of calling is known as IMPLICITE calling as the name of
the module is implied by the contents of the working storage variable.

87. PGM-A calls PGM-B. What will happen when PGM-B issues STOP RUN?
The control will not come back to PGM-A after the execution of PGM-B and hence
PGM-B will stop abruptly.

21
88. PGM-A calls PGM-B recursively. What will happen to the Data Items
declared in PGM-B?
The status of Data Items will get changed whenever the PGM-B is called. Thus
when control leaves a subroutine, it is not likely to be in the same state in which
it was entered. If the same sub routine is called again, it will be entered in its
last used state.
Note:
If you want to have the subroutine in its initial state, the subroutine should be
called after having cancelled its current state by means of a CANCEL statement.

22
Compiler Options

89. What compiler option would you use for dynamic linking?
DYNAM.

90. What is SSRANGE, NOSSRANGE ?


These are compiler options wrt subscript out of range checking. NOSSRANGE is
the default and if chosen, no run time error will be flagged if your index or
subscript goes out of the permissible range.

91. What care has to be taken to force program to execute above 16-MB
line?
Make sure that link option is AMODE=31 and RMODE = ANY.
Compile option should never have SIZE(MAX).
BUFSIZE can be 2K, efficient enough.

92. What are AMODE and RMODE? What is AMODE(24), AMODE(31),


RMODE(24) and RMODE(ANY)? What do 24 or 31 mean to it?
( applicable to only MVS/ESA Enterprise Server).

Addressing Mode/Access Mode


AMODE(24) indicates 24-bit (three-byte) addressing - memory below the line.
AMODE(31) indicates 31-bit addressing - memory above and below the line.
AMODE=ANY indicates the program may use either of the addressing technique.

Run Mode/Residency Mode


RMODE(24) indicates that the program must be loaded into memory below the
line. Resides in virtual storage below 16-MB line. Use this for 31 bit programs
that call 24 bit programs. (OS/VS Cobol programs use 24 bit addresses only).

RMODE(31) indicates that the program can be loaded either below or above the
line.
RMODE=ANY indicates that the program can be run in either 24 bit (below)or 31
bit memory (above).
These are compile/link edit options.

AMODE - Addressing mode. RMODE - Residency mode.


AMODE(24) - 24 bit addressing.
AMODE(31) - 31 bit addressing.
AMODE(ANY) - Either 24 bit or 31 bit addressing depending on RMODE.

RMODE(24) - Resides in virtual storage below 16-MB line. Use this for 31 bit
programs that call 24 bit programs. (OS/VS Cobol programs use 24 bit
addresses only).
RMODE(ANY) - Can reside above or below 16 MB line.

23
Character Handling

93. What is the Purpose of POINTER Phrase in STRING command?


The Purpose of POINTER phrase is to specify the leftmost position within
receiving field where the first transferred character will be stored

94. How will you move the part of character field to other character field?
By Reference modification
e.g.,.
To move the first 4 Chars of a variable ABC to XYZ:
MOVE ABC (1:4) TO XYZ

24
Abends

95. What are the causes for S0C1, S0C4, S0C5, S0C7, and S0CB ABENDs?
S0C1 - May be due to
1.Missing or misspelled DD name
2.Read/Write to unopened DataSet
3.Read to DataSet opened output
4.Write to DataSet opened input
5.Called subprogram not found
S0C4 - May be due to
1.Missing Select statement (during compile)
2.Bad Subscript/index
3.Protection Exception
4.Missing parameters on called subprogram
5.Read/Write to unopened file
6.Move data from/to unopened file
S0C5 - May be due to
1.Bad Subscript/index
2.Close an unopened DataSet
3.Bad exit from a perform
4.Access to I/O area (FD) before read
S0C7 - May be due to
1.Numeric operation on non-numeric data
2.Un-initialize working-storage
3.Coding past the maximum allowed sub script
S0CB - May be due to
1.Division by Zero

96. What do you do to resolve SOC-7 error? -


Basically you need to correct the offending data.

Many times the reason for SOC7 is an uninitialized numeric item. Examine that
possibility first.

Many installations provide you a dump for run time ABENDs ( it can be
generated also by calling some subroutines or OS services thru assembly
language). These dumps provide the offset of the lastinstruction at which the
ABEND occurred. Examine the compilation
output XREF listing to get the verb and the line number of the source code at
this offset. Then you can look at the source code to find the bug. To get
capture the runtime dumps, you will have to define some Data Sets
(SYSABOUT etc ) in the JCL.

If none of these are helpful, use judgement and DISPLAY to localise the source
of error.

Some installation might have batch program debugging tools. Use them.

97. What is SOC1 and SOC4?

25
A S0C1 occurs if the CPU attempts to execute binary code that isn't a valid
machine instruction; e.g. if you attempt to execute data. A S0C4 is a memory
protection violation. This occurs if a program attempts to access storage beyond
the areas assigned to it.

26
Misc.

98. What is the Structured programming and how do you identify it?
The difference between regular programming approach and structured
programming is that structured programs get rid of GO TO statements and the
whole programs can be represented in a Top-Down design. This design is
possible because of existence of 3 basic structures:

a. Sequence Structure: Within sequence structure all functions are executed in


their physical order. The structure has one entry point and one exit point.

b. Selection Structure: Within selection structure execution of the function


depends on whether conditions true or false. The structure has one entry point
and one exit point.

c. Iteration Structure: Within iteration structure the execution of the function will
be reiterated over and over again until condition becomes true. The structure
has one entry point and one exit point. All these structures have one entry point
and one exit point. Because of this if the programs is written by using only these
structures, the whole programs will have one entry point and one exit point.

99. What are advantages of Structured Programming?


The programs gets rid of GO TO statements and is represented by Top-Down
Structure which is visible and easy to understand, because the programs has a
specific (hierarchical) structure, it is easy to debug the programs.

100. What is the difference between Structured Cobol Programming and


Object Oriented COBOL programming?
Structured programming is a logical way of programming; you divide the
functionalities into modules and code logically. OOP is a Natural way of
programming; you identify the objects first, and then write functions, procedures
around the objects.

101. What will happen if you code GO BACK instead of STOP


RUN in a stand alone COBOL program i.e. a program, which is not calling any
other program. Both give the same results when a program is not calling any
other program.

102. How can you submit a job from COBOL programs?


Write JCL cards to a DataSet with
//xxxxxxx SYSOUT=(A,INTRDR) where ‘A’ is output class, and DataSet should be
opened for output in the program. Define a 80 byte record layout for the file.

103. What is difference between COBOL and VS COBOL II?.

27
OS/VS Cobol pgms can only run in 24 bit addressing mode, VS Cobol II pgms
can run either in 24 bit or 31 bit addressing modes.
Report writer is supported only in OS/VS Cobol.
USAGE IS POINTER is supported only in VS COBOL II.
Reference modification e.g.: WS-VAR(1:2) is supported only in VS COBOL II.
EVALUATE is supported only in VS COBOL II.
Scope terminators are supported only in VS COBOL II.
OS/VS Cobol follows ANSI 74 stds while VS COBOL II follows ANSI 85 stds.
Under CICS Calls between VS COBOL II programs are supported.

Note: In using COBOL on PC we have only flat files and the programs can access
only limited storage, whereas in VS COBOL II on M/F the programs can access
up-to 16MB or 2GB depending on the addressing and can use VSAM files to
make I/O operations faster.

104. Can you call an OS VS COBOL pgm from a VS COBOL II pgm ?


In non-CICS environment, it is possible. In CICS, this is not possible.

105. What's a LDS(Linear Data Set) and what's it used for ?(VSAM)
LDS is a VSAM DataSet in name only. It has unstructured 4k (4096 bytes) fixed
size CIs which do not contain control fields and therefore from VSAM's
standpoint they do not contain any logical records. There is no FreeSpace, and
no access from Cobol. Can be accessed by DB2 and IMS fast path DataSet. LDS
is essentially a table of data maintained on disk. The 'table entries' must be
created via a user program and can only be logically accessed via a user
program. When passed, the entire LDS must be mapped into storage, then data
is accessed via base and displacement type processing.

106. What are the steps you go through while creating a COBOL program
executable?
DB2 precompiler (if embedded SQL used),
CICS translator (if CICS pgm),
Cobol compiler,
Link editor.

If DB2 program, create plan by binding the DBRMs.

*********************************************************

Compiled By : A.Mohammed Rafi


Employee No. : 930491
Project : Cummins
Location : Shollinganallur, Chennai
Email : a.rafi@tcs.com

*********************************************************

28
29

You might also like