[USflag] The American Programmer [USflag]


Home
Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer - iSeries
Everything about CICS
Cobol programs, manuals, books
  Sample Cobol code: The Simple, Single File COBOL Program
  Sample Cobol code: The Simple, Single File Report COBOL Program with Record Count or Final Totals
  Sample Cobol code: The Simple, Single File Report COBOL Program with Record Count or Final Totals
  Sample Cobol code: The Sequence Check COBOL Program
  Sample Cobol code: The Record Selection COBOL Program
  Sample Cobol code: The Edit or Validate COBOL Program
  Sample Cobol code: The The One Level Subtotal (Control Break) COBOL Program
  Sample Cobol code: The Three Level Subtotal (Control Break) COBOL Program
  Sample Cobol code: The Sequential File, Batch Update COBOL Program
  Sample Cobol code: The COBOL Sort
  Sample Cobol code: The CASE Structure: COBOL EVALUATE
  Sample Cobol code: Direct Subscripting in COBOL
  Sample Cobol code: The Sequential, or Serial Search in COBOL
  Sample Cobol code: The Binary Search in COBOL
  Sample Cobol code: Loading a Table from a Sequential File in a COBOL program
  Sample Cobol code: The VSAM File Read Sequentially in a COBOL program
  Sample Cobol code: The VSAM KSDS, Read Randomly in a COBOL program
  Sample Cobol code: The VSAM File, Read Randomly in a COBOL program
  Sample Cobol code: VSAM Initial Load in a COBOL program
  Sample Cobol code: VSAM File Maintenance (Add, Change, Delete) in a COBOL program
  Sample Cobol code: VSAM Read Sequentially, with START, in a COBOL program
  Sample Cobol code: Creating a Variable Format File in a COBOL program
  Sample Cobol code: Reading a Variable Format File in a COBOL program
  Sample Cobol code: Creating a Variable Format File with Occurs Depending On in a COBOL program
  Sample Cobol code: COBOL Reading a Variable Format File with Occurs Depending On, in a COBOL program
  Sample Cobol code: COBOL The Table Load with Occurs Depending On
  Sample Cobol/DB2 code: Singleton Select
  Manuals on the COBOL programming language.
  Books on Cobol
  Abend Codes from Cobol programs
Everything about DB2 and SQL
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > COBOL   > The Simple, Single File Report Program

The Simple, Single File Report COBOL Program


2. The Simple, Single File Report Program

SEQRPT1.
Same as the Simple, Single File Program, #1 above, but it prints things on paper, producing a report. It will print each record that it reads (detail printing) Also, some printing logic is needed in order to print out headers and detail lines. Logic is needed to change the page when needed.

This type of program is very common. It simply reports on what is found in a file, formatting it in a way that is easy to read. Although the major logic path is not complex, it may be combined with a table lookup which will transform some value found on the file into some other, more meaningful value for use on the report.

Here is an explanation of the logic of SEQRPT1. This programís logic is very similar to that of SEQSIMP1, but it prints out a report, so there is output formatting, lines are counted, (line 12200) so that the page can be changed at the appropriate time (line 10900).

All WRITE statements have an added option - AFTER ADVANCING. This causes the compiler to take on the job of controlling printer spacing (line 14000). PAGE makes it go to the top of the next page, 1 LINE advances 1 line, etc. Please use AFTER ADVANCING only with report files, do not use it with data files that will normally be read only by another program.

AFTER ADVANCING steals the first character of your print line, using it for printer control commands, so you canít use it for anything else.

Here is the program SEQRPT1:

Compliments of Gabe Gargiulo, author of several recent books on programming and modern languages, available at Amazon.com.



