Cobol Interview Questions
Cobol Interview Questions
Cobol Interview Questions
What are the different data types available in COBOL?Alpha-numeric (X), alphabetic
(A) and numeric (9).
What does the INITIALIZE verb do? - GS
Alphabetic, Alphanumeric fields & alphanumeric edited items are set to SPACES. Numeric, Numeric
edited items set to ZERO. FILLER , OCCURS DEPENDING ON items left untouched.
What is 77 level used for ?
Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be
subdivided themselves.
What is 88 level used for ?
For condition names.
What is level 66 used for ?
For RENAMES clause.
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 - .
How do you define a table/array in COBOL?
ARRAYS.
05 ARRAY1
PIC X(9) OCCURS 10 TIMES.
05 ARRAY2
PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX.
Can the OCCURS clause be at the 01 level?
No.
What is the difference between index and subscript? - GS
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.
What is the difference between SEARCH and SEARCH ALL? - GS
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.
What should be the sorting order for SEARCH ALL? - GS
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).
What is binary search?
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.
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.
How do you sort in a COBOL program? Give sort file definition, sort statement syntax and
meaning. - GS
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 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.
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.
What is the difference between performing a SECTION and a PARAGRAPH? - GS
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.
What is the use of EVALUATE statement? - GS
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.
What are the different forms of EVALUATE statement?
EVALUATE
WHEN A=B AND C=D
imperative stmt
WHEN (D+X)/Y = 4
imperative stmt
WHEN OTHER
imperative stmt
END-EVALUATE
END-EVALUATE
END-EVALUATE
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 installation might have batch program
debugging
tools. Use them.
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.
How is sign stored in a comp-3 field? - GS
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...
How is sign stored in a COMP field ? - GS
In the most significant bit. Bit is ON if -ve, OFF if +ve.
What is the difference between COMP & COMP-3 ?
COMP is a binary storage format while COMP-3 is packed decimal format.
What is COMP-1? COMP-2?
COMP-1 - Single precision floating point. Uses 4 bytes.
COMP-2 - Double precision floating point. Uses 8 bytes.
How do you define a variable of COMP-1? COMP-2?
No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.
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.
How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?
Will occupy 8 bytes (one extra byte for sign).
How many bytes will a S9(8) COMP field occupy ?
4 bytes.
What is the maximum value that can be stored in S9(8) COMP?
99999999
What is COMP SYNC?
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.
What is the maximum size of a 01 level item in COBOL I? in COBOL II?
In COBOL II: 16777215
How do you reference the following file formats from COBOL programs:
Fixed Block File IS F,
BLOCK CONTAINS 0 .
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 ie
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
ie 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).
Fixed Unblocked -
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.
The program will go in an infinite loop.
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. Calling a
program name literal (CALL
What is the difference between a DYNAMIC and STATIC call in COBOL.
To correct an earlier answer: All called modules cannot run standalone if they require program
variables passed to them via the LINKAGE section. 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 (joblib or steplib) 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 u 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.
How may divisions are there in JCL-COBOL?
SIX
What is the purpose of Identification Division?
Documentation.
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.
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.
What guidelines should be followed to write a structured Cobol prg'm?
use 'evaluate' stmt for constructing cases.
use scope terminators for nesting.
use in line perform stmt for writing 'do ' constructions.
use test before and test after in the perform stmt for writing do-while constructions.
Read the following code. 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. how many times will b-para be executed ?
5 times only. it will not take the value 10 that is initialized in the loop.
What is the difference between SEARCH and SEARCH ALL? What is more efficient?
SEARCH is a sequential search from the beginning of the table. SEARCH ALL is a binary search,
continually dividing the table in two halves until a match is found. SEARCH ALL is more efficient for
tables larger than 70 items.
What are some examples of command terminators?
END-IF, END-EVALUATE
What care has to be taken to force program to execute above 16 Meg 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.
How do you submit JCL via a Cobol program?
Use a file //dd1 DD sysout=(*, intrdr)write your JCL to this file. Pl some on try this out.
How to execute a set of JCL statements from a COBOL program
Using EXEC CICS SPOOL WRITE(var-name) END-EXEC command. var-name is a COBOL host
structure containing JCL statements.
Give some advantages of REDEFINES clause.
You can REDEFINE a Variable from one PICTURE class to another PICTURE class by using the
same memory
location.
By REDEFINES we can INITIALISE the variable in WORKING-STORAGE Section itself.
We can REDEFINE a Single Variable into so many sub variables. (This facility is very useful in
solving Y2000
Problem.)
What is the difference between static call & Dynamic call
In the case of Static call, the called program is a stand-alone program, it is an executable program.
During run time we can call it in our called program. As about Dynamic call, the called program is not
an executable program it can executed through the called program
What do you feel makes a good program?
A program that follows a top down approach. It is also one that other programmers or users can follow
logically and is easy to read and understand.
How do you code Cobol to access a parameter that has been defined in JCL? And do you code
the PARM
parameter on the EXEC line in JCL?
using JCL with sysin. //sysin dd *here u code the parameters(value) to pass in to cobol program /* and
in program
you use accept variable name(one accept will read one row)/.another way.
in jcl using parm statement ex: in exec statement parm='john','david' in cobol pgm u have to code
linkage section in that for first value you code length variable and variable name say, abc pic x(4).it
will take john inside to read next value u have to code another variable in the same way above
mentioned.
Why do we code S9(4) comp. Inspite of knowing comp-3 will occupy less space.
Here s9(4)comp is small integer ,so two words equal to 1 byte so totally it will occupy 2 bytes(4
words).here in s9(4) comp-3 as one word is equal to 1/2 byte.4 words equal to 2 bytes and sign will
occupy 1/2 byte so totally it will occupy 3 bytes.
The maximum number of dimensions that an array can have in COBOL-85 is ----------- ?
SEVEN in COBOL - 85 and THREE in COBOL - 84
How do you declare a host variable (in COBOL) for an attribute named Emp-Name of type
VARCHAR(25) ?
01 EMP-GRP.
49 E-LEN PIC S9(4) COMP.
49 E-NAME PIC X(25).
What is Comm?
COMM - HALF WORD BINARY
Differentiate COBOL and COBOL-II. (Most of our programs are written in COBOLII, so, it is
good to know,
how, this is different from COBOL)
The following features are available with VS COBOL II:
MVS/XA and MVS/ESA support The compiler and the object programs it produces can be run in
either
24- or 31-bit addressing mode.
VM/XA and VM/ESA support The compiler and the object programs it produces can be run in either
24- or 31-bit addressing mode.
3. VSE/ESA support The compiler and the object programs it produces can be run under
VSE/ESA.
What is PERFORM ? What is VARYING ? (More details about these clauses)
The PERFORM statement is a PROCEDURE DIVISION statement which transfers control to one or
more specified procedures and controls as specified the number of times the procedures are executed.
After execution of the specified procedures is completed (i.e., for the appropriate number of times or
until some specified condition is met), control is transferred to the next executable statement
following the PERFORM statement. There are 5 types of PERFORM statements:
Basic PERFORM
PERFORM TIMES
PERFORM UNTIL
PERFORM VARYING
IN-LINE PERFORM
How many sections are there in data division?.
SIX SECTIONS 1.FILE SECTION 2.WORKING-STORAGE SECTION 3. LOCAL-STORAGE
SECTION 4.SCREEN SECTION 5.REPORT SECTION 6. LINKAGE SECTION
What is Redefines clause?
Redefines clause is used to allow the same storage allocation to be referenced by different data names .
How many bytes does a s9(4)comp-3 field occupy?
3Bytes (formula : n/2 + 1))
What is the different between index and subscript?
Subscript refers to the array of occurrence , where as Index represents an occurrence of a table
element. An index can only modified using perform, search & set. Need to have an index for a table in
order to use SEARCH and SEARCH All.
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. 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.
What divisions, sections and paragraphs are mandatory for a COBOL program?
A110)
IDENTIFICATION DIVISION and PROGRAM-ID paragraph are mandatory for a
compilation error free COBOL
program.
Can JUSTIFIED be used for all the data types?
No, it can be used only with alphabetic and alphanumeric data types.
What happens when we move a comp-3 field to an edited (say z (9). ZZ-)
the editing characters r to be used with data items with usage clause as display which is the default.
When u tries displaying 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 u want this particular data item to be
edited u have to move it into a data item whose usage is display and then have that particular data item
edited in the format desired.
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. GO BACK will give the
control to the system even though it is a single program.
what is the difference between external and global variables?
Global variables are accessible only to the batch program whereas external variables can be referenced
from any batch program residing in the same system library.
You are writing report program with 4 levels of totals: city, state, region and country. The codes
being used can be the same over the different levels, meaning a city code of 01 can be in any
number of states, and the same applies to state and region code so how do you do your checking
for breaks and how do you do add to each level?
Always compare on the highest-level first, because if you have a break at a highest level, each level
beneath it must also break. Add to the lowest level for each record but add to the higher level only on a
break.
What is difference between COBOL and VS COBOL II?.
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.
Why occurs can not be used in 01 level ?
Because, Occurs clause is there to repeat fields with same format, not the records.
What is report-item?
A Report-Item Is A Field To Be Printed That Contains Edit Symbols
Difference between next and continue clause
The difference between the next and continue verb is that in the continue verb it is used for a situation
where there in no EOF condition that is the records are to be accessed again and again in an file,
whereas in the next verb the indexed file is accessed sequentially, read next record command is used.
What is the Importance of GLOBAL clause According to new standards of COBOL
When any data name, file-name, Record-name, condition name or Index defined in an Including
Program can be referenced by a directly or indirectly in an included program, Provided the said name
has been declared to be a global name by GLOBAL Format of Global Clause is01 data-1 pic 9(5) IS
GLOBAL.
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
How do we get current date from system with century?
By using Intrinsic function, FUNCTION CURRENT-DATE
What is the maximum length of a field you can define using COMP-3?
10 Bytes (S9(18) COMP-3).
Why do we code s9 (4) comp? In spite of knowing comp-3 will occupy less space?
Here s9(4)comp is small integer, so two words equal to 1 byte so totally it will occupy 2 bytes(4
words).here in s9(4) comp-3 as one word is equal to 1/2 byte.4 words equal to 2 bytes and sign will
occupy 1/2
byte so totally it will occupy 3 bytes.
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.
Describe the difference between subscripting and indexing ?
Indexing uses binary displacement. Subscripts use the value of the occurrence.
What R 2 of the common forms of the EVALUATE STATEMENT ?
What does the initialize statement do ?
What is the reference modification.
Name some of the examples of COBOl 11?
What are VS COBOL 11 special features?
What are options have been removed in COBOL 11?
What is the file organization clause ?
What is a subscript ?
What is an index for tables?
What are the two search techniques ?
What is an in-line perform ?
What is CALL statement in COBOL?
When can the USING phrase be included in the call statement ?
In EBCDIC, how would the number 1234 be stored?
How would the number +1234 be stored if a PIC clause of PICTUREs9(4) comp-3 were used?
What is Alternate Index ? How is it different from regular index ?
COBOL
1.Name the divisions in a COBOL program. IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION,
PROCEDURE DIVISION.
2.What are the different data types available in COBOL?
Alpha-numeric (X), alphabetic (A) and numeric (9).
3.What does the INITIALIZE verb do? Alphabetic, Alphanumeric fields & alphanumeric edited items are set
to SPACES.
Numeric, Numeric edited items set to ZERO.
FILLER , OCCURS DEPENDING ON items left untouched.
4.What is 77 level used for ?
Elementary level item. Cannot be subdivisions of other items (cannot
be qualified), nor can they be subdivided themselves.
5.What is 88 level used for ?
For condition names.
6.What is level 66 used for ?
For RENAMES clause.
7.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 - .
8.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 WSINDEX.
END PERFORM
26.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 paraname rather than in-line perform.
27.What is the difference between CONTINUE & NEXT SENTENCE ?
CONTINUE is like a null statement (do nothing) , while NEXT SENTENCE
transfers control to the next sentence (!!) (A sentence is terminated
by a period)
28.What does EXIT do ?
Does nothing ! If used, must be the only sentence within a paragraph.
29.Can I redefine an X(100) field with a field of X(200)?
Yes. Redefines just causes 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.
30.Can I redefine an X(200) field with a field of X(100) ?
Yes.
30.What do you do to resolve SOC-7 error? Basically you need to correcting the offending data.
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.
31.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.
32.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...
33. How is sign stored in a COMP field ? In the most significant bit. Bit is on if -ve, off if +ve.
34.What is the difference between COMP & COMP-3 ?
COMP is a binary storage format while COMP-3 is packed decimal
format.
35.What is COMP-1? COMP-2?
COMP-1 - Single precision floating point. Uses 4 bytes.
COMP-2 - Double precision floating point. Uses 8 bytes.
36.How do you define a variable of COMP-1? COMP-2?
No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.
37.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.
38.How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?
Will occupy 8 bytes (one extra byte for sign).
CLAUSES
ENVIRONMENT DIVISION
(CONNECTS TO JCL/CONFIGURATION)
FILE-CONTROL
USES SELECT/ASSIGN CLAUSES TO CONNECT FILES TO JCL
BLOCK=0 TO ALLOW JCL SPECIFICATIONS
DATA DIVISION
(DESCRIBES DATA ELEMENTS/FILES)
FILE-SECTION
FILE DEFINITIONS (FD)
WORKING-STORAGE
DEFINING RECORDS HERE MAKES IT EASIER TO
FIND RECORDS IN DUMPS
DATA STRUCTURES LEVEL 01
RENAMES LEVEL 66
CONDITIONAL TEST LEVEL 88
CONSTANTS
3
LINKAGE-SECTION
DESCRIBING DATA IN A CALLED PROGRAM THAT
WAS PASSED FROM A CALLING PROGRAM/DBMS (CICS, IMS)/JCL
PARM
THE CALLED PROGRAM CONTAINS THE LINKAGE SECTION
EXIT VIA GOBACK OR EXIT PROGRAM
CALLING PROGRAM WILL USE CALL USING
Parm on JCL EXEC statement
Define parm field in the linkage section with first two bytes defined as PIC
S9(4) comp for the parm length; code USING option on the procedure division header
WORKING STORAGE
DATA DESCRIPTIONS
FD FILE DESCRIPTION
Label records are standard
Record contains
Block contains
If 0, the blocksize is picked up from the JCL
Dynamic -- records in a file can be accessed seq or randomly
Variable length recording mode v/multiple 01 or occurs depending on
Write depending on a field name defining the length/
Write from record description
SD SORT/MERGE FILE DESCRIPTION
RD REPORT DESCRIPTION
ELEMENTARY ITEMS CANNOT BE SUB-DIVIDED AND HAVE PICTURES
Open statements
Input, output i/o, extend,
Use a rewrite statement with i/o file will be read but also will be written back
onto the file at the same disk locations that they were read from
Extend - like mod
PROCEDURE DIVISION
(EXECUTABLE STATEMENTS)
ELEMENTARY/ACTION VERBS
OPEN
READ FILES
WRITE RECORDS
CLOSE
LOGIC:
AND/OR/NOT
IF/ELSE
CONTINUE NO EXECUTABLE SENTENCE IS PRESENT/OUT OF IF CLAUSE
NEXT SENTENCE GOES TO STATEMENT FOLLOWING THE NEXT PERIOD
SET TO TRUE
PERFORM LOOP CONTROL
PROCEDURE
THRU N TIMES
UNTIL
PERFORM VARYING FROM/UNTIL
UNTIL PRE-TEST IF TRUE OUT/IF FALSE PROCESS
Counter is updated from FROM value
Test is done at the beginning
INLINE PERFORM
PERFORM VERB CAN BE USED WITHOUT NAMING A PARAGRAPH
PERFORM UNTIL CNT < 1
END-PERFORM
Use inline perform when you do not want to branch out of a paragraph to
Perform an iterative process
EVALUATES case nested ifs
CONTROL:
GO TO
EXIT
STOP RUN ends cobol programs
GOBACK exit a valled program
CONTINUE
NEXT
4
DATA MANIPULATION:
MOVE TO
MOVE CORRESPONDING STRUCTURE MOVE
INITIALIZE
ACCEPT
DISPLAY
HEX NOTATION
REDEFINES
File Status Return Codes
00 last i/o operation successful 10 end of file 30-90 errors
ARITHMETIC:
ADD/SUBTRACT/MULTIPLY/DIVIDE add x1, x2 to x3
COMPUTE compute x3 = x1 + x2
ROUNDIED
SIZE ERROR CONDITION
TABLES:
INITIALIZE THROUGH REDEFINES IN DATA DIVISION/READING VALUES
FROM FILE/USING VALUE CLAUSE ON ENTRY THAT NAMES TABLE
SET UP A TABLE USING THE OCCURS CLAUSE IN THE DATA DIVISION
INDEX BY
EXAMPLE:
ROLL UP TABLE USING READ INTO IN A PERFORM UNTIL EOF
IF NOT EOF, MOVE READ FILE FIELD TO ARRAY FIELD
IN SEARCH PARAGRAPH, SET INDEX FIELD TO 1
SEARCH TABLE VARYING INDEX WHEN FIELD = ARRAY(SUB)
SET used to set value in index
SEARCH
SERIAL SEARCH
BINARY SEARCH
SUBSCRIPTS OCCURRENCE IN TABLE
INDEX DISPLACEMENT OF AN ITEM IN TABLE/MORE EFFICIENT
SET/SEARCH/SEARCH ALL/PERFORM VARYING CHANGE VALUE
OF INDEX
SEARCH SEQUENTIAL SEARCH
SEARCH ALL BINARY SEARCH
SUBROUTINES:
DYNAMIC CALL/CANCEL
CALL causes control to be passed from one object program to another
PARM
DEBUGGING:
READY/RESET TRACE
DISPLAY
EXHBIT
ON
RETURN-CODE MOVE CONDITION CODE <= 4095
DATA TYPES:
DISPLAY DATA
PICTURE
Z NUMERIC SUPPRESS
X ANY TYPE OF DATA
A CHARACTER/SPACE
9 NUMERIC
V IMPLIED DECIMAL
S SIGN
ALSO .,$/+-cr db
USAGE
PACKED DECIMAL COMP-3 105 00105C
C POSITIVE RIGHT 1/2 BYTE
D NEGATIVE
BINARY INTEGER COMP 0015
HIGH ORDER 0 POSITIVE
HIGH ORDER 1 NEGATIVE
INDEX INDEX
ZONED DECIMAL DISPLAY F0F1F0F5
ALIGNMENT
CHARACTER MANIPULATION:
5
INSPECT (REPLACE, TALLYING) DATA VALIDATION
STRING/UNSTRING CONCATENATION or separation
TRANSFORM CHARACTER REPLACEMENT/ alter characters from one set of
values to another
CONTINUE NULL BRANCH
NEXT SENTENCE PASSES CONTROL TO NEXT SENTENCE
Set to true used to set a conditional item to true, i.e. 88 eof statements
I/O:
BUFFERS I/O AREA GROUPED STORAGE
MOVE
LOCATE
END OF FILE
COBOL SORT
IN DATA DIVISION CODE A SD
IN PROCEDURE DIVISION USE ON ASCENDING/DESCENDING KEY USING
SET CONDITION CODE IN JCL MOVE SPECIFIED VALUE
TO RETURN-CODE
DIFFERENCE BETWEEN COBOL II AND COBOL VS
DIVISIONS/SECTIONS/CLAUSES ARE NOW OPTIONAL/OBSOLETE
LABEL RECORDS/FILLER OPTIONAL
RESERVED WORD TO ALLOWED IN ADD/GIVING STATEMENT
>=/<= ALLOWED
VALUE CLAUSES ALLOWED ON OCCURS CLAUSES
IMPROVED INTERFACES WITH CICS AND SORT/MERGE/
COBOL DOCUMENTATION
USE MEANINGFUL DATA/PARAGRAPH NAMES
USE CHANGE LOG AT TOP OF PROGRAM
USE NOTES IN COLUMNS 73-80
HOUSE STANDARDS
WORKING STORAGE SECTION CONSTANTS ONLY
USE SPACE/ZERO NOT 0
SIGN NUMERIC FIELDS
USE () IF PICTURE EXCEEDS 3
PROCEDURE DIVISION
TOP DOWN/STRUCTURED PROGRAMMING
ONE ENTRY AND EXIT FOR EACH SECTION OF CODE
TOPIC: COBOL
Q: What are S0C1, S0C4, S0C5, S0C7 ABENDs?
A: S0C1 (Operation Exception Error) - May be due to
Missing or misspelled DD name
Read/Write to unopened dataset
Reading a dataset opened output mode
Writing into a dataset opened input mode
Called subprogram not found
S0C4 may be due to
Missing Select statement (during compile)
Bad Subscript/index
Protection Exception
Missing parameters on called subprogram
Read/Write to unopened file
Move data from/to unopened file;
S0C5 May be due to
Bad Subscript/index
Close an unopened dataset
Bad exit from a perform
Access to I/O area (FD) before read;
S0C7 may be due to
Numeric operation on non-numeric data
Un-initialized working storage
Coding past the maximum allowed subscript
S0CB might be due to 1.Division by Zero
Q: What will happen if you code GOBACK instead of
STOPRUN in a stand-alone COBOL program [i.e. a program
which is not calling any other program]
A: Both give the same results when a program is not calling any
other program. GOBACK will give the control to the system even
though it is a single program.
Q: What is the difference between EXTERNAL and GLOBAL
variables?
A: GLOBAL variables are accessible only to the batch program
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.
Q. 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.
Q.What are the two ways of doing sorting in a COBOL program? Give the
formats. - GS
See question 16.
Q. Give the format of USING and GIVING in SORT statement. What are the
restrictions with it? - GS
See question 16. Restrictions - Cannot massage records, canot select records to be
sorted.
Q.What is the difference between performing a SECTION and a PARAGRAPH?
- GS
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.
Q.What is the use of EVALUATE statement? - GS
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.
Q. What are the different forms of EVALUATE statement?
EVALUATE
STATUS
MODE IS V, BLOCK CONTAINS 0. Do not code the 4 bytes for record length in FD
ie 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 ie 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).
Q. What are different file OPEN modes available in COBOL?
Open for INPUT, OUTPUT, I-O, EXTEND.
Q. What is the mode in which you will OPEN a file for writing? - GS
OUTPUT, EXTEND
Q. 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.
Q. 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.
Q. What is file status 92? - GS
Logic error. e.g., a file is opened for input and an attempt is made to write to it.
Q. 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.
Q. What is Static,Dynamic linking ?
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.
Q. What is AMODE(24), AMODE(31), RMODE(24) and RMODE(ANY)?
( applicable to only MVS/ESA Enterprise Server).
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 Meg line. Use this for 31 bit
programs that call 24 bit programs. (OS/VS Cobol pgms use 24 bit addresses only).
RMODE(ANY) - Can reside above or below 16 Meg line.
Q. What compiler option would you use for dynamic linking?
DYNAM.
Q. What is SSRANGE, NOSSRANGE ?
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.
Q. How do you set a return code to the JCL from a COBOL program?
Move a value to RETURN-CODE register. RETURN-CODE should not be declared
in your program.
Q. 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.
Q. 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.
Report writer is supported only in OS/VS Cobol.
USAGE IS POINTER is supported only in VS COBOL II.
Reference modification eg: 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.
Q. 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.
Q. 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.
Q1. What are the differences between COBOL and COBOL II?
A1. There are at least five differences: COBOL II supports structured programming
Q11. If you were passing a table via linkage, which is preferable - a subscript or an
index?
A11. Wake up - you haven't been paying attention! It's not possible to pass an index
via linkage. The index is not part of the calling programs working storage. Those of
us who've made this mistake, appreciate the lesson more than others.
Q12. Explain the difference between an internal and an external sort, the pros and
cons, internal sort syntax etc.
A12. An external sort is not COBOL; it is performed through JCL and PGM=SORT.
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.
Q13. What is the difference between comp and comp-3 usage? Explain other COBOL
usages.
A13. Comp is a binary usage, while comp-3 indicates packed decimal. The other
common usages are binary and display. Display is the default. 3/28/00 Dave
Herrmann: 'I was reading your FAQ on Cobol, as an fyi Comp is defined as the
fastest/preferred numeric data type for the machine it runs on. IBM Mainframes are
typically binary and AS400's are packed.'
Q14. When is a scope terminator mandatory?
A14. Scope terminators are mandatory for in-line PERFORMS and EVALUATE
statements. For readability, it's recommended coding practice to always make scope
terminators explicit.
Q15. In a COBOL II PERFORM statement, when is the conditional tested, before or
after the perform execution?
A15. In COBOL II the optional clause WITH TEST BEFORE or WITH TEST
AFTER can be added to all perform statements. By default the test is performed
exists outside the program's working storage. You SET an index to a value and SET it
UP BY value and DOWN BY value.
Q11. If you were passing a table via linkage, which is preferable - a subscript or an
index?
A11. Wake up - you haven't been paying attention! It's not possible to pass an index
via linkage. The index is not part of the calling programs working storage. Those of
us who've made this mistake, appreciate the lesson more than others.
Q12. Explain the difference between an internal and an external sort, the pros and
cons, internal sort syntax etc.
A12. An external sort is not COBOL; it is performed through JCL and PGM=SORT.
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.
Q13. What is the difference between comp and comp-3 usage? Explain other COBOL
usages.
A13. Comp is a binary usage, while comp-3 indicates packed decimal. The other
common usages are binary and display. Display is the default. 3/28/00 Dave
Herrmann: 'I was reading your FAQ on Cobol, as an fyi Comp is defined as the
fastest/preferred numeric data type for the machine it runs on. IBM Mainframes are
typically binary and AS400's are packed.'
Q14. When is a scope terminator mandatory?
A14. Scope terminators are mandatory for in-line PERFORMS and EVALUATE
statements. For readability, it's recommended coding practice to always make scope
terminators explicit.
Q15. In a COBOL II PERFORM statement, when is the conditional tested, before or
after the perform execution?
A15. In COBOL II the optional clause WITH TEST BEFORE or WITH TEST
AFTER can be added to all perform statements. By default the test is performed
before the perform.
Q16. In an EVALUTE statement is the order of the WHEN clauses significant?
A16. Absolutely. Evaluation of the WHEN clauses proceeds from top to bottom and
their sequence can determine results.
Q17. What is the default value(s) for an INITIALIZE and what keyword allows for
an override of the default.
A17. INITIALIZE moves spaces to alphabetic fields and zeros to alphanumeric