[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   > COBOL program Reading a Variable Format File with Occurs Depending On

COBOL Reading a Variable Format File with Occurs Depending On, in a COBOL program


25. Reading a Variable Format File with Occurs Depending On

VARODOR1.
This program, VARODOR1 will read the variable format data file created by VARODOW1. Notice how easy it is to read this file: the program's logic is very simple.
The Occurs Depending On handles the record length automatically.

Here is the program VARODOR1:

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


000200 IDENTIFICATION DIVISION.
000300 PROGRAM-ID. VARODOR1.
000400* the input file is variable format
000500*     with three record lengths: 20, 40, 60
000600* the occurs depending on counter
000700* tells if you have short, med, long
000800*
000900 ENVIRONMENT DIVISION.
001000 CONFIGURATION SECTION.
001100 INPUT-OUTPUT SECTION.
001200 FILE-CONTROL.
001300*  INPUT FILE: is from program varodow1
001400     SELECT INFILE  ASSIGN INFILE.
001800     SELECT OUTFILE ASSIGN REPORTFI.
002200 DATA DIVISION.
002300 FILE SECTION.
002400
002500 FD  INFILE
002510     RECORDING MODE IS V
002800*     so 64 is really the maximum record length.
002900*     don't put  64 here, because MVS would make it 68...
003000*     if you use the LRECL parameter in JCL, it must be 64 , not
003100*     (the minimum record length means nothing -
003200*           you could put 0, 1, or 59...they all work the same)
003300     RECORD CONTAINS 20 to 60 CHARACTERS.
003600*     this record description is the same as
003700*     the one used for creating it - see program varodow1
003800 01  IN-RECORD.
003900     05 ODO-COUNTER PIC 9(5).
004000     05 FILLER      PIC X(5).
004100     05 INPUT-NAME  PIC X(10)
004200          OCCURS 5 TIMES DEPENDING ON ODO-COUNTER.
004300
004400 FD  OUTFILE
004410     RECORDING MODE IS F
004800     RECORD CONTAINS 133 CHARACTERS.
004900 01  OUT-RECORD PIC X(133).
005000
005100 WORKING-STORAGE SECTION.
005200 01  SWITCHES.
005300      05  FILE-AT-END     PIC X  VALUE 'N'.
005400
005500 01  WS-PRINT-LINE.
005600     05 FILLER              PIC X VALUE SPACE.
005700     05 WS-PRINT-LINE-DATA PIC X(132) VALUE SPACES.
005800
005900 PROCEDURE DIVISION.
006000     PERFORM INITIALIZATION
006100     PERFORM PROCESS-ALL
006200**       upper case Y, please
006300         UNTIL FILE-AT-END = 'Y'
006400     PERFORM TERMINATION
006500     GOBACK.
006600
006700 INITIALIZATION.
006800     OPEN INPUT INFILE
006900          OUTPUT OUTFILE
007000     PERFORM READ-PAR.
007100
007200 PROCESS-ALL.
007300        MOVE SPACES TO  WS-PRINT-LINE.
007400*     this next move will move only as much
007500*     of in-record as needed
007600*     it looks at the odo counter first
007700*     to determine how long in-record is
007800     MOVE IN-RECORD TO WS-PRINT-LINE-DATA
007900     WRITE OUT-RECORD FROM WS-PRINT-LINE-DATA
008000          AFTER ADVANCING 1 LINE
008100     PERFORM READ-PAR.
008200
008300 TERMINATION.
008400     CLOSE INFILE OUTFILE.
008500
008600 READ-PAR.
008700*     we are not reading INTO here
008800*     because we don't know what to read into
008900*     until we have already read a record
009000     READ INFILE
009100         AT END MOVE 'Y' TO FILE-AT-END
009200     END-READ.

Compliments of Gabe Gargiulo, author of several recent books on programming and modern languages, available at Amazon.com.
Here is sample JCL: //STEP1 EXEC PGM=VARODOW1 //STEPLIB DD DSN=your.executable.program.library.goes.here,DISP=SHR //*OF COURSE, THE NEXT LIBRARY NAME MAY BE DIFFERENT AT YOUR COMPANY //FIXEDINP DD DSN=userid.COBBOOK.DATA(FIXEDINP),DISP=SHR //VAROUT DD DSN=&&TEMPFILE, // DISP=(NEW,PASS), // UNIT=SYSDA, MAY HAVE TO CHANGE SYSDA // SPACE=(TRK,(1)), // LRECL=64,RECFM=VB 64 is right - programís 60, +4 //SYSOUT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //* //STEP2 EXEC PGM=VARODOR1 //STEPLIB DD DSN=your.executable.program.library.goes.here,DISP=SHR //*OF COURSE, THE NEXT LIBRARY NAME MAY BE DIFFERENT AT YOUR COMPANY //VARINP DD DSN=&&TEMPFILE,DISP=(OLD,DELETE), // LRECL=64,RECFM=VB //REPORTFI 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 |