Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COBOL Copybook Explaination 1

Status
Not open for further replies.

chimota

Technical User
Dec 22, 2000
4
0
0
US
I have been asked to create a cobol copybook from a data dictionary. I have never used cobol or made a data dictionary. This is copybook will then be used wiith the program Data Junction. I have a sample of the data dictionary but I do not understand it. If someone could please help explain to me how to read and define what goes where. Like S9 and value(9) and so forth.

jtr
 
If all you are looking for is an example copybook.......here ya go!
Code:
01   PKLR1-DETAIL-LOAN-RECORD.                                   
    10  PKLR1-BASIC-SECTION.                                     
        20  PKLR1-SORT-CONTROL-FIELD.                            
            30  PKLR1-USER-IDENT         PIC X(1).               
            30  PKLR1-EXTRACT-CODE       PIC X(1).               
                88  PKLR1-DATE-RECORD            VALUE '*'.      
                88  PKLR1-DATA-RECORD            VALUE '0'.      
                88  PKLR1-END-OF-FILE            VALUE '9'.      
            30  PKLR1-SECTION            PIC X(1).               
            30  PKLR1-TYPE               PIC X(1).               
            30  PKLR1-NUMERIC-STATE-CODE PIC X(2).               
            30  PKLR1-CONTRACT-NUMBER    PIC X(10).              
        20  PKLR1-PAR-PEN-REG-CODE       PIC X(1).               
        20  PKLR1-VALUATION-CODE.                                
            30  PKLR1-MORTALITY-TABLE    PIC X(2).               
            30  PKLR1-LIVES-CODE         PIC X(1).               
            30  PKLR1-FUNCTION           PIC X(1).               
            30  PKLR1-VAL-INTEREST       PIC S9(2)V9(3) COMP-3.  
            30  PKLR1-MODIFICATION       PIC X(1).               
            30  PKLR1-INSURANCE-CLASS    PIC X(1).               
            30  PKLR1-SERIES             PIC X(5).               
        20  PKLR1-POLICY-STATUS          PIC X(2).               
        20  PKLR1-PAR-CODES.                                     
            30  PKLR1-PAR-TYPE           PIC X(1).               
            30  PKLR1-DIVIDEND-OPTION    PIC X(1).               
            30  PKLR1-OTHER-OPTION       PIC X(1).               
        20  PKLR1-ALPHA-STATE-CODE       PIC X(2).
Thanks,

s-)
 
Thank you Greenguy71 for the example. What I still don't understand is 1) Does the spacing matter? 2) How do I know if it is a pic or a value or to put something like COMP-3 after the size? Again the example helps. Thanks

jtr
 
Chimota,

I have a few question for you.

1. Does your sample data dictionary represent a cobol data file? ie.. Do you have a cobol file and also the layout of it as Greenguy71 posted.

2. Do you know the cobol file type. Sequential, Index etc.

Data Junction can read many different types of files as you know, but first you have to define to data junction what the file type is and its structure.

Can you post any information about your sample data dictionary? What COBOL vendor produced this file?

The comp-3 etc that you mention determines how the internal value is read etc... So it matters greatly..


 
Chimota,

sounds like you are in dire need of a quick introduction into the COBOL language.
As i estimate, no short answer will do in response to your question; i'm going to give it a try, anyway.

Some points of interest may be these:

Every COBOL program source defines a section that is known as Working Storage. This is a map of a section of memory the program in question uses to store input from files, intermediate results, output to be written to files, etc.
The Working-Storage Section of any COBOL program defines a map for that program. Parts of that map can be hard coded in every program; however, is several programs manipulate e.g. the same file, it makes sense to define the layout for that file into a copybook. Each program can incorporate the exact same layout (= the copybook) in it's working storage by use of the COPY statement.

A Working-Storage definition follows strict rules; so will any copybook. Some of them are (using the example GreenGuy71 gave you):

The words are identifiers to give the program a reference to access a certain portion of memory, i.e. PKLR1-CONTRACT-NUMBER (12th line) defines a 10 byte section of alphameric data. The numbers at the beginning of each line are level numbers; the top level is identified by '01', every number beneath that defines a part of the '01'-level.
For instance, PKLR1-DETAIL-LOAN-RECORD' references the whole definition, since it is at 01-level; PKLR1-BASIC-SECTION is the only defintion at 10-level, and therefore superfluous; every 20-level listed in the example divides the 10-level (and therfore the 01-level) up into several bits that may be manipulated indivdually.

The 'PIC'-clause (PICture) defines the way the referenced bytes should be looked at. I.e. PIC X(10) means 10 bytes of alphameric content, PIC 9(02) means 2 bytes of numeric content, with each byte containing 1 digit, PIC S9(02) means the same, burt with a sign (= positive or negative). The adjective 'COMP-3' means that the numeric content should be stored in a specific format, where each nibble (=4 bits) holds 1 digit. This saves space in the memory occupied.

About spacing: every line in a COBOL program is devided up into 2 sections; area 'A', in the case of your copybook, runs froms position 7 up to 11; position 7 is reserved for comment characters, and the '01' level indicator should be in the positions from 8 to 11 (usually starting at 8). Every other bit should be in the 'B'-section, from position 12 up to the end of the line (usually 72). In section 'B'. spacing is mostly relevant for legibility, as long as each part of a line (that is, level nember, identifier name, 'PIC'-clause, picture, etc.) is at least seperated be a single space.

About value: the 'VALUE'-clause presets the defined memory area to a certain value. Normally, this is determined by the program while executing; however, it can be used to set the value for certain identifiers at the start of execution, either as an initial value, or as a value for a constant.

I hope this lengthy response gets you on the way and NOT confuses you even more !

Good luck !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top