The Buckalew Group

 

 

 

 


PB Technical Group

 

 

 

 


P M Buckalew

 

 

 

    There are FOUR divisions in a COBOL program
    IDENTIFICATION DIVISION
    ENVIRONMENT DIVISION
    DATA DIVISION
    PROCEDURE DIVISION
    There are FOUR data types available in COBOL.

    Alpha-numeric ( Picture X),

    Alphabetic (Picture A),

    Numeric (Picture 9).

    Floating Point (COMP-1 or COMP-2 with No Picture Clause).

    COMP-1 is SINGLE PRECISION (uses 4 bytes)

    COMP-2 is DOUBLE PRECISION (uses 8 bytes)

    The INITIALIZE verb ...

    Sets Alphabetic fields, Alphanumeric fields & Alpha-numeric edited items to SPACES.

    Sets Numeric fields and Numeric edited items to ZERO.

    NOTE: FILLER and OCCURS DEPENDING ON items are left untouched.

    The 77 level is an elementary level item. It cannot be subdivided into other items (cannot be qualified), nor can they be subdivided themselves.

    An 88 level is used for condition names.

    A 66 level is used for RENAMES clause.

    The IS NUMERIC clause is used in conjunction with alphanumeric item, 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 - .

    An ARRAY is defined in COBOL as follows:

    01 ARRAY01
    05 ARRAY01A PIC X(9) OCCURS 10 TIMES
    05 ARRAY01B PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX

    An OCCURS clause CANNOT be at the 01 level.

    Indexes and Subscripts

    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. An index for a table is required in order to use SEARCH or SEARCH ALL clause.

    The difference between SEARCH and SEARCH ALL is that a SEARCH is a serial search where a SEARCH ALL is a binary search. The table must be sorted (ASCENDING/DESCENDING using the KEY clause along with the data) before using SEARCH ALL.

    When using SEARCH ALL, it can be either ASCENDING or DESCENDING. ASCENDING is the default. If you want the search to be done on an array sorted in descending order, you should use the DESCENDING KEY clause when defining the array. (You must load the table in the specified order).

    A BINARY Search is a search on a sorted array. Compare the item to be searched with the item at the center. If it matches, fine else the process is repeated using the top half or bottom half depending on where the item lies.

    Debugging Subscript Errors

    To prevent a subscript value that is outside of the array range, you must use compiler option SSRANGE if you want array bounds checking. Typically, the default is NOSSRANGE.

    To sort within a COBOL program, you much provide the sort file definition (SD), the sort statement syntax and meaning.

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

    A sort file in JCL that runs the COBOL program is defined as follows:
    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.

    SECTIONs and PARAGRAPHs

    Performing a PARAGRAPH will cause only that paragraph to be performed whereas performing a SECTION will cause all the paragraphs that are part of the section to be performed.
    The EVALUATE statement is like a CASE statement in other languages and is used to replace nested Ifs. The difference between EVALUATE and CASE is that there no 'break' is required for EVALUATE (i.e. control comes out of the EVALUATE as soon as a match is made).

    Examples of EVALUATE statement is as follows:

    EVALUATE SQLCODE ALSO FILE-STATUS
    WHEN A=B AND C=D WHEN 100 ALSO '00'
    imperative stmt
    WHEN (D+X)/Y = 4 WHEN -305 ALSO '32'
    imperative stmt
    WHEN OTHER
    imperative stmt
    END-EVALUATE

    EVALUATE SQLCODE ALSO A=B EVALUATE SQLCODE ALSO TRUE
    WHEN 100 ALSO TRUE WHEN 100 ALSO A=B
    imperative stmt
    WHEN -305 ALSO FALSE WHEN -305 ALSO (A/C=4)
    imperative stmt
    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. In an EVALUATE statement, you can give complex conditions on a when clause.

    Scope terminators are used to mark the end of a verb e.g. EVALUATE, END-EVALUATE; IF, END-IF. A scope terminator can also be a PERIOD.

    In-line PERFORMs are used as follows:

    PERFORM ... ...

    END PERFORM

    In-line PERFORMs are recommended if 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 paragraph rather than in-line perform.

    The difference between CONTINUE and NEXT SENTENCE is that the CONTINUE clause is like a null statement (do nothing) , while NEXT SENTENCE transfers control to the next sentence (terminated by a period).

    If there is an EXIT clause in a paragraph, it should be the only statement there!!

    REDEFINES

    You can REDEFINE to a data area that is larger. 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.

    If you REDEFINE to a data area that is smaller. There is a risk of encountering an S0C7 abend. To resolve an SOC-7 error, Basically you need to correct the offending data. Many times the reason for SOC7 is an un-initialized numeric item (i.e. spaces). 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 judgment and DISPLAY to localize the source of error. Some installation might have batch program debugging tools. Use them.

    PACKED and ZONED DECIMAL fields...

    A PACKED DECIMAL field is where the sign is stored as a hex value in the last nibble (4 bits) of the storage. COMP-3 fields are PACKED DECIMAL

    ZONED DECIMAL fields, as a default, have its sign as an over punch 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...

    In a COMP field, the value is in the most significant bit. Bit is on if -, off if +. The difference between COMP & COMP-3 is that COMP is a binary storage format while COMP-3 is packed decimal format.

    Remember that when you define a variable of COMP-1 or COMP-2, no picture clause is given.

    01 WS-VAR USAGE COMP-1.

    In a COMP-3 fiend, remember that the field is compressed. Two digits occupy the same byte. If there is an odd number of digits, there will be an extra byte used. For example, in a S9(7) COMP-3 field, it 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.

    When using SIGN TRAILING SEPARATE clause and there is an odd number of digits, (i.e. S9(7))

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

    If you have an S9(8) COMP field defined, it will occupy 4 bytes.

    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.

    ORGANIZATION IS...:

    Fixed Block File - ORGANIZATION IS SEQUENTIAL
    RECORDING MODE IS F
    BLOCK CONTAINS 0

    Fixed Unblocked - ORGANIZATION IS SEQUENTIAL
    RECORDING MODE IS F

    Variable Block File - ORGANIZATION IS SEQUENTIAL
    RECORDING MODE IS V
    BLOCK CONTAINS 0.
    NOTE: Do not code the 4 bytes for record length in FD i.e.: JCL rec length will be max rec length in programs + 4
    Variable Unblocked - ORGANIZATION IS SEQUENTIAL
    RECORDING MODE IS V
    NOTE: Do not code the 4 bytes for record length in FD i.e.: JCL rec length will be max rec length in programs + 4.

    ESDS VSAM file - ORGANIZATION IS SEQUENTIAL.
    KSDS VSAM file - ORGANIZATION IS INDEXED
    RECORD KEY IS ...
    ALTERNATE RECORD KEY IS ...

    RRDS File - ORGANIZATION IS RELATIVE
    RELATIVE KEY IS ...

    Printer File - ORGANIZATION IS SEQUENTIAL
    RECORDING MODE IS F
    BLOCK CONTAINS 0
    NOTE: Use RECFM=FBA in JCLs DCB

    There are FOUR different file OPEN modes available in COBOL

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

    If you plan to OPEN a file for writing only, use either OUTPUT or EXTEND

    STATIC vs. DYNAMIC Linking

    In static linking, the called subroutine is link-edited into the calling program , while in dynamic linking, the subroutine and 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.

    Within the MVS/ESA Enterprise Server architecture, there are different addressing and residency modes that are set as 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 programs use 24 bit addresses only).
    RMODE(ANY) - Can reside above or below 16 Meg line.

    To submit a job from a COBOL program, write JCL statements to an output dataset as follows ...

    //READER01 SYSOUT=(A,INTRDR)
    Where 'READER01 is identified in the FD section of the COBOL program
    'A' is output class, and dataset should be opened for output in the
    program. You will need to define a 80 byte record layout for the
    output file.

    Differences between OS VS COBOL and VS COBOL II

  • From a performance standpoint, OS/VS Cobol programs can only run in 24 bit addressing mode, while VS Cobol II (and later) programs can run either in 24 bit or 31 bit addressing modes.
  • Report writer is supported only in OS/VS Cobol as it was discontinued in COBOL II (and later).
  • USAGE IS POINTER is supported only in VS COBOL II (and later).
  • Reference modification eg: WS-VAR(1:2) is supported only in VS COBOL II.
  • Remember that the EVALUATE clause is only supported in VS COBOL II (and later).
  • Scope terminators are supported only in VS COBOL II or later.
  • OS/VS Cobol follows ANSI 74 standards while VS COBOL II follows ANSI 85 standards.
  • Under CICS Calls between VS COBOL II programs are supported.
  • The steps to go through to make a COBOL program executable is as follows:

  • If the COBOL program has SQL (DB2) code, then the DB2 pre-compiler will need to execute.
  • If the COBOL program has CICS code, then the CICS translator will need to execute.
  • These pre-compilers are then followed by the Cobol compiler and the Linkage Editor.
  • If the DB2 pre-compiler was performed, binding of the plan(s) generates the DBRM file.
  • You can call an OS VS COBOL programs from a VS COBOL II program, but only within a batch process. In a CICS environment, this is not possible.

 

 

Send mail to philip.buckalew@gmail.com with questions or comments about this web site.
Copyright © 2010 P M Buckalew
Last modified: 05/14/2010

 

 

Send mail to webmaster@pbtechgroup.com with questions or comments about this web site.
Copyright © 2008 PB Technical Group
Last modified: 06/29/08

 

 

Send mail to webmaster@pbtechgroup.com with questions or comments about this web site.
Copyright © 2016 PB Technical Group
Last modified: 06/22/2016