contents.gifindex.gif

Preparing and Compiling your COBOL program

After the environment has been set up for Acu4GL, you are ready to use the system. The following example will illustrate how to set up a COBOL program to utilize your Acu4GL RDMS interface.

NOTE

If you are not familiar with the Acu4GL directives described in Using Directives , you may want to read that section before continuing with this section.

The purchase-orders file from a COBOL program at an imaginary company will be stored in the database. This file contains the records that handle all of the information from the company's purchase orders.

Within the purchase-orders file are two record types:

* the purchase-order header record (There is one of these for each purchase-order form.)

* the purchase-order detail record (There is one detail record for each line item in a purchase-order.)

The file is keyed off the purchase-order number. We will build and examine the database table three times, to illustrate three different approaches to using the COBOL file description:

* First, no directives will be added to the COBOL code. The code will be compiled as is. Only the largest record will thus be included in the database table.

* Second, the WHEN directive will be added, and the program recompiled. This will cause all record formats to be included in the database.

* Finally, several fields will be grouped together and renamed as a matter of convenience.

Here's the sample code:

IDENTIFICATION DIVISION.
program-id.  purchase.

ENVIRONMENT DIVISION.

input-output section.
file-control.

select p-o-file
 assign to disk "purch1"
organization is indexed 
 access mode is dynamic
 record key is p-o-number
 file status is p-o-status.

DATA DIVISION.
file section.
fd p-o-file.
01 p-o-record.
 03 p-o-division-number         pic 9(3).
 03 p-o-record-type             pic x.
  88 header-record           value "h".
  88 detail-record           value "d".
 03 p-o-number                  pic 9(10).
 03 p-o-number-detail redefines 
    p-o-number.
  05 picking-ticket-number      pic 9(6).
  05 shipping-region            pic 9(2).
  05 p-o-customer-type          pic 9(2).
  05 p-o-customer-breakdown redefines 
    p-o-customer-type.
   07 customer-category         pic x.
    88 p-o-customer-retail   value "r".
    88 p-o-customer-whlsale  value "w".
   07 customer-pay-format       pic x.
    88 is-net-30             value "3".
    88 is-net-10             value "1".
 03 p-o-date.
  05 p-o-yy                     pic 9(2).
  05 p-o-mm                     pic 9(2).
  05 p-o-dd                     pic 9(2).

01 p-o-detail-record.
 03 p-o-dept-number             pic 9(3).
 03 p-o-record-type             pic x.
 03 detail-p-o-number           pic 9(10).
 03 p-o-shipping-info.
  05 p-o-quantity-to-ship       pic s9(4) comp.
  05 p-o-total-quantity         pic s9(4) comp.
 03 p-o-notes.
  05 notes-line occurs 3 times  pic x(40).

working-storage section.

01 p-o-status                   pic x(2).

PROCEDURE DIVISION.

level-1 section.
main-logic.

 open output p-o-file.
 close p-o-file.
 stop run.
Approach One

You can compile the preceding program as is with the -Zx option, to generate the data dictionary. The compiled program will run, and will build the database table shown at the end of this section.

Here's how the database table is built. First, any fields listed in the KEY IS clause of the SELECT are included (p-o-number in this example). Then the compiler takes the largest record (p-o-detail-record), and lists the fields that make up that record. The next two pages show the specific fields that are placed into the table.

All of the data from the COBOL program is stored in and retrieved from the database, even though not all fields are explicitly named in the database table. See Data Dictionaries for a description of how this works.

The underlined fields are the only ones that will be entered into the table:

fd p-o-file.
01 p-o-record.
 03 p-o-division-number         pic 9(3).
 03 p-o-record-type             pic x.
  88 header-record           value "h".
  88 detail-record           value "d".

 03 p-o-number                  pic 9(10).
 03 p-o-number-detail redefines p-o-number.
  05 picking-ticket-number      pic 9(6).
  05 shipping-region            pic 9(2).
  05 p-o-customer-type          pic 9(2).
  05 p-o-customer-breakdown redefines 
    p-o-customer-type.
   07 customer-category         pic x.
    88 p-o-customer-retail   value "r".
    88 p-o-customer-whlsale  value "w".
   07 customer-pay-format       pic x.
    88 is-net-30             value "3".
    88 is-net-10             value "1".
 03 p-o-date.
  05 p-o-yy                     pic 9(2).
  05 p-o-mm                     pic 9(2).
  05 p-o-dd                     pic 9(2).

01  p-o-detail-record.
 03 p-o-dept-number             pic 9(3).
 03 p-o-record-type             pic x.
 03 detail-p-o-number           pic 9(10).
 03 p-o-shipping-info.
  05 p-o-quantity-to-ship       pic s9(4) comp.
  05 p-o-total-quantity         pic s9(4) comp.
 03 p-o-notes.
  05 notes-line occurs 3 times  pic x(40).
As the table is built:

* Any hyphens in the COBOL field names are converted to underscores.

