Cobol FAQs
Cobol FAQs
Alphabetic, Alphanumeric fields & alphanumeric edited items are set to SPACES.
Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor
can they be subdivided themselves.
IS NUMERIC can be used on alphanumeric items, signed numeric & packed decimal
items and usigned 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 - .
01 ARRAYS.
No.
Subscript refers to the array occurrence while index is the displacement (in no of bytes)
from the beginning of the array. An index can only be modified using PERFORM,
SEARCH & SET.
Need to have index for a table in order to use SEARCH, SEARCH ALL.
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.
14. 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.
15. How do you sort in a COBOL program? Give sort file definition, sort statement
syntax and meaning.
Syntax:
USING file-2
GIVING file-3.
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.
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.
16. 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.
17. What are the two ways of doing sorting in a COBOL program? Give the formats.
18. Give the format of USING and GIVING in SORT statement. What are the
restrictions with it?
See question 16. Restrictions - Cannot massage records, canot select records to be sorted.
Performing a SECTION will cause all the paragraphs that are part of the section, to be
performed.
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.
21. What are the different forms of EVALUATE statement?
END-EVALUATE END-EVALUATE
END-EVALUATE END-EVALUATE
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.
Yes.
Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE;
IF, END-IF.
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 paraname rather
than in-line perform.
Yes. Redefines just causes both fields to start at the same location. For example:
Yes.
Many times the reason for SOC7 is an un-initialized 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 last instruction 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 datasets (SYSABOUT etc ) in the JCL.
If none of these are helpful, use judgement and DISPLAY to localize the source of error.
Some installtion might have batch program debugging tools. Use them.
32. 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.
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...
Will take 4 bytes. Sign is stored as hex value in the last nibble.
39. How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?
41. What is the maximum value that can be stored in S9(8) COMP?
99999999
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
43. What is the maximum size of a 01 level item in COBOL I? in COBOL II?
44. How do you reference the following file formats from COBOL programs:
46. What is the mode in which you will OPEN a file for writing?
OUTPUT, EXTEND
47. 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.
48. Can you REWRITE a record in an ESDS file? Can you DELETE a record from it?
Logic error. e.g., a file is opened for input and an attempt is made to write to it.
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.
In static linking, the called subroutine is link-edited into the calling program , while in
dynamic linking, the subroutine & the main program will exist as separate load modules.
You choose static/dynamic linking by choosing either the DYNAM or NODYNAM link
edit option. (Even if you choose NODYNAM, a CALL identifier (as opposed to a CALL
literal), will translate to a DYNAMIC call).
A statically called subroutine will not be in its initial state the next time it is called unless
you explicitly use INITIAL or you do a CANCEL. A dynamically called routine will
always be in its initial state.
RMODE(24) - Resides in virtual storage below 16 Meg line. Use this for 31 bit
programs that call 24 bit programs. (OS/VS Cobol pgms use 24 bit addresses
only).
53. What compiler option would you use for dynamic linking?
DYNAM.
These are compiler options w.r.t 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.
55. How do you set a return code to the JCL from a COBOL program?
57. What are the differences between OS VS COBOL and VS COBOL II?
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.
OS/VS Cobol follows ANSI 74 stds while VS COBOL II follows ANSI 85 stds.
DB2 precompiler (if embedded sql used), CICS translator (if CICS pgm), Cobol
compiler, Link editor.