Home
Technology
Mainframe
JCL
Assembler language
VSAM
DB2
CICS
REXX / CLIST language
IMS
HTML Tutorial
JAVA
Aptitude questions - 1
Aptitude questions - 2
News
Stocks
Weather
Quiz
Food Recipes
Videos/Movie Trailers
Jobs
Sports
Playstation
Photo gallery
Earthquake Report
Tamil News
Miscellaneous
Murali Web World Presents
                                      Information Technology  Technical  Tips 
                          Mainframe Software
 

COBOL Language

 

Divisions in a COBOL program 

IDENTIFICATION DIVISION,

ENVIRONMENT DIVISION,

DATA DIVISION,

PROCEDURE DIVISION.


 

Data Division related tips

 

Different data types COBOL
Alpha-numeric (X),

Numeric (9).

 

PIC 9v99 v indicates assumed decimal point. Total bytes = 3.

 

COMP

Binary storage format

Sign is stored in most significant bit. If it is -ve, BIT is ON and if it is +ve - BIT is OFF.

example:

S9(8) COMP - 4 bytes

 

COMP sync Causes the item to be aligned on natural boundaries.

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

Example, 

if memory word size is 4 bytes then 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.

 

COMP-1

Single precision floating point = 4 bytes

 

COMP-2

Double precision floating point = 8 bytes

 

COMP-3 field

It is packed decimal format and sign is stored in the last nibble.

Example 

For number = +111, hex 1C in the last byte

For number = -102   hex 2D in the last byte 

S9(7) COMP-3 will occupy 4 bytes (INT((n/2) + 1).


SIGN TRAILING SEPARATE field
S9(5) SIGN will occupy 6 bytes - (5+1(for sign))

Maximum size of a 01 level item in COBOL is 16777215

 

77 level in Data Division is for Independent elementary level item and cannot be subdivided.

 

88 level in Data Division is for condition names (True or False)

 

66 level in Data Division is for RENAMES clause.

 

REDEFINES clause,

 

01 VARIABLE1 PIC X(1)

01 VARIABLE2 REDEFINES VARIABLE1 X(2).

 

if 2 digit number is moved to VARIABLE2 then VARIABLE1 contains left most digit of 2 digit number and VARIABLE 2 contains 2 digit number. If 15 is moved then VARIABLE1=1

and VARIABLE = 15.

 

IS Numeric Clause,

IS Numeric clause return TRUE when data item contains 0-9 and if it is signed item 0-9,+,-.

 

Array / Occurs clause in COBOL, (It cannot be at 01 level)

01 GROUP1

    05 GROUP-ARRAY1  PIC X(9) OCCURS 10 TIMES.

    05 GROUP-ARRAY2  PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX.

 

 

File Section,
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 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).

 


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

Difference between index and subscript.
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. 

Difference between SEARCH and 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. 

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. 

Compiler option SSRANGE needs to be used if we want to check array bounds Default is NOSSRANGE. 

SORT  in a COBOL program
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.

Q16) How do you define a sort file in JCL that runs the COBOL program ?

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

Q17) What is the difference between performing a SECTION and a PARAGRAPH ?

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

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. 
 
After the execution of one of the when clauses, the control is automatically passed on to the next sentence after the EVALUATE statement.

 

EVALUATE can be used in place of the nested IF THEN ELSE statements.

scope terminator is used to mark the end of a verb example EVALUATE END-EVALUATE and IF, END-IF.

in-line PERFORM
PERFORM ... ... END-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.

Difference between CONTINUE & NEXT SENTENCE.
 They appear to be similar, that is, the control goes to the next sentence in the paragraph. But, Next Sentence would take the control to the sentence after it finds a full stop (.). Check out by writing the following code example, one if sentence followed by 3 display statements (sorry they appear one line here because of formatting restrictions) If 1 > 0 then next sentence end if display 'line 1' display 'line 2'. display 'line 3'. *** Note- there is a dot (.) only at the end of the last 2 statements, see the effect by replacing Next Sentence with Continue *** 

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


