COBOL FAQs -- Part III
Home -- FAQs Home
A D V E R T I S E M E N T
1.How many Sections are there in Data Division?.
Ans:
SIX SECTIONS 1.'FILE SECTION' 2.'WORKING-STORAGE SECTION' 3.'LOCAL-STORAGE SECTION' 4.'SCREEN SECTION' 5.'REPORT SECTION' 6.'LINKAGE SECTION'
In COBOL II, there are only 4 sections. 1.'FILE SECTION' 2.'WORKING-STORAGE SECTION' 3.'LOCAL-STORAGE SECTION' 4.'LINKAGE SECTION'.
2.How can I tell if a module is being called DYNAMICALLY or STATICALLY?
Ans:
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).
3.What is the difference between a DYNAMIC and STATIC call in COBOL.
Ans:
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 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.
4.What is the difference between PIC 9.99 and 9v99?
Ans:
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.
5.How is PIC 9.99 is different from PIC 9v99?
Ans:
PIC 9.99 is a four position field that actually contains a decimal point where as 9v99 is a three position numeric field with an implied or assumed decimal point.
6.what is Pic 9v99 Indicates?
Ans:
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.
7.what guidelines should be followed to write a structured COBOL program?
Ans:
1) Use 'EVALUATE' stmt for constructing cases. 2) Use scope terminators for nesting. 3)Use in-line Perform stmt for writing 'do ' constructions. 4) Use Test Before and test after in the Perform stmt for writing Do-While constructions.
8.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 ?
Ans:
5 Times only. it will not take the value 10 that is initialized in the loop.
9.What are some examples of command terminators?
Ans:
END-IF, END-EVALUATE
10.What care has to be taken to force program to execute above 16 Meg line?
Ans:
Make sure that link option is AMODE=31 and RMODE=ANY. Compile option should never have SIZE(MAX).BUFSIZE can be 2K, efficient enough.
11.Give some advantages of REDEFINES clause.
Ans:
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.3. We can REDEFINE a Single Variable into so many sub-variables.(This facility is very useful in solving Y2000 Problem.)
12.Why do we code s9(4)comp. Inspite of knowing comp-3 will occupy less space.
Ans:
Here s9(4)comp is small integer ,so two words equal to 8 bytes. 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 bytes totally it will occupy 3 bytes.
13.The maximum number of dimensions that an array can have in COBOL-85 is ________.
Ans:
SEVEN in COBOL - 85 and THREE in COBOL - 84
14.Name the divisions in a COBOL program.
Ans:
IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION, PROCEDURE DIVISION.
15.What are the different data types available in COBOL?
Ans:
Alpha-numeric (X), alphabetic (A) and numeric (9).
16.What is 77 level used for ?
Ans:
Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.
17.What is 88 level used for ?
Ans:
For defining condition names.
18.What is level 66 used for ?
Ans:
For RENAMES clause.
19.What does the IS NUMERIC clause establish?
Ans:
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 - .
20.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?
Ans:
Must use compiler option SSRANGE if you want array bounds checking. Default is NOSSRANGE.
21. What is the difference between performing a SECTION and a PARAGRAPH?
Ans:
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.
22.Can I redefine an X(200) field with a field of X(100) ?
Ans:
Yes.
23.What does EXIT do?
Ans:
Does nothing ! If used, must be the only sentence within a paragraph.
24.Can I redefine an X(100) field with a field of X(200)?
Ans:
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.
25.Can I redefine an X(200) field with a field of X(100) ?
Ans:
Yes.
26.What do you do to resolve SOC-7 error?
Ans:
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. You may even use batch program debugging tools.
27.How is sign stored in Packed Decimal fields and Zoned Decimal fields?
Ans:
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.
28.How is sign stored in a comp-3 field?
Ans:
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 1D if the number is -101, hex 2D if the number is -102 etc...
29.How is sign stored in a COMP field ?
Ans:
In the most significant bit. Bit is on if -ve, off if +ve.
30.What is the difference between COMP & COMP-3 ?
Ans:
COMP is a binary storage format while COMP-3 is packed decimal format.
31.What is COMP-1? COMP-2?
COMP-1 - Single precision floating point. Uses 4 bytes.
COMP-2 - Double precision floating point. Uses 8 bytes.
32.How do you define a variable of COMP-1? COMP-2?
Ans:
No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.
33.How many bytes does a S9(7) COMP-3 field occupy ?
Ans:
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.
34.How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?
Ans:
Will occupy 8 bytes (one extra byte for sign).
35.What is the maximum size of a 01 level item in COBOL I? in COBOL II?
In COBOL II: 16777215
36.What is COMP SYNC?
Ans:
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 comp field is faster.
37.How do you reference the following file formats from COBOL programs?
Ans:
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 record length will be max record length in program + 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).
38.What are different file OPEN modes available in COBOL? In which modes are the files Opened to write.
Ans:
Different Open modes for files are INPUT, OUTPUT, I-O and EXTEND. Of which Output and Extend modes are used to write new records into a file.
39.In the JCL, how do you define the files referred to in a subroutine?
Ans:
Supply the DD cards just as you would for files referred to in the main program.
40.Can you REWRITE a record in an ESDS file? Can you DELETE a record from it?
Ans:
Can rewrite(record length must be same), but not delete.
41.What is file status 92?
Ans:
Logic error. e.g., a file is opened for input and an attempt is made to write to it.
42.What is file status 39?
Ans:
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.
43.What is Static, Dynamic linking ?
Ans:
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.
44.Explain NEXT and CONTINUE verbs for file handling.
Ans:
A The Continue verb is used for a situation where there in no EOF condition. i.e. The records are to be accessed again and again in a file. Whereas in the next verb the indexed file is accessed sequentially, whence when index clause is accessed sequentially read next record command is used.
45.What is AMODE(24), AMODE(31), RMODE(24) and RMODE(ANY)? (applicable to only MVS/ESA).
Ans:
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.
46.What compiler option would you use for dynamic linking?
DYNAM.
47.What is SSRANGE, NOSSRANGE ?
Ans:
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.
48.How do you set a return code to the JCL from a COBOL program?
Ans:
Move a value to RETURN-CODE register. RETURN-CODE should not be declared in your program.
49.How can you submit a job from COBOL programs?
Ans:
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.
50.What are the differences between OS VS COBOL and VS COBOL II?
Ans:
- 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 allowing program to address above 16 Meg main storage line.
- 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.
- COBOL II introduces new features (EVALUATE, SET ... TO TRUE, CALL ... BY CONTEXT, etc)
- Scope terminators are supported in 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.
- COBOL II supports structured programming by using in-line PERFORM 's.
- COBOL II does not support old features (READY TRACE, REPORT-WRITER, ISAM, etc.).
- In non-CICS environment, it is possible. In CICS, this is not possible.