Program with headers - SAMPLE2
This program has headers that will appear on the first page only. This
is because the headers are written in the A-100-INITIALIZE paragraph just
after the files have been opened. If we had a multiple page report and
we wanted headers on every page, we would have had to handle this
differently (examples of this are coming).
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE2.
AUTHOR. GROCER
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT CUSTOMER-FILE
ASSIGN TO "C:\PCOBWIN\CIS12FST\C12FIRST.DAT".
SELECT CUSTOMER-REPORT
ASSIGN TO PRINTER.
DATA DIVISION.
FILE SECTION.
FD CUSTOMER-FILE
DATA RECORD IS CUSTOMER-RECORD.
01 CUSTOMER-RECORD.
05 CUSTOMER-ID PIC X(4).
05 CUSTOMER-NAME PIC X(20).
05 CUSTOMER-STREET PIC X(20).
05 CUSTOMER-CITY PIC X(15).
05 CUSTOMER-STATE PIC X(2).
05 CUSTOMER-ZIP PIC X(5).
05 FILLER PIC X(10).
FD CUSTOMER-REPORT
DATA RECORD IS PRINTZ.
01 PRINTZ.
05 FILLER PIC X.
05 CUSTOMER-ID-PR PIC X(4).
05 FILLER PIC X(2).
05 CUSTOMER-NAME-PR PIC X(20).
05 FILLER PIC X(2).
05 CUSTOMER-STREET-PR PIC X(20).
05 FILLER PIC X(2).
05 CUSTOMER-CITY-PR PIC X(15).
05 FILLER PIC X(2).
05 CUSTOMER-STATE-PR PIC X(2).
05 FILLER PIC X(2).
05 CUSTOMER-ZIP-PR PIC X(5).
05 FILLER PIC X(3).
WORKING-STORAGE SECTION.
01 INDICATORS.
05 END-OF-FILE PIC XXX VALUE "NO ".
01 PAGE-HDR.
05 FILLER PIC X(24) VALUE SPACES.
05 FILLER PIC X(32)
VALUE "CUSTOMER NAME AND ADDRESS REPORT".
05 FILLER PIC X(24) VALUE SPACES.
01 COLUMN-HDR.
05 FILLER PIC X VALUE SPACES.
05 FILLER PIC X(4) VALUE "ID #".
05 FILLER PIC X(2) VALUE SPACES.
05 FILLER PIC X(13) VALUE "CUSTOMER NAME".
05 FILLER PIC X(9) VALUE SPACES.
05 FILLER PIC X(14) VALUE "STREET ADDRESS".
05 FILLER PIC X(8) VALUE SPACES.
05 FILLER PIC X(4) VALUE "CITY".
05 FILLER PIC X(11) VALUE SPACES.
05 FILLER PIC X(5) VALUE "STATE".
05 FILLER PIC X VALUE SPACES.
05 FILLER PIC X(3) VALUE "ZIP".
05 FILLER PIC X(5) VALUE SPACES.
PROCEDURE DIVISION.
MAIN-PROGRAM.
PERFORM A-100-INITIALIZATION.
PERFORM B-100-PROCESS-FILE.
PERFORM C-100-WRAP-UP.
STOP RUN.
A-100-INITIALIZATION.
OPEN INPUT CUSTOMER-FILE
OUTPUT CUSTOMER-REPORT.
WRITE PRINTZ FROM PAGE-HDR
AFTER ADVANCING PAGE.
WRITE PRINTZ FROM COLUMN-HDR
AFTER ADVANCING 2 LINES.
MOVE SPACES TO PRINTZ.
WRITE PRINTZ
AFTER ADVANCING 1 LINES.
B-100-PROCESS-FILE.
READ CUSTOMER-FILE
AT END
MOVE "YES" TO END-OF-FILE.
PERFORM B-200-PROCESS-RECORD
UNTIL END-OF-FILE = "YES".
B-200-PROCESS-RECORD.
MOVE SPACES TO PRINTZ.
MOVE CUSTOMER-ID TO CUSTOMER-ID-PR.
MOVE CUSTOMER-NAME TO CUSTOMER-NAME-PR.
MOVE CUSTOMER-STREET TO CUSTOMER-STREET-PR.
MOVE CUSTOMER-CITY TO CUSTOMER-CITY-PR.
MOVE CUSTOMER-STATE TO CUSTOMER-STATE-PR.
MOVE CUSTOMER-ZIP TO CUSTOMER-ZIP-PR.
WRITE PRINTZ
AFTER ADVANCING 1 LINE.
READ CUSTOMER-FILE
AT END
MOVE "YES" TO END-OF-FILE.
C-100-WRAP-UP.
CLOSE CUSTOMER-FILE
CUSTOMER-REPORT.
*
*Note: An * in col 7 makes the line a comment.
*The input file being processed by this program contains the
*following three records:
*
*1234Jane Doe 123 Elm St Fall River MA02771
*2345Ann Smith 45 Oak St Braintree MA02184
*3456Susan Ash 234 Maple St Weymouth MA02180
*
*
*
*Output that was produced:
*
* CUSTOMER NAME AND ADDRESS REPORT
*
* ID # CUSTOMER NAME STREET ADDRESS CITY STATE ZIP
*
* 1234 Jane Doe 123 Elm St Fall River MA 02771
* 2345 Ann Smith 45 Oak St Braintree MA 02184
* 3456 Susan Ash 234 Maple St Weymouth MA 02180