Cobol Interview Questions

Advertisements


IDENTIFICATION DIVISION

ENVIRONMENT DIVISION

DATA DIVISION

PROCEDURE DIVISION.

Documentation.

SIX SECTIONS

  1. FILE SECTION
  2. WORKING-STORAGE SECTION
  3. LOCAL-STORAGE SECTION
  4. SCREEN SECTION
  5. REPORT SECTION
  6. LINKAGE SECTION

IDENTIFICATION DIVISION and PROGRAM-ID paragraph are mandatory for a compilation error free COBOL program.

The linkage section is part of a called program that 'links' or maps to data items in the calling program's working storage.

It is the part of the called program where these share items are defined.

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

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.

There are at least five differences:

COBOL II supports structured programming by using in line Performs and explicit scope terminators, It introduces new features (EVALUATE, SET. TO TRUE, CALL. BY CONTEXT, etc) It permits programs to be loaded and addressed above the 16-megabyte line It does not support many old features (READY TRACE, REPORT-WRITER, ISAM, Etc.), and It offers enhanced CICS support.

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.

REMARKS, NOMINAL KEY, PAGE-COUNTER, CURRENT-DAY, TIME-OF-DAY, STATE, FLOW, COUNT, EXAMINE, EXHIBIT, READY TRACE and RESET TRACE.

Note: these are partial lists only.

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.

Alpha-numeric (X)

Alphabetic (A)

Numeric (9)

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

For condition names.

For RENAMES clause.

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

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.

16777215

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.

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.

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

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

It is stored in the last nibble.

In the most significant bit. Bit is ON if -ve, OFF if +ve.

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

COMP-1 - Single precision floating point. Uses 4 bytes.

COMP-2 - Double precision floating point. Uses 8 bytes.

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.

Will occupy 8 bytes (one extra byte for sign).

4 bytes

99999999

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.

3Bytes (formula : n/2 + 1))

the editing characters are to be used with data items with usage clause as display which is the default. When 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 this particular data item to be edited this should to move it into a data item whose usage is display and then have that particular data item edited in the format desired.

10 Bytes (S9(18) COMP-3).

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.

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.

Yes.

Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE; IF, END-IF.

Yes, Evaluation of the WHEN clauses proceeds from top to bottom and their sequence can determine results.

In COBOL II the 88 levels can be set rather than moving their associated values to the related data item.

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.

	PERFORM ... [UNTIL] ... 
		[sentences]
	END-PERFORM

The PERFORM and END-PERFORM statements bracket all COBOL II statements between them.

The COBOL equivalent is to PERFORM or PERFORM THRU a paragraph.

In line PERFORMs work as long as there are no internal GO TOs, not even to an exit.

The in line PERFORM for readability should not exceed a page length - often it will reference other PERFORM paragraphs.

Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements.

For readability, it's recommended coding practice to always make scope terminators explicit.

The PERFORM statement 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, control is transferred to the next executable statement following the PERFORM statement.

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

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

It can be either ASCENDING or DESCENDING. ASCENDING is default.

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

Indexing uses binary displacement.

Subscripts use the value of the occurrence

NEXT SENTENCE gives control to the verb following the next period.

CONTINUE gives control to the next verb after the explicit scope terminator.

It's safest to use CONTINUE rather than NEXT SENTENCE in COBOL II.

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.

Alphabetic, Alphanumeric fields & alphanumeric edited items are set to SPACES.

Numeric, Numeric edited items set to ZERO. FILLER , OCCURS DEPENDING ON items left untouched.

LENGTH acts like a special register to tell the length of a group or elementary item.

REPLACING allows for the same copy to be used more than once in the same code by changing the replace value.

Redefines clause is used to allow the same storage allocation to be referenced by different data names .

By using intrinsic function, FUNCTION CURRENT-DATE

Yes. Redefines just causes both fields to start at the same location.

Yes.

Fixed Block File - Use

ORGANISATION IS SEQUENTIAL.
RECORDING MODE IS F
BLOCK CONTAINS 0 .

Fixed Unblocked - Use

ORGANISATION IS SEQUENTIAL.
RECORDING MODE IS F
do not use BLOCK CONTAINS

Variable Block File - Use

ORGANISATION IS SEQUENTIAL.
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.
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.
RECORDING MODE IS F
BLOCK CONTAINS 0.

Open for INPUT, OUTPUT, I-O, EXTEND.

OUTPUT, EXTEND

We can rewrite (record length must be same), but not delete.

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 COBOL pgm & the JCL (or the dataset label). will get file status 39 on an OPEN.

These are compile/link edit options. Basically AMODE stands for Addressing mode and RMODE for 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.

RMODE(ANY) - Can reside above or below 16 Meg line.

DYNAM.

These are compiler options with respect to 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.

Make sure that link option is AMODE=31 and RMODE=ANY.

Compile option should never have SIZE(MAX). BUFSIZE can be 2K, efficient enough.

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.

static/dynamic linking by choosing either the DYNAM or NODYNAM link edit option.

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.

The parameters passed in a call by context are protected from modification by the called program.

In a normal call they are able to be modified.

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.

Move a value to RETURN-CODE register. RETURN-CODE should not be declared in program.

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.

DB2 precompiler (if embedded SQL used), CICS translator (if CICS pgm), Cobol compiler, Link editor. If DB2 program, create plan by binding the DBRMs.

Use a file //dd1 DD sysout=(*, intrdr)write your JCL to this file.

Using EXEC CICS SPOOL WRITE(var-name) END-EXEC command. var-name is a COBOL host structure containing JCL statements

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.

Basically we 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 a dump for run time abend’s ( 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 installation might have batch program debugging tools.

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.

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.

A Report-Item Is A Field To Be Printed That Contains Edit Symbols

Advertisements