Reading COBOL Layouts

This tutorial on how to read a COBOL layout was written specifically for our customers who have had a conversion performed at Disc Interchange and have received a COBOL layout with the data.  It is intended to give you enough information to read most simple layouts.  It does not cover all topics or everything you would find in a complex layout, and it is intended to explain COBOL layouts only so you can use your converted data, not so you can write COBOL programs. 

This article begins here: Reading COBOL Layouts where you will also find a topic index.

Part 2: Simple COBOL Layouts

This section describes a very simple COBOL layout, then introduces the concept of groups.

Contents of this section:
Need to convert COBOL files? Request a COBOL quote
That's our business!

   The  Simplest Example
   Groups

Let's start with a simple layout and add features as we go.

The Simplest Example

This is a very simple COBOL layout for a customer list.  The name of the record is "CUSTOMER-RECORD".  All the fields are at the same level (05), there are no groups.
   01  CUSTOMER-RECORD.
       05  LAST-NAME               PIC X(15).
       05  FIRST-NAME              PIC X(8).
       05  STREET-ADDRESS          PIC X(20).
       05  CITY                    PIC X(17).
       05  STATE                   PIC XX.
       05  ZIP-CODE                PIC 9(5).
       05  FILLER                  PIC X(10).
Notice a few things:
  1. A field name can have dashes between words, but not spaces.
  2. The 01 level specifies the name of the record, and does not have a PIC (it's composed of all the fields that follow).
  3. All the fields in this record are at the 05 level, so none are subordinate to any others; they are all just one-after-another in the file.
  4. The 05 level is arbitrary; it could have been anything from 02 to 49.
  5. There is a FILLER field at the end of the record to reserve space for future expansion.
  6. The record size is the sum of the fields, or 15 + 8 + 20 + 17 + 2 + 5 + 10 = 77 bytes.
  7. The starting position of each field is not explicitly given, but is determined by the sum of all the fields before it.

Groups

Now let's add a group called CUSTOMER-NAME, which will be composed of the fields LAST-NAME and FIRST-NAME:
   01  CUSTOMER-RECORD.
       05  CUSTOMER-NAME.
           10  LAST-NAME           PIC X(15).
           10  FIRST-NAME          PIC X(8).
       05  STREET-ADDRESS          PIC X(20).
       05  CITY                    PIC X(17).
       05  STATE                   PIC XX.
       05  ZIP-CODE                PIC 9(5).
       05  FILLER                  PIC X(10).
This record has exactly the same field positions as the previous layout.  The group CUSTOMER-NAME at the 05 level is composed of all the fields subordinate to it, down to the next 05 field.  i.e., it's composed of  LAST-NAME and FIRST-NAME.  CUSTOMER-NAME is a group, not a field, and therefore does not have (and cannot have) a PIC, and the line that reads "05 CUSTOMER-NAME" does not, by itself, reserve any space in the record.

Groups are handy for a number of reasons.  You can operate on all the fields in a group by referring to the name of the group.  If you reference CUSTOMER-NAME in the above layout, it will implicitly include all lower levels, LAST-NAME and FIRST-NAME in this case.

You can also have groups within a group. The following example, used in part 1 of this article is an example:

   01  MAILING-RECORD.
       05  COMPANY-NAME            PIC X(30).
       05  CONTACTS.
           10  PRESIDENT.
               15  LAST-NAME       PIC X(15).
               15  FIRST-NAME      PIC X(8).
           10  VP-MARKETING.
               15  LAST-NAME       PIC X(15).
               15  FIRST-NAME      PIC X(8).
           10  ALTERNATE-CONTACT.
               15  TITLE           PIC X(10).
               15  LAST-NAME       PIC X(15).
               15  FIRST-NAME      PIC X(8).
       05  ADDRESS                 PIC X(15).
       05  CITY                    PIC X(15).
       05  STATE                   PIC XX.
       05  ZIP                     PIC 9(5).

Notice the group CONTACTS is composed of three subordinate groups: PRESIDENT, VP-MARKETING, and ALTERNATE-CONTACT. Notice, too, that the group CONTACTS contains no elementary items (fields), only groups.  It could have contained elementary items, such as the following fragment:

       05  CONTACTS.
           10 SOURCE-OF-NAMES      PIC XX.
           10  PRESIDENT.
               15  LAST-NAME       PIC X(15).
               15  FIRST-NAME      PIC X(8).
           10  VP-MARKETING.
               15  LAST-NAME       PIC X(15).
               15  FIRST-NAME      PIC X(8).
           10  ALTERNATE-CONTACT.
               15  TITLE           PIC X(10).
               15  LAST-NAME       PIC X(15).
               15  FIRST-NAME      PIC X(8).

As noted in Part 1 of this article, it is legal to have multiple fields called LAST-NAME and FIRST-NAME, because they are in different groups.  Although it's legal, it's still wise to make each field name unique, and you are more likely to see them prefixed or suffixed, like PRES-LAST-NAME, VP-LAST-NAME and ALT-LAST-NAME.

Next: Part 3 Redefined Fields
 

Additional Information

For more articles on data conversion, see our TechTalk Index.

Our COBOL Conversion Services

If you need to convert a simple COBOL file, Disc Interchange has several methods at our disposal that are less expensive than writing a COBOL program.  We can often convert a simple COBOL file without any programming at all.  More complex files can frequently be converted with minimal programming using one of our many utility programs.
 
Mainframe & AS/400 Conversions
Mainframe & AS/400 Conversion to PC

With 32 years experience, we are the experts at transferring mainframe data to PCs.
Get more information on IBM Mainframe conversions
Request a COBOL quote

Disc Interchange Service Company, Inc.
Media Conversion Specialists
15 Stony Brook Road
Westford, MA 01886

Copyright © 1997 - 2015 by Disc Interchange
All rights reserved. See our copyright page.

Home