000200 IDENTIFICATION DIVISION.
000300 PROGRAM-ID. SEQRPT1.
000400*    General logic for program that reads every input record
000500*     and then prints it out.
000600* header and detail line, page change
000700 ENVIRONMENT DIVISION.
000800 CONFIGURATION SECTION.
000900 INPUT-OUTPUT SECTION.
001000 FILE-CONTROL.
001100*    INPUT FILE PARTS
001200     SELECT IN-FILE  ASSIGN PARTS.
001500*    OUTPUT FILE: SEND TO PRINTER
001600     SELECT OUT-FILE ASSIGN OUTFILE.
001900 DATA DIVISION.
002000 FILE SECTION.
002100 FD  IN-FILE
002110     RECORDING MODE IS F
002500     RECORD CONTAINS 80 CHARACTERS.
002600 01  IN-RECORD PIC X(80).
002610      05  PART-NUMBER     PIC X(6).
002620      05  filler          pic x.
002630      05  PART-DESC       PIC X(30).
002640      05  filler          pic x.
002650      05  QTY-ON-HAND     PIC 9(3).
002660      05  filler          pic x.
002670      05  QTY-ON-ORDER    PIC 9(3).
002680      05  filler          pic x.
002690      05  QTY-ON-RESERVE  PIC 9(3).
002700      05  filler          pic x.
002710      05  PART-PRICE      PIC 9(3)V99.
002720      05  UNUSED          PIC X(25).
002730
002800 FD  OUT-FILE
002810     RECORDING MODE IS F
003000*    Record length can be more than input file
003100*    because you are printing, not copying to a file
003400     RECORD CONTAINS 133 CHARACTERS.
003500 01  OUT-RECORD PIC X(133).
003600
003700 WORKING-STORAGE SECTION.
003800 01  SWITCHES.
003900      05  FILE-AT-END     PIC X  VALUE 'N'.
004000
004100 01  COUNTERS-AND-ACCUMULATORS.
004200      05  LINES-PRINTED        PIC S9(5)
004300             PACKED-DECIMAL VALUE 0.
004400      05  INPUT-RECORD-COUNT   PIC S9(5)
004500             PACKED-DECIMAL VALUE 0.
004600      05  OUTPUT-RECORD-COUNT  PIC S9(5)
004700             PACKED-DECIMAL VALUE 0.
004800*      55 is a very common value. use more or less according
004900*      to your program's requirements
005000      05  MAX-PER-PAGE         PIC S9(5) PACKED-DECIMAL
005100           VALUE +55.
006700
006800 01  WS-OUT-RECORD.
006900*   We will use edit fields for the numeric fields
007000*   we are using fillers between the fields for legibility
007100      05  FILLER              PIC X(3) VALUE SPACES.
007200      05  OUT-PART-NUMBER     PIC X(6).
007300      05  FILLER              PIC X(3) VALUE SPACES.
007400      05  OUT-PART-DESC       PIC X(30).
007500      05  FILLER              PIC X(3) VALUE SPACES.
007600      05  OUT-QTY-ON-HAND     PIC ZZ9.
007700      05  FILLER              PIC X(3) VALUE SPACES.
007800      05  OUT-QTY-ON-ORDER    PIC ZZ9.
007900      05  FILLER              PIC X(3) VALUE SPACES.
008000      05  OUT-QTY-ON-RESERVE  PIC ZZ9.
008100      05  FILLER              PIC X(3) VALUE SPACES.
008200      05  OUT-PART-PRICE      PIC ZZZ.99.
008300      05  FILLER              PIC X(3) VALUE SPACES.
008400      05  OUT-UNUSED          PIC X(30).
008500      05  FILLER              PIC X(31) VALUE SPACES.
008600
008700 01  HEADER-1.
008800*     Leave first character position blank
008900*      because of after advancing
009000     05  FILLER               PIC X VALUE SPACE.
009100     05  FILLER               PIC X(80)
009200         VALUE 'PRINT OF DATA FILE FOR ABC COMPANY'.
009300
009400 PROCEDURE DIVISION.
009500     PERFORM INITIALIZATION
009600*    UPPER CASE Y, PLEASE
009700     PERFORM PROCESS-ALL
009800         UNTIL FILE-AT-END = 'Y'
009900     PERFORM TERMINATION
010000     GOBACK.
010100
010200 INITIALIZATION.
010300     OPEN INPUT IN-FILE
010400          OUTPUT OUT-FILE
010500     PERFORM HEADING-ROUTINE
010600     PERFORM READ-PAR.
010700
010800 PROCESS-ALL.
010900     IF LINES-PRINTED > MAX-PER-PAGE
011000     THEN
011100            PERFORM HEADING-ROUTINE
011200     END-IF
011300     MOVE PART-NUMBER    TO OUT-PART-NUMBER
011400     MOVE PART-DESC      TO OUT-PART-DESC
011500     MOVE QTY-ON-HAND    TO OUT-QTY-ON-HAND
011600     MOVE QTY-ON-ORDER   TO OUT-QTY-ON-ORDER
011700     MOVE QTY-ON-RESERVE TO OUT-QTY-ON-RESERVE
011800     MOVE PART-PRICE     TO OUT-PART-PRICE
011900     MOVE UNUSED         TO OUT-UNUSED
012000     WRITE OUT-RECORD    FROM WS-OUT-RECORD
012100         AFTER ADVANCING 1 LINE
012200     ADD 1 TO LINES-PRINTED
012300     PERFORM READ-PAR.
012400
012500 TERMINATION.
012600     CLOSE IN-FILE OUT-FILE.
012700
012800 READ-PAR.
012900     READ IN-FILE 
013000         AT END MOVE 'Y' TO FILE-AT-END
013100     END-READ.
013200
013300 HEADING-ROUTINE.
013400*       after advancing PAGE does a page eject,
013500*        puts printer at top of page
013600*        after doing advancing page,
013700*        all your writes for that file must use the adv. option
013800*        and you must have a blank filler in the first
013900*        character position of the line to be printed
014000     WRITE OUT-RECORD FROM HEADER-1 AFTER ADVANCING PAGE
014100     MOVE 0 TO LINES-PRINTED.

Compliments of Gabe Gargiulo, author of several recent books on programming and modern languages, available at Amazon.com.
Here is the input data file PARTS: (the next two lines are a column ruler) 1 2 3 4 5 6 123456789.123456789.123456789.123456789.123456789.123456789.12345678 PART01 LEFT HANDED WIDGET WRENCHES 003 007 002 10022 PART02 LEAD-WINGED GLIDERS 004 006 001 14054 PART04 LEFT FOOT REEBOKS 021 002 004 04323 PART06 286 COMPUTERS W 4K HARD DISK 043 077 012 00042 Here is sample JCL: //STEP1 EXEC PGM=SEQRPT1 //STEPLIB DD DSN=your.executable.program.library.goes.here,DISP=SHR //*OF COURSE, THE NEXT LIBRARY NAME MAY BE DIFFERENT AT YOUR COMPANY //PARTS DD DSN=userid.COBBOOK.DATA(PARTS),DISP=SHR //OUTFILE DD SYSOUT=* //SYSOUT DD SYSOUT=* //SYSUDUMP DD SYSOUT=*

Top of Page

Your email and other personal information will not be given to anyone
[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |