[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 Sequence Check Program

The Sequence Check COBOL Program


4. The Sequence Check Program

SEQCK1.
Similar to The Simple, Single File Report Program with record count or final totals, #3 above, but checks the input file to determine whether the records are in sort order on some field, such as an account number. When a record is encountered that is out of order, it prints out the offending record and as much other useful information as possible. At the end of the file, it prints out a record count and the count of records that were out of sequence. If some were out of sequence, it prints out or displays a noticeable error message.

One day this will be your programming assignment:
A file is received from a distant location, from another company, from another business application system within the company. The file should be in sorted order - but what if it isnít? That could cause a database load, a VSAM KSDS load, a file update program or a subtotal program to abend or worse - produce disastrous results. Your job is to write a program that simply checks the sequence of the records.

A few words about the logic of this program. It builds on the logic of the SEQSIMP1 program. However it must save the field you are checking for sequence (line 11800), right after reading the first record (line 11600).

The actual sequence checking is done in a separate paragraph so as to keep PROCESS-ALL simple.

The program makes a major decision (line 12500), whether to write to the valid file or the invalid file.

Here is the program SEQCK1:

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



000200 IDENTIFICATION DIVISION.
000300* Batch cobol sequence check file
000400 program-id. Seqck1.
000500* logic for program that reads every input record
000600* it writes it out to an output file only if in sequence.
000700* displays a message if records not in sequence
000800 ENVIRONMENT DIVISION.
000900 INPUT-OUTPUT SECTION.
001000 FILE-CONTROL.
001100* Input file: (first time you run it) emp
001200*    (no out of seq records)
001300*    run it a second time with emp1 (out of seq records)
001400      SELECT INPUT-FILE ASSIGN EMP.
001700* Output file:  validfi:
001800*    send to printer for this example.
001900*    in real life it might be a real disk/tape file
002000     SELECT VALID-FILE  ASSIGN VALIDFI.
002300* Output file:  reportfi: a report file,
002400*    prints out information on out of sequence records,
002500*    send to printer
002600     SELECT REPORT-FILE  ASSIGN REPORTFI.
002900
003000 DATA DIVISION.
003100 FILE SECTION.
003200
003300 FD  INPUT-FILE
003400     RECORDING MODE IS F
003700     RECORD CONTAINS 80 CHARACTERS.
003710 01  EMPLOYEE-RECORD.
003720     05  FILLER                        PIC X(8).
003730     05  FILLER                        PIC X(01).
003740     05  ER-EMPLOYEE-NUMBER            PIC X(05).
003750     05  FILLER                        PIC X(01).
003760     05  ER-EMPLOYEE-NAME              PIC X(25).
003770     05  FILLER                        PIC X(01).
003780     05  ER-EMPLOYEE-DEPARTMENT        PIC X(05).
003790     05  FILLER                        PIC X(01).
003800     05  ER-EMPLOYEE-SALARY-CODE       PIC X(02).
003810     05  FILLER                        PIC X(01).
003820     05  FILLER                        PIC X(30).
003900
004000 FD  VALID-FILE
004100     RECORDING MODE IS F
004400     RECORD CONTAINS 80 CHARACTERS.
004500 01  VALID-RECORD                       PIC X(80).
004600
004700 FD  REPORT-FILE
004800     RECORDING MODE IS F
005100     RECORD CONTAINS 133 CHARACTERS.
005200
005300 01  REPORT-RECORD                      PIC X(133).
005400
005500 WORKING-STORAGE SECTION.
005600
005700 01  FILE-AT-END             PIC X VALUE 'N'.
005800*
005900 01  SW-VALID-RECORD         PIC X VALUE 'Y'.
006000
007700 01  HOLD-EMPLOYEE-NUMBER    PIC X(5) VALUE SPACES.
007800
007900 01  COUNTERS-AND-ACCUMULATORS.
008000     05  CTR-OUT-OF-SEQ      PIC  S9(5)
008100             PACKED-DECIMAL     VALUE 0.
008200     05  CTR-RECORDS-READ    PIC  S9(5)
008300             PACKED-DECIMAL     VALUE 0.
008400     05  CTR-RECORDS-WRITTEN PIC  S9(5)
008500             PACKED-DECIMAL     VALUE 0.
008600
008700 01  TITLE-HEADING-LINE.
008800     05  FILLER               PIC X(1) VALUE SPACES.
008900     05  FILLER               PIC X(35)
009000                   VALUE 'SEQUENCE CHECK PROGRAM'.
009100     05  FILLER               PIC X(04) VALUE SPACES.
009200     05  FILLER               PIC X(33)
009300                   VALUE 'OUT OF SEQUENCE RECORDS '.
009400     05  REPORT-DATE.
009500           10  REPORT-YY            PIC 99.
009600           10  REPORT-MM            PIC 99.
009700           10  REPORT-DD            PIC 99.
009800
009900 01  DETAIL-INVALID-LINE.
010000     05  FILLER               PIC X(1) VALUE SPACES.
010100     05  REASON-INVALID       PIC X(30) VALUE SPACES.
010200     05  RECORD-IMAGE         PIC X(80) VALUE SPACES.
010300
010400 PROCEDURE DIVISION.
010500     PERFORM INITIALIZATION
010600     PERFORM PROCESS-ALL UNTIL
010700        FILE-AT-END = 'Y'
010800     PERFORM TERMINATION
010900     GOBACK.
011000
011100 INITIALIZATION.
011200     OPEN INPUT INPUT-FILE
011300          OUTPUT VALID-FILE
011400                 REPORT-FILE
011500     WRITE REPORT-RECORD FROM TITLE-HEADING-LINE
011600     PERFORM READ-PAR
011700
011800     MOVE ER-EMPLOYEE-NUMBER TO HOLD-EMPLOYEE-NUMBER
011900     ACCEPT REPORT-DATE FROM DATE.
012000
012100 PROCESS-ALL.
012200     MOVE SPACES TO DETAIL-INVALID-LINE
012300     MOVE 'Y' TO SW-VALID-RECORD
012400     PERFORM SEQUENCE-CHECK
012500     IF SW-VALID-RECORD = 'Y'
012600     THEN
012700        PERFORM WRITE-VALID-RECORD
012800        ADD 1 TO CTR-RECORDS-WRITTEN
012900     ELSE
013000        PERFORM PRINT-INVALID-LINE
013100        ADD 1 TO CTR-OUT-OF-SEQ
013200     END-IF
013300
013400     PERFORM READ-PAR.
013500
013600 WRITE-VALID-RECORD.
013700
013800     WRITE VALID-RECORD FROM EMPLOYEE-RECORD.
013900
014000 PRINT-INVALID-LINE.
014100     MOVE EMPLOYEE-RECORD TO RECORD-IMAGE
014200     WRITE REPORT-RECORD FROM DETAIL-INVALID-LINE.
014300
014400 TERMINATION.
014500
014600     CLOSE INPUT-FILE
014700           VALID-FILE
014800           REPORT-FILE
014900     IF CTR-OUT-OF-SEQ > 1
015000     THEN
015100        GO TO ERROR-EXIT.
015200
015300 SEQUENCE-CHECK.
015400     IF ER-EMPLOYEE-NUMBER < HOLD-EMPLOYEE-NUMBER
015500       MOVE    'RECORD OUT OF SEQUENCE (EMPLOYEE-NUMBER)'
015600                TO REASON-INVALID
015700       MOVE    EMPLOYEE-RECORD TO RECORD-IMAGE
015800       MOVE 'N' TO SW-VALID-RECORD
015900       ADD 1 TO CTR-OUT-OF-SEQ
016000     END-IF
016100     MOVE ER-EMPLOYEE-NUMBER TO HOLD-EMPLOYEE-NUMBER.
016200
016300  READ-PAR.
016400     READ INPUT-FILE
016500     AT END
016600        MOVE 'Y' TO FILE-AT-END
016700     NOT AT END
016800        ADD 1 TO CTR-RECORDS-READ
016900     END-READ.
017000
017100  ERROR-EXIT.
017200     DISPLAY 'THERE WERE OUT-OF-SEQUENCE RECORDS'
017300     DISPLAY 'THE OUTPUT FILE MAY NOT BE USEABLE'
017400     GOBACK.

Compliments of Gabe Gargiulo, author of several recent books on programming and modern languages, available at Amazon.com.
Here is the input data file EMP: (the next two lines are a column ruler) 1 2 3 4 5 6 123456789.123456789.123456789.123456789.123456789.123456789.12345678 01000 PEARLE E GATES D0001 01 02000 LED BALOON D0002 04 03000 KIT E LITTER D0005 06 04000 MOE PEDD D0504 01 Here is sample JCL: //STEP1 EXEC PGM=SEQCK1 //STEPLIB DD DSN=your.executable.program.library.goes.here,DISP=SHR //*OF COURSE, THE NEXT LIBRARY NAME MAY BE DIFFERENT AT YOUR COMPANY //EMP DD DSN=userid.COBBOOK.DATA(EMP),DISP=SHR //VALIDFI 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 |