SOC-7 error

The reason for SOC7 is an un-initialized numeric item. Many installations provide you 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 them. 

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

AMODE(24), AMODE(31), RMODE(24) and RMODE(ANY)
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. (OS/VS Cobol pgms use 24 bit addresses only). RMODE(ANY) - Can reside above or below 16 Meg line. 

RETURN-CODE register
Move a value to RETURN-CODE register to set return-code. RETURN-CODE should not be declared in your program. 

Submitting a job from COBOL programs/JCL
 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. 

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. I. Report writer is supported only in OS/VS Cobol. II. USAGE IS POINTER is supported only in VS COBOL II. III. Reference modification e.g.: WS-VAR(1:2) is supported only in VS COBOL II. IV. EVALUATE is supported only in VS COBOL II. V. Scope terminators are supported only in VS COBOL II. VI. OS/VS Cobol follows ANSI 74 stds while VS COBOL II follows ANSI 85 stds. VII. Under CICS Calls between VS COBOL II programs are supported. 

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

calling OS VS COBOL pgm from a VS COBOL II pgm  is not possible

Differences between COBOL and COBOL II.
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. 

Significance of 'above the line' and 'below the line'.
 Before IBM introduced MVS/XA architecture in the 1980's a program's virtual storage was limited to 16 megs. Programs compiled with a 24 bit mode can only address 16 Mb of space, as though they were kept under an imaginary storage line. With COBOL II a program compiled with a 31 bit mode can be 'above the 16 Mb line. (This 'below the line', 'above the line' imagery confuses most mainframe programmers, who tend to be a literal minded group.) 

Below list are removed from COBOL in the COBOL II implementation,
Partial list: REMARKS, NOMINAL KEY, PAGE-COUNTER, CURRENT-DAY, TIME-OF-DAY, STATE, FLOW, COUNT, EXAMINE, EXHIBIT, READY TRACE and RESET TRACE. 

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

If  index of table cannot be  passed via linkage.

Difference between an internal and an external sort, the pros and cons, internal sort syntax etc.
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 syntax’s: 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. 

Common Tips
 In a COBOL II PERFORM statement, 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. 

In an EVALUTE statement,WHEN clauses proceeds from top to bottom and their sequence can determine results. 

SET TO TRUE all about to set rather than moving their associated values to the related data item.

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

REPLACING option of a copy statement,allows for the same copy to be used more than once in the same code by changing the replace value. 

If we code GO BACK instead of STOP RUN in a stand alone COBOL program causes program to go in an infinite loop.

To execute a set of JCL statements from a COBOL program, use EXEC CICS SPOOL WRITE(var-name) END-EXEC command. var-name is a COBOL host structure containing JCL statements. 

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

To access a parameter that has been defined in JCL, use 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. 2) 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. 

The maximum number of dimensions that an array can have in COBOL-85 is SEVEN in COBOL - 85 and THREE in COBOL - 84

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

COMM - HALF WORD BINARY 

PERFORM VARYING - 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: a) Basic PERFORM b) PERFORM TIMES c) PERFORM UNTIL d) PERFORM VARYING e) IN-LINE PERFORM 

Sections are in data division
1.FILE SECTION 2.WORKING-STORAGE SECTION 3. LOCAL-STORAGE SECTION 4.SCREEN SECTION 5.REPORT SECTION 6. LINKAGE SECTION

Purpose of POINTER Phrase in STRING command - To specify the leftmost position within receiving field where the first transferred character will be stored 

current date from system with century  can be determined using Intrinsic function, FUNCTION CURRENT-DATE 

Indexing uses binary displacement. Subscripts use the value of the occurrence. 

 

 

 

 

JCL

 

DB2

 

CICS

 

Mainframe Assembler

 

REXX / CLIST

 

JAVA

 

Microsoft questions

 

Google Interview