Examples of Preparing and Compiling a Program

The DatabaseConnectors sub-directory within your Examples directory contains three sample programs that are based on the code excerpt below. These programs show different ways of how to manipulate your COBOL records in readiness for being written to a database. Remember to compile them with the appropriate IDXFORMAT directive and accompanying ACUFH configuration file.

Note: If you are not familiar with XFD directives, you may want to read the topics in the Using XFD Directives section before continuing with this topic.

The examples are based upon a purchase orders file from a COBOL program and will be stored in a database. The file descriptor below contains the records that handle all of the information from a fictitious company's purchase orders. Within it are two record types:

The file is keyed off the purchase order number. This following three examples demonstrate three different approaches to using the COBOL file descriptor and XFD directives:

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.