mercredi 28 janvier 2015

Cobol: Data Validation

I'm trying to code a program to determine if different kinds of errors appear in a given file. I'm going to post my entire code, because I honestly have no idea where I'm going wrong here. It's just abending on me. The data validation is 2100-error-checking.



ENVIRONMENT DIVISION.
* defines the external files - an input file and output file
INPUT-OUTPUT SECTION.
FILE-CONTROL.


SELECT DATVAL02 ASSIGN TO DATAIN
FILE STATUS IS EF-STATUS.

SELECT REPORT-FILE ASSIGN TO DATAOUT
FILE STATUS IS PF-STATUS.

DATA DIVISION.

FILE SECTION.
FD DATVAL02.
01 SALES-RECORD.
05 RECORD-CODE PIC XX.
05 FILLER PIC X.
05 VEND-NUM PIC X(8).
05 YEAR-DUE PIC 99.
05 MONTH-DUE PIC 99.
05 DAY-DUE PIC 99.
05 VEND-NAME PIC X(20).
05 FILLER PIC XXX.
05 AMT-DUE PIC S9(6)V99.

FD REPORT-FILE.
01 REPORT-RECORD PIC X(80).

WORKING-STORAGE SECTION.

01 FLAGS-AND-ACCUMLATORS.
05 VALID-RECORDS PIC S99.
05 INVALID-RECORDS PIC S99.
05 EF-STATUS PIC 99 VALUE 0.
05 PF-STATUS PIC 99 VALUE 0.
05 A-ERROR PIC X VALUE SPACE.
05 C-ERROR PIC X VALUE SPACE.
05 E-ERROR PIC X VALUE SPACE.
05 F-ERROR PIC X VALUE SPACE.
05 B-ERROR PIC X VALUE SPACE.
05 D-ERROR PIC X VALUE SPACE.
05 G-ERROR PIC X VALUE SPACE.
05 H-ERROR PIC X VALUE SPACE.
05 I-ERROR PIC X VALUE SPACE.
05 A-AST PIC XX VALUE SPACES.
05 BC-AST PIC X(8) VALUE SPACES.
05 D-AST PIC XX VALUE SPACES.
05 E-AST PIC XX VALUE SPACES.
05 F-AST PIC XX VALUE SPACES.
05 G-AST PIC X(15) VALUE SPACES.
05 I-AST PIC X(8) VALUE SPACES.
05 END-OF-FILE PIC XXX VALUE "NO".
05 ERROR-FLAG PIC XXX VALUE SPACES.
05 ERROR-FLAG2 PIC XXX VALUE SPACES.
05 VC PIC XX VALUE "VC".
05 NOO PIC XX VALUE "NO".
05 D-CHECK PIC S9999999V99.


01 HEADING-LINE-1.
05 PIC X(15) VALUE SPACES.
05 PIC X(24) VALUE
"VENDOR RECORD VALIDATION".
05 PIC X(24) VALUE SPACES.
05 PIC X(6) VALUE
"PAGE 1".

01 HEADING-LINE-2.
05 PIC XX VALUE
"RC".
05 PIC X VALUE SPACE.
05 PIC X(8) VALUE
"VENDOR #".
05 PIC XX VALUE SPACES.
05 PIC X(8) VALUE
"DATE DUE".
05 PIC XX VALUE SPACES.
05 PIC X(11) VALUE
"VENDOR NAME".
05 PIC X(6) VALUE SPACES.
05 PIC X(10) VALUE
"AMOUNT DUE".
05 PIC XXX VALUE SPACES.
05 PIC X(16) VALUE
"-- ERROR CODES--".

01 DETAIL-LINE.
05 RECORD-CODE-OUT PIC XX.
05 PIC X VALUE SPACE.
05 VEND-NUM-OUT PIC 9(8).
05 PIC XX VALUE SPACES.
05 YEAR-DUE-OUT PIC XX.
05 MONTH-DUE-OUT PIC XX.
05 DAY-DUE-OUT PIC XX.
05 PIC XX VALUE SPACES.
05 VEND-NAME-OUT PIC X(20).
05 PIC XX VALUE SPACES.
05 AMT-DUE-OUT PIC 999,999V99.
05 PIC XX VALUE SPACES.
05 A-ERROR-OUT PIC X.
05 PIC XX VALUE SPACES.
05 B-ERROR-OUT PIC X.
05 PIC XX VALUE SPACES.
05 C-ERROR-OUT PIC X.
05 PIC XX VALUE SPACES.
05 D-ERROR-OUT PIC X.
05 PIC XX VALUE SPACES.
05 E-ERROR-OUT PIC X.
05 PIC XX VALUE SPACES.
05 F-ERROR-OUT PIC X.
05 PIC XX VALUE SPACES.
05 G-ERROR-OUT PIC X.
05 PIC XX VALUE SPACES.
05 H-ERROR-OUT PIC X.
05 PIC XX VALUE SPACES.
05 I-ERROR-OUT PIC X.

01 ASTERISK-LINE.
05 A-AST-OUT PIC XX.
05 PIC X VALUE SPACE.
05 BC-AST-OUT PIC X(8).
05 PIC XX VALUE SPACES.
05 D-AST-OUT PIC XX.
05 PIC X VALUE SPACE.
05 E-AST-OUT PIC XX.
05 PIC X VALUE SPACE.
05 F-AST-OUT PIC XX.
05 PIC XX VALUE SPACES.
05 G-AST-OUT PIC X(15).
05 PIC XX VALUE SPACES.
05 I-AST-OUT PIC X(8).
05 PIC XX VALUE SPACES.
05 H-AST-OUT PIC X(8).

01 RECORD-TOTALS.
05 PIC X(16) VALUE
"VALID RECORDS: ".
05 VALID-RECORDS-OUT PIC 99.
05 PIC XX VALUE SPACES.
05 PIC X(17) VALUE
"INVALID RECORDS: ".
05 INVALID-RECORDS-OUT PIC 99.

PROCEDURE DIVISION.

1000-MAIN-CONTROL.
PERFORM 2000-INITIALIZE.
PERFORM UNTIL END-OF-FILE = "YES"
READ DATVAL02
AT END
MOVE "YES" TO END-OF-FILE
NOT AT END
PERFORM 2100-ERROR-ROUTINE
IF ERROR-FLAG = "YES"
PERFORM 2500-PROCESS
PERFORM 3000-PROCESS
END-IF
IF ERROR-FLAG = "NO"
PERFORM 2500-PROCESS
END-IF
END-PERFORM.
PERFORM 4000-PROCESS.
PERFORM 4500-TERMINATE.
STOP RUN.

2000-INITIALIZE.
OPEN INPUT DATVAL02.
OPEN OUTPUT REPORT-FILE.

WRITE REPORT-RECORD FROM HEADING-LINE-1.
WRITE REPORT-RECORD FROM HEADING-LINE-2.

2100-ERROR-ROUTINE.
MOVE "NO" TO ERROR-FLAG.
MOVE "NO" TO ERROR-FLAG2.

IF VEND-NUM = SPACES
MOVE "YES" TO ERROR-FLAG
MOVE "********" TO BC-AST-OUT
MOVE "B" TO B-ERROR-OUT
END-IF.


IF ERROR-FLAG = "YES"
ADD 1 TO INVALID-RECORDS
END-IF.

IF ERROR-FLAG = "NO"
ADD 1 TO VALID-RECORDS
END-IF.



2500-PROCESS.
MOVE RECORD-CODE TO RECORD-CODE-OUT.
MOVE VEND-NUM TO VEND-NUM-OUT.
MOVE YEAR-DUE TO YEAR-DUE-OUT.
MOVE MONTH-DUE TO MONTH-DUE-OUT.
MOVE DAY-DUE TO DAY-DUE-OUT.
MOVE VEND-NAME TO VEND-NAME-OUT.
MOVE AMT-DUE TO AMT-DUE-OUT.

WRITE REPORT-RECORD FROM DETAIL-LINE.

3000-PROCESS.
WRITE REPORT-RECORD FROM ASTERISK-LINE.

4000-PROCESS.
MOVE VALID-RECORDS TO VALID-RECORDS-OUT.
MOVE INVALID-RECORDS TO INVALID-RECORDS-OUT.
WRITE REPORT-RECORD FROM RECORD-TOTALS.

4500-TERMINATE.
CLOSE DATVAL02, REPORT-FILE.


Data in looks as such...



VC 10045380051005ABC ELECTRONICS 00001298
VT 000000 00020000


Looking to achieve this



XX 9AAA9999 99/99/99 SHIFTED 12A 4GL 78 A C E F H I
** ******** ** ** *************** *** *** **


where * are under error's in the data. And letters show what error's are found. Thanks for your time.


Aucun commentaire:

Enregistrer un commentaire