[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 Edit or Validate Program

The Edit or Validate COBOL Program


6. The Edit or Validate Program

VALID1.
Similar to The Record Selection Program, #5 above, but produces a report. It typically writes out the “good” records to a file, as in The Sequence Check Program, #4, but it also prints out the “bad” records on a report. If some were invalid, it prints out or displays a noticeable error message.

Please compare this program to the Selection program and to the Sequence Check program. The logic is very similar. The Edit or Validate program will check every record of the input file against certain criteria. These criteria might be:
- all number fields contain valid numerics
- all data fields contain data - not spaces
- certain fields contain data that is found on a table (see the programs EVAL1, DIRSUB1, SERSRCH1, BINSRCH1.

Here is the program VALID1:

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



000200 IDENTIFICATION DIVISION.
000300* Validate input data
000400*  if good, write to output file
000500*  if bad, print out on report
000600 PROGRAM-ID. VALID1.
000700 ENVIRONMENT DIVISION.
000800 INPUT-OUTPUT SECTION.
000900 FILE-CONTROL.
001000*     INPUT FILE EMP1
001100     SELECT INPUT-FILE ASSIGN EMP1.
001500*     OUTPUT FILE VALIDFI SEND TO PRINTER
001510     SELECT VALID-FILE ASSIGN VALIDFI.
001900*     REPORTFI SEND TO PRINTER
002000     SELECT REPORT-FILE ASSIGN REPORTFI.
002300
002400 DATA DIVISION.
002500 FILE SECTION.
002600
002700 FD  INPUT-FILE
002800     RECORDING MODE IS F
003100     RECORD CONTAINS 80 CHARACTERS.
003200 01  INPUT-RECORD.
003210     05  FILLER                        PIC X(8).
003220     05  FILLER                        PIC X(01).
003230     05  ER-EMPLOYEE-NUMBER            PIC X(05).
003240     05  FILLER                        PIC X(01).
003250     05  ER-EMPLOYEE-NAME              PIC X(25).
003260     05  FILLER                        PIC X(01).
003270     05  ER-EMPLOYEE-DEPARTMENT        PIC X(05).
003280     05  FILLER                        PIC X(01).
003290     05  ER-EMPLOYEE-SALARY-CODE       PIC X(02).
003300     05  FILLER                        PIC X(01).
003310     05  FILLER                        PIC X(30).
003320
003400 FD  VALID-FILE
003500     RECORDING MODE IS F
003800     RECORD CONTAINS 80 CHARACTERS.
003900 01  VALID-RECORD                       PIC X(80).
004000
004100 FD  REPORT-FILE
004200     RECORDING MODE IS F
004500     RECORD CONTAINS 133 CHARACTERS.
004700
004800 01  REPORT-REC                      PIC X(133).
004900
005000 WORKING-STORAGE SECTION.
005100
005200 01  SW-VALID-RECORD                 PIC X VALUE 'Y'.
005300
005400 01  FILE-AT-END                     PIC X VALUE 'N'.
005500*
007200 01  COUNTERS-AND-ACCUMULATORS.
007300     05  CTR-INVALID-RECORDS            PIC  S9(5)
007400               PACKED-DECIMAL       VALUE 0.
007500     05  CTR-RECORDS-READ               PIC  S9(5)
007600               PACKED-DECIMAL       VALUE 0.
007700     05  CTR-RECORDS-WRITTEN            PIC  S9(5)
007800               PACKED-DECIMAL       VALUE 0.
007900
008000 01  TITLE-HEADING-LINE.
008100     05  FILLER                         PIC X(1) VALUE SPACES.
008200     05  FILLER                         PIC X(35)
008300                   VALUE 'VALIDATION PROGRAM'.
008400     05  FILLER                         PIC X(04) VALUE SPACES.
008500     05  FILLER                         PIC X(33)
008600                   VALUE 'INVALID RECORDS         '.
008700     05  REPORT-DATE.
008800           10  REPORT-YY   PIC 99.
008900           10  REPORT-MM   PIC 99.
009000           10  REPORT-DD   PIC 99.
009100     05  FILLER                         PIC X(29) VALUE SPACEs.
009200     05  PAGE-LIT-FLD                   PIC X(5)  VALUE 'PAGE '.
009300     05  PAGE-NUMBER                    PIC 9(2) VALUE 1.
009400
009500 01  DETAIL-INVALID-LINE.
009600     05  FILLER                         PIC X(1) VALUE SPACES.
009700     05  REASON-INVALID                 PIC X(30) VALUE SPACES.
009800     05  RECORD-IMAGE                   PIC X(80) VALUE SPACES.
009900
010000 PROCEDURE DIVISION.
010200     PERFORM INITIALIZATION
010300     PERFORM PROCESS-ALL
010400        UNTIL FILE-AT-END = 'Y'
010500     PERFORM TERMINATION
010600     GOBACK.
010700
010800 INITIALIZATION.
010900     OPEN INPUT INPUT-FILE
011000          OUTPUT VALID-FILE
011100                 REPORT-FILE
011200     PERFORM READ-PAR
011300     ACCEPT REPORT-DATE FROM DATE.
011400
011500 PROCESS-ALL.
011600     MOVE SPACES TO DETAIL-INVALID-LINE
011700     MOVE 'Y' TO SW-VALID-RECORD
011800     PERFORM VALIDATE-THE-RECORD
011900     IF SW-VALID-RECORD  = 'Y'
012000     THEN
012100        PERFORM WRITE-VALID-RECORD
012200        ADD 1 TO CTR-RECORDS-WRITTEN
012300     ELSE
012400        PERFORM PRINT-INVALID-LINE
012500        ADD 1 TO CTR-INVALID-RECORDS
012600     END-IF
012700
012800     PERFORM READ-PAR.
012900
013000 WRITE-VALID-RECORD.
013100     WRITE VALID-RECORD FROM INPUT-RECORD.
013200
013300 PRINT-INVALID-LINE.
013400     MOVE INPUT-RECORD TO RECORD-IMAGE IN DETAIL-INVALID-LINE
013500     WRITE REPORT-REC FROM DETAIL-INVALID-LINE.
013600
013700 TERMINATION.
013800     IF CTR-RECORDS-WRITTEN = 0
013900     THEN
014000         GO TO ERROR-EXIT
014100     END-IF
014200
014300     CLOSE INPUT-FILE
014400           VALID-FILE
014500           REPORT-FILE.
014600
014700 VALIDATE-THE-RECORD.
014800*    If there is anything wrong with the record,
014900*    move 'n' to sw-valid-record.
015000     IF  ER-EMPLOYEE-NUMBER     IS NUMERIC
015100     THEN CONTINUE
015200     ELSE
015300         MOVE 'EMPLOYEE NUM NOT NUMERIC' TO REASON-INVALID
015400         MOVE 'N' TO SW-VALID-RECORD
015500     END-IF
015600     IF  ER-EMPLOYEE-NUMBER            = SPACES
015700     THEN
015800         MOVE 'BAD EMPLOYEE NUMBER    ' TO REASON-INVALID
015900         MOVE 'N' TO SW-VALID-RECORD
016000     END-IF
016100     IF  ER-EMPLOYEE-NAME              = SPACES
016200     THEN
016300         MOVE 'BAD EMPLOYEE NAME      ' TO REASON-INVALID
016400         MOVE 'N' TO SW-VALID-RECORD
016500     END-IF
016600     IF  ER-EMPLOYEE-DEPARTMENT        = SPACES
016700     THEN
016800         MOVE 'BAD EMPLOYEE DEPARTMENT' TO REASON-INVALID
016900         MOVE 'N' TO SW-VALID-RECORD
017000     END-IF
017100     IF  ER-EMPLOYEE-SALARY-CODE       = SPACES
017200     THEN
017300         MOVE 'BAD EMPLOYEE SALARY CODE' TO REASON-INVALID
017400         MOVE 'N' TO SW-VALID-RECORD
017500     END-IF.
017600*    Other things you might check are:
017700*      numeric fields numeric?
017800*      numbers within range
017900*      code is found within a table (table lookup/search verb)
018000*      check whether all fields filled in, etc
018100*    if a field fails the test, move 'n' to valid-flag
018200*    if a field passes the test, do nothing
018300*    complex conditions are best expressed with positives, not ne
018400*    example: if input-code is equal to '1' or '2' or '3'
018500*    then continue
018600*    else
018700*    move 'n' to valid-flag
018800*    end-if.
018900
019000 READ-PAR.
019100     READ INPUT-FILE 
019200         AT END MOVE 'Y' TO FILE-AT-END
019300     NOT AT END
019400        ADD 1 TO CTR-RECORDS-READ
019500     END-READ.
019600
019700 ERROR-EXIT.
019800     DISPLAY 'THERE WERE' CTR-RECORDS-WRITTEN 'GOOD RECORDS'
019900     DISPLAY 'THERE WERE' CTR-INVALID-RECORDS 'INVALID RECORDS'
020000     DISPLAY 'PROGRAM ABORTED'
020100*     AT YOUR COMPANY YOU MIGHT CALL AN ABEND ROUTINE HERE
020200     CLOSE INPUT-FILE
020300           VALID-FILE
020400           REPORT-FILE.
020500     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 EMP1: (the next two lines are a column ruler) 1 2 3 4 5 6 123456789.123456789.123456789.123456789.123456789.123456789.12345678 00001 ZONE, CAL D0001 01 00002 BYE, LOLA D0004 02 00003 PEDD, MOE D0003 04 00004 MANDER, SAL A. D0029 09 00005 BEARER, PAUL D0003 03 00006 BAEHR, TED E. D0003 01 00025 GUINI, LEN D0022 24 00032 VOUS, RHONDA D0008 23 00041 YONARA, CY D0004 22 00051 DORA, FLORA D0002 13 00054 GATOR, AL E. D0005 07 00056 TYME, JUSTIN D0004 08 00057 CASE, JUSTIN D0004 03 01000 PEARLE E GATES D0001 01 03000 KIT E LITTER D0005 06 02000 LED BALOON D0002 04 04000 MOE PEDD D0504 01 Here is sample JCL: //STEP1 EXEC PGM=VALID1 //STEPLIB DD DSN=your.executable.program.library.goes.here,DISP=SHR //*OF COURSE, THE NEXT LIBRARY NAME MAY BE DIFFERENT AT YOUR COMPANY //EMP1 DD DSN=userid.COBBOOK.DATA(EMP1),DISP=SHR //VALIDFI DD SYSOUT=* //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 |