* Field names longer than 18 characters will issue a warning if they are not unique within the first 18 characters. Some databases, Informix for example, limit you to 18 total characters. It is recommended for portability and for end-user purposes, that you use the least amount of characters.

* Fields in OCCURS clauses get special handling, because the runtime system must assign a unique name to each data item. So sequential index numbers are appended to the item named in the OCCURS. Because the indexed name cannot exceed 30 characters (the limit for Oracle), the name is truncated by Acu4GL if necessary before the index is added.

NOTE

detail-p-o-number is not part of the table, because the key overlays this area.

This table is built in the database:

table2.gif

* For these Types in DBMaker, substitute, in order, decimal (10, 0), smallint, smallint, smallint.

See the Limits and Ranges topic found in the section specific to your RDMS for a list of supported data types and their COBOL equivalents.

Approach Two

Suppose that you wanted both record formats to be placed into the table. This might be the case if you intended to do any work within your RDMS. Add the WHEN directive in front of each record, as shown below (see the topic that discusses Using Directives ). The underlined fields are the ones that will be entered into the table:

fd p-o-file.
*(( xfd when p-o-record-type = "h" ))
01 p-o-record.
 03 p-o-division-number                 pic 9(3).
 03 p-o-record-type                     pic x.
  88 header-record                   value "h".
  88 detail-record                   value "d".
 03 p-o-number                          pic 9(10).
 03 p-o-number-detail redefines p-o-number.
  05 picking-ticket-number              pic 9(6).
  05 shipping-region                    pic 9(2).
  05 p-o-customer-type                  pic 9(2).
  05 p-o-customer-breakdown redefines 
      p-o-customer-type.
   07 customer-category                 pic x.
    88 p-o-customer-retail           value "r".
    88 p-o-customer-whlsale          value "w".
   07 customer-pay-format               pic x.
    88 is-net-30                     value "3".
    88 is-net-10                     value "1".
 03 p-o-date.
  05 p-o-yy                             pic 9(2).
  05 p-o-mm                             pic 9(2).
  05 p-o-dd                             pic 9(2).
*(( xfd when p-o-record-type = "d" ))
01 p-o-detail-record.
 03 p-o-dept-number                     pic 9(3).
 03 p-o-record-type                     pic x.
 03 detail-p-o-number                   pic 9(10).
 03 p-o-shipping-info.
  05 p-o-quantity-to-ship               pic s9(4) comp.
  05 p-o-total-quantity                 pic s9(4) comp.
 03 p-o-notes.
  05 notes-line occurs 3 times          pic x(40).
NOTE

p-o-record-type is entered into the table only once. The detail-p-o-number field is not part of the table, because the key overlays this area.

This table is built in the database:

table3.gif

* For these Types in DBMaker, substitute, in order, smallint, decimal (10,0), smallint, smallint, smallint, smallint, smallint, smallint.
 
 

Approach Three

In this final approach, you decide to streamline the code a bit. Three changes are introduced:

* The USE GROUP directive is applied to the notes, because you don't need to access each note line individually from the database side. Grouping them improves execution speed and clarity.

* The notes field is renamed for convenience.

* The USE GROUP and DATE directives are applied to the date, to give it all the properties of a date on the database side.

fd p-o-file.
*(( xfd when p-o-record-type = "h" ))
01 p-o-record.
 03 p-o-division-number                 pic 9(3).
 03 p-o-record-type                     pic x.
  88 header-record                   value "h".
  88 detail-record                   value "d".
 03 p-o-number                          pic 9(10).
 03 p-o-number-detail redefines p-o-number.
  05 picking-ticket-number              pic 9(6).
  05 shipping-region                    pic 9(2).
  05 p-o-customer-type                  pic 9(2).
  05 p-o-customer-breakdown redefines 
    p-o-customer-type.
   07 customer-category                 pic x.
    88 p-o-customer-retail           value "r".
    88 p-o-customer-whlsale          value "w".
   07 customer-pay-format               pic x.
    88 is-net-30&                    value "3".
    88 is-net-10                     value "1".
*(( xfd use group, date ))
03 p-o-date.
  05 p-o-yy                             pic 9(2).
  05 p-o-mm                             pic 9(2).
  05 p-o-dd                             pic 9(2).
*(( xfd when p-o-record-type = "d" ))
01 p-o-detail-record.
 03 p-o-dept-number                     pic 9(3).
 03 p-o-record-type                     pic x.
 03 detail-p-o-number                   pic 9(10).
 03 p-o-shipping-info.
  05 p-o-quantity-to-ship               pic s9(4) comp.
  05 p-o-total-quantity                 pic s9(4) comp.
*(( xfd use group, name = notes ))
 03 p-o-notes.
  05 notes-line occurs 3 times          pic x(40).
NOTE

p-o-record-type is entered only once into the table. The detail-p-o-number field is not part of the table, because the key overlays this area.
This table is built in the database:

table4.gif

* For these Types in DBMaker, substitute, in order, smallint, decimal (10,0), smallint, smallint, smallint.

This is the end of the Working with COBOL section. Click the Contents button at the top of this window to return to the Table of Contents page.