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.
IDENTIFICATION DIVISION.
PROGRAM-ID. ASSIGNMENT1.
AUTHOR. AARON.
******************************************************************
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 DATE-DUE.
05 YEAR-DUE PIC XX.
05 MONTH-DUE PIC XX.
05 DAY-DUE PIC XX.
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 VALUE 0.
05 INVALID-RECORDS PIC S99 VALUE 0.
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 H-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 ERROR-FILLER PIC XXX VALUE SPACES.
05 VC PIC XX VALUE "VC".
05 NOO PIC XX VALUE "NO".
05 D-CHECK PIC S9999999V99.
05 DAY-DUE-NUM PIC 99.
05 MONTH-DUE-NUM PIC 99.
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 X(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,999.99.
05 PIC XX VALUE SPACES.
05 A-ERROR-OUT PIC X VALUE SPACES.
05 PIC XX VALUE SPACES.
05 B-ERROR-OUT PIC X VALUE SPACE.
05 PIC XX VALUE SPACES.
05 C-ERROR-OUT PIC X VALUE SPACE.
05 PIC XX VALUE SPACES.
05 D-ERROR-OUT PIC X VALUE SPACE.
05 PIC XX VALUE SPACES.
05 E-ERROR-OUT PIC X VALUE SPACE.
05 PIC XX VALUE SPACES.
05 F-ERROR-OUT PIC X VALUE SPACE.
05 PIC XX VALUE SPACES.
05 G-ERROR-OUT PIC X VALUE SPACE.
05 PIC XX VALUE SPACES.
05 H-ERROR-OUT PIC X VALUE SPACE.
05 PIC XX VALUE SPACES.
05 I-ERROR-OUT PIC X VALUE SPACE.
01 ASTERISK-LINE.
05 A-AST-OUT PIC XX VALUE SPACES.
05 PIC X VALUE SPACE.
05 BC-AST-OUT PIC X(8) VALUE SPACES.
05 PIC XX VALUE SPACES.
05 D-AST-OUT PIC XX VALUE SPACES.
05 PIC X VALUE SPACE.
05 E-AST-OUT PIC XX VALUE SPACES.
05 PIC X VALUE SPACE.
05 F-AST-OUT PIC XX VALUE SPACES.
05 PIC XX VALUE SPACES.
05 G-AST-OUT PIC X(15) VALUE SPACES.
05 PIC XX VALUE SPACES.
05 I-AST-OUT PIC X(8) VALUE SPACES.
05 PIC XX VALUE SPACES.
05 H-AST-OUT PIC X(8) VALUE SPACES.
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
PERFORM 4200-REINITILIZE
END-IF
IF ERROR-FLAG = "NO"
PERFORM 2500-PROCESS
END-IF
END-READ
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 VEND-NUM IS NOT NUMERIC AND ERROR-FLAG = NOO
MOVE "YES" TO ERROR-FLAG
MOVE "********" TO BC-AST-OUT
MOVE "C" TO C-ERROR-OUT
END-IF.
IF RECORD-CODE IS NOT = VC
MOVE "YES" TO ERROR-FLAG
MOVE "**" TO A-AST-OUT
MOVE "A" TO A-ERROR-OUT
END-IF.
IF DATE-DUE IS NOT NUMERIC
MOVE "YES" TO ERROR-FLAG2
MOVE "YES" TO ERROR-FLAG
MOVE "**" TO D-AST-OUT
MOVE "D" TO D-ERROR-OUT
MOVE "**" TO E-AST-OUT
MOVE "**" TO F-AST-OUT
END-IF.
IF DATE-DUE = 0 AND ERROR-FLAG2 = NOO
IF AMT-DUE IS > 0
MOVE "YES" TO ERROR-FLAG
MOVE "YES" TO ERROR-FLAG2
MOVE "**" TO D-AST-OUT
MOVE "D" TO D-ERROR-OUT
MOVE "**" TO E-AST-OUT
MOVE "**" TO F-AST-OUT
END-IF
END-IF.
MOVE DAY-DUE TO DAY-DUE-NUM.
MOVE MONTH-DUE TO MONTH-DUE-NUM.
IF DAY-DUE-NUM > 31 OR DAY-DUE < 0 AND ERROR-FLAG2 = NOO
MOVE "YES" TO ERROR-FLAG
MOVE "**" TO E-AST-OUT
MOVE "E" TO E-ERROR-OUT
END-IF.
IF MONTH-DUE-NUM > 12 OR < 1 AND ERROR-FLAG2 = NOO
MOVE "YES" TO ERROR-FLAG
MOVE "**" TO F-AST-OUT
MOVE "F" TO F-ERROR-OUT
END-IF.
IF VEND-NAME = SPACES
MOVE "YES" TO ERROR-FLAG
MOVE "***************" TO G-AST-OUT
MOVE "G" TO G-ERROR-OUT
END-IF.
IF VEND-NAME(1:1) IS EQUAL TO SPACE
MOVE "YES" TO ERROR-FLAG
MOVE "***************" TO H-AST-OUT
MOVE "H" TO H-ERROR-OUT
IF AMT-DUE IS NOT NUMERIC
MOVE "YES" TO ERROR-FLAG
MOVE "********" TO I-AST-OUT
MOVE "I" TO I-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.
4200-REINITILIZE.
MOVE A-ERROR TO A-ERROR-OUT.
MOVE B-ERROR TO B-ERROR-OUT.
MOVE C-ERROR TO C-ERROR-OUT.
MOVE D-ERROR TO D-ERROR-OUT.
MOVE E-ERROR TO E-ERROR-OUT.
MOVE F-ERROR TO F-ERROR-OUT.
MOVE G-ERROR TO G-ERROR-OUT.
MOVE H-ERROR TO H-ERROR-OUT.
MOVE I-ERROR TO I-ERROR-OUT.
MOVE A-AST TO A-AST-OUT.
MOVE BC-AST TO BC-AST-OUT.
MOVE D-AST TO D-AST-OUT.
MOVE E-AST TO E-AST-OUT.
MOVE F-AST TO F-AST-OUT.
MOVE G-AST TO G-AST-OUT.
MOVE H-AST TO H-AST-OUT.
MOVE I-AST TO I-AST-OUT.
MOVE ERROR-FILLER TO ERROR-FLAG.
MOVE ERROR-FILLER TO ERROR-FLAG2.
MOVE A-AST TO DAY-DUE-NUM.
MOVE A-AST TO MONTH-DUE-NUM.
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 errors in the data. And letters show what errors are found.
In your latest version, you have made a group item (DATE-DUE) but you have not adjusted the level-numbers for the other date fields which are subordinate to it. I have made those three level 10. To use SYSIN data to be convenient for me, I added a 32-byte FILLER to the end of the input record.
I compile, gets an RC/CC of 4, so the linkedit/binder runs.
I used this data from your other question:
VC 10045380051005ABC ELECTRONICS 00001298
VC 050926XYZ COMPANY 00R00549
VT 12348760051115QUALITY ASSURANCE CO 00400053
VC A14BCF80051201 00100930
And got this output, with no abend:
VENDOR RECORD VALIDATION PAGE 1
RC VENDOR # DATE DUE VENDOR NAME AMOUNT DUE -- ERROR CODES--
VC 10045380 051005 ABC ELECTRONICS 000,012.98
VC 050926 XYZ COMPANY 009,005.49 B
********
VT 12348760 051115 QUALITY ASSURANCE CO 004,000.53 A
**
VC A14BCF80 051201 001,009.30 C G H
******** *************** ********
VALID RECORDS: 01 INVALID RECORDS: 03
I have pasted the data from your other question.
Note, if your actual data is incorrect, you may get an abend with the amount field.
Note also what has happened to the R in the amount field. You haven't validated that for NUMERIC.
I have now compiled and run your program with the two corrections (the VALUE clauses for the two counts, and the END-READ). Here is the output:
VENDOR RECORD VALIDATION PAGE 1
RC VENDOR # DATE DUE VENDOR NAME AMOUNT DUE -- ERROR CODES--
VC 10045380 051005 ABC ELECTRONICS 000,01298
VT 0 000000 000,20000 B
********
VALID RECORDS: 01 INVALID RECORDS: 01
I used a fixed-length file, as I don't have access to your actual file, which must be variable-length (it is good to be explicit in the FD, then you don't get those I-informational messages at the end of your compile).
You still have some things to sort out, but the program is running and producing output. If you make those code changes and still have problems, then it is your file that is in error.
You have a very frustrating problem which seems to be down to the "environment". You need to be able to see your compile listings. If the compile fails (RC/CC above 4) then your linkedit/binder step won't run, and you won't get a new executable program. I think that is your problem, but you need help from your tutor to sort out how to find the compile listing and confirm that there are no errors.
I have not used Rational Developer and don't know if you are using zPDT or are compiling on the Mainframe or how you'd look at the compiler output in either case from your Rational Developer session.
Your code is basically OK for a learner, and probably has been for a couple of days. You have been struggling with a problem not directly to do with the code, but to do with not knowing your program had compile errors. Basically, except for a couple of typos, it was there.
When you do get it running in your environment, update your Code Review question please.
A really good thing to know is what compile produced the version of the program that you ran, whether or not it abended.
You can display the date and time that the program was compiled:
WORKING-STORAGE SECTION.
01 W-WHEN-COMPILED PIC X(8)BX(8).
...
Before doing anything else, other than identifying that it is the first time in a CALLed sub-program, something like this:
MOVE WHEN-COMPILED TO W-WHEN-COMPILED
DISPLAY
"Program XXXXXXXX compiled on "
W-WHEN-COMPILED
The output you get will be the date/time from the actual compile of that program, matching exactly to the date/time on the compile listing.
I've used code like that, and recommended it to others, for over 30 years, and it has saved shed-loads of time.
There is also an intrinsic FUNCTION, WHEN-COMPILED. This is the same, but with a four-digit year. Since for the forseeable future the CC in the year will be 20 you can chose which one to do. Both are resolved at compile-time, and impact on run-time will be minimal.
You have no END-READ. This gives you an E-level diagnostic from the compile, a Return-Code/Condition-Code of 8, and you linkedit/binder step following probably hasn't run (have a look at the COND for the step in file 2 of the spool for your job).
Here is your code as a reminder:
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.
Here is what it could look like with the END-READ:
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-READ
END-PERFORM
Since no new program has been linked, you are running the old program still and getting the old error still.
You are adding to non-binary fields which you have not given an initial value.
05 VALID-RECORDS PIC S99.
05 INVALID-RECORDS PIC S99.
IF ERROR-FLAG = "YES"
ADD 1 TO INVALID-RECORDS
END-IF.
IF ERROR-FLAG = "NO"
ADD 1 TO VALID-RECORDS
END-IF.
Without an initial value (either from a VALUE clause, or a MOVE or even the dread INITIALIZE), the value is undefined and is unlikely to be valid for a zoned-decimal field, so S0C7.
Have a look at this: https://stackoverflow.com/a/17102485/1927206 to see if you can work out from that exactly where it is failing in your program.
Program which compiles clean, with RC 0 and no diagnostic messages, and runs without abend:
ID DIVISION.
PROGRAM-ID. VARA.
ENVIRONMENT DIVISION.
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 RECORDING MODE F.
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.
05 FILLER PIC X(32).
FD REPORT-FILE RECORDING MODE F.
01 REPORT-RECORD PIC X(80).
WORKING-STORAGE SECTION.
01 W-WHEN-COMPILED PIC X(8)BX(8).
01 FLAGS-AND-ACCUMLATORS.
05 VALID-RECORDS PIC S99 VALUE ZERO.
05 INVALID-RECORDS PIC S99 VALUE ZERO.
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,999.99.
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.
MOVE WHEN-COMPILED TO W-WHEN-COMPILED
DISPLAY
"TEST PROGRAM COMPILED ON "
W-WHEN-COMPILED
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-READ
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.
Related
I have a program that works perfectly except when reading in the SEQ file it is suppose to skip/bypass the record entirely then move on to the next one in the file. It is suppose to bypass the input file if the student has graduated (skip Graduation Status if equal to 'Y'). Bypass if Class Standing is anything other than '1' or '2'. Lastly, bypass if Major is not 'DIG', 'NES', or 'PGM'. I have a Bypass in the program under 120-CHECK-BYPASS. but it is not sorting/stopping any records from processing. How do I fix this?
Program:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT STUDENTS-FILE-IN
ASSIGN TO 'STUDENTS.SEQ'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT STUDENTS-FILE-OUT
ASSIGN TO 'STUDENTS.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD STUDENTS-FILE-IN.
01 STUDENTS-RECORD-IN.
05 SOCIAL-SECURITY-NUMBER-FIRST-IN PIC X(3).
05 SOCIAL-SECURITY-NUMBER-MIDDLE-IN PIC X(2).
05 SOCIAL-SECURITY-NUMBER-LAST-IN PIC X(4).
05 STUDENT-NAME-FIRST-IN PIC X.
05 STUDENT-NAME-MIDDLE-IN PIC X.
05 STUDENT-NAME-LAST-IN PIC X(9).
05 PIC X(5).
05 GRADUATION-STATUS-IN PIC X.
05 CLASS-STANDING-IN PIC X.
05 MAJOR-IN PIC X(3).
05 CREDIT-HOURS-EARNED-IN PIC 9(3).
05 CREDIT-POINTS-EARNED-IN PIC 9(3).
FD STUDENTS-FILE-OUT.
01 STUDENTS-RECORD-OUT PIC X(80).
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
01 LINES-PRINTED PIC 99 VALUE 99.
01 PAGE-NUMBER PIC 99 VALUE ZERO.
01 WS-FIRST-TIME-THRU PIC X(3) VALUE 'YES'.
01 WS-GPA PIC Z.ZZ VALUE ZERO.
01 WS-GRAND-HOURS PIC 9(7) VALUE ZERO.
01 WS-GRAND-POINTS PIC 9(7) VALUE ZERO.
01 WS-GRAND-GPA PIC Z.ZZ VALUE ZERO.
01 WS-PRO-STUDENT PIC 9(2) VALUE ZERO.
01 WS-GRAND-PRO-STUDENT PIC 99V9 VALUE ZERO.
01 WS-PRO-GPA-NUM PIC 99 VALUE ZERO.
01 WS-DIG-STUDENT PIC 99 VALUE ZERO.
01 WS-DIG-GPA-NUM PIC 99 VALUE ZERO.
01 WS-GRAND-DIG-STUDENT PIC 99V9 VALUE ZERO.
01 WS-GRAND-NES-STUDENT PIC 99V9 VALUE ZERO.
01 WS-NES-STUDENT PIC 99 VALUE ZERO.
01 WS-NES-GPA-NUM PIC 99 VALUE ZERO.
01 WS-OTHER PIC 99 VALUE ZERO.
01 WS-CURRENT-DATE-DATA.
05 WS-CURRENT-DATE.
10 RUN-YEAR PIC XX.
10 RUN-MONTH PIC XX.
10 RUN-DAY PIC XX.
01 HEADING-LINE-1.
05 PIC X(22) VALUE SPACES.
05 PIC X(33) VALUE '------ ----- ------- ----- ------'.
05 PIC X(6) VALUE SPACES.
05 HL-1-DATE.
10 MONTH-2 PIC XX.
10 PIC X VALUE'/'.
10 DAY-2 PIC XX.
10 PIC X VALUE'/'.
10 YEAR-2 PIC XX.
05 PIC X(4) VALUE SPACES.
05 PIC X(4) VALUE 'PAGE'.
05 HL-1-PAGE-NUMBER PIC Z9.
01 HEADING-LINE-2.
05 PIC X VALUE SPACE.
05 PIC X(10) VALUE 'SOC SEC NO'.
05 PIC X(4) VALUE SPACES.
05 PIC X(12) VALUE 'STUDENT NAME'.
05 PIC X(3) VALUE SPACES.
05 PIC X(8) VALUE 'STANDING'.
05 PIC X(4) VALUE SPACES.
05 PIC X(5) VALUE 'MAJOR'.
05 PIC X(10) VALUE SPACES.
05 PIC X(5) VALUE 'HOURS'.
05 PIC X(2) VALUE SPACES.
05 PIC X(6) VALUE 'POINTS'.
05 PIC X(5) VALUE SPACES.
05 PIC X(3) VALUE 'GPA'.
01 DETAIL-LINE.
05 PIC X VALUE SPACE.
05 SOCIAL-SECURITY-NUMBER-FIRST-OUT PIC X(3).
05 SSN-FDASH PIC X VALUE "-".
05 SOCIAL-SECURITY-NUMBER-MIDDLE-OUT PIC X(2).
05 SSN-MDASH PIC X VALUE "-".
05 SOCIAL-SECURITY-NUMBER-LAST-OUT PIC X(4).
05 PIC X(3) VALUE SPACES.
05 STUDENT-NAME-FIRST-OUT PIC X.
05 PIC X VALUE SPACE.
05 STUDENT-NAME-MIDDLE-OUT PIC X.
05 PIC X VALUE SPACE.
05 STUDENT-NAME-LAST-OUT PIC X(9).
05 PIC X(2) VALUE SPACES.
05 CLASS-STANDING-OUT PIC X(9).
05 PIC X(3) VALUE SPACES.
05 MAJOR-OUT PIC X(13).
05 PIC X(4) VALUE SPACES.
05 HOURS-OUT PIC ZZZ.
05 PIC X(5) VALUE SPACES.
05 POINTS-OUT PIC ZZZ.
05 PIC X(4) VALUE SPACES.
05 STUDENT-GPA-OUT PIC 9.99.
01 TOTALS-LINE.
05 PIC X VALUE SPACE.
05 PIC X(6) VALUE 'Totals'.
05 PIC X(50) VALUE SPACES.
05 TL-GRAND-HOURS PIC Z,ZZZ.
05 PIC X(2) VALUE SPACES.
05 TL-GRAND-POINTS PIC ZZ,ZZZ.
05 PIC X(4) VALUE SPACES.
05 TL-GRAND-GPA PIC 9.99.
01 TOTALS-LINE-2A.
05 PIC X VALUE SPACE.
05 PIC X(19) VALUE 'Programming Majors:'.
01 TOTALS-LINE-2B.
05 PIC X(5) VALUE SPACES.
05 PIC X(18) VALUE 'Number of students'.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-PRO-STUDENT PIC X(2).
01 TOTALS-LINE-2C.
05 PIC X(5) VALUE SPACES.
05 PIC X(21) VALUE 'Number with GPA > 3.0'.
05 PIC X(6) VALUE SPACES.
05 TL-GRAND-PRO-NUM-GPA PIC X(2).
01 TOTALS-LINE-2D.
05 PIC X(5) VALUE SPACES.
05 PIC X(22) VALUE 'Percent with GPA > 3.0'.
05 PIC X(5) VALUE SPACES.
05 TL-GRAND-PRO-GPA-PER PIC 99.9.
05 PIC X VALUE '%'.
01 TOTALS-LINE-3A.
05 PIC X VALUE SPACE.
05 PIC X(21) VALUE 'Digital Media Major:'.
01 TOTALS-LINE-3B.
05 PIC X(5) VALUE SPACES.
05 PIC X(18) VALUE 'Number of students'.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-DIG-STUDENT PIC X(2).
01 TOTALS-LINE-3C.
05 PIC X(5) VALUE SPACES.
05 PIC X(21) VALUE 'Number with GPA > 3.0'.
05 PIC X(6) VALUE SPACES.
05 TL-GRAND-DIG-NUM-GPA PIC XX.
01 TOTALS-LINE-3D.
05 PIC X(5) VALUE SPACES.
05 PIC X(22) VALUE 'Percent with GPA > 3.0'.
05 PIC X(5) VALUE SPACES.
05 TL-GRAND-DIG-GPA-PER PIC 99.9.
05 PIC X VALUE '%'.
01 TOTALS-LINE-4A.
05 PIC X VALUE SPACE.
05 PIC X(24) VALUE 'Network Security Major:'.
01 TOTALS-LINE-4B.
05 PIC X(5) VALUE SPACES.
05 PIC X(18) VALUE 'Number of students'.
05 PIC X(9) VALUE SPACES.
05 TL-GRAND-NET-STUDENT PIC X(2).
01 TOTALS-LINE-4C.
05 PIC X(5) VALUE SPACES.
05 PIC X(21) VALUE 'Number with GPA > 3.0'.
05 PIC X(6) VALUE SPACES.
05 TL-GRAND-NET-NUM-GPA PIC XX.
01 TOTALS-LINE-4D.
05 PIC X(5) VALUE SPACES.
05 PIC X(22) VALUE 'Percent with GPA > 3.0'.
05 PIC X(5) VALUE SPACES.
05 TL-GRAND-NET-GPA-PER PIC ZZ.9.
05 PIC X VALUE '%'.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT STUDENTS-FILE-IN
OPEN OUTPUT STUDENTS-FILE-OUT
ACCEPT WS-CURRENT-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-2
MOVE RUN-DAY TO DAY-2
MOVE RUN-YEAR TO YEAR-2
PERFORM 300-WRITE-HEADINGS
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO'
READ STUDENTS-FILE-IN
AT END
PERFORM 400-TOTALS-ROUTINE
PERFORM 700-GRAND-TOTALS-PROGRAMMING
PERFORM 800-PRO-GPA
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 120-CHECK-BYPASS
END-READ
END-PERFORM
CLOSE STUDENTS-FILE-IN
CLOSE STUDENTS-FILE-OUT
STOP RUN.
120-CHECK-BYPASS.
IF GRADUATION-STATUS-IN NOT EQUAL TO 'Y'
AND CLASS-STANDING-IN EQUAL TO '1' OR '2'
AND MAJOR-IN IS EQUAL TO 'DIG' OR 'NES' OR 'PGM'
PERFORM 200-PROCESS-ONE-RECORD
ELSE CONTINUE
END-IF.
200-PROCESS-ONE-RECORD.
IF LINES-PRINTED > 57
PERFORM 300-WRITE-HEADINGS
END-IF
PERFORM 725-PRO-STUDENT-NUM
COMPUTE WS-GPA ROUNDED = CREDIT-POINTS-EARNED-IN / CREDIT-HOURS-EARNED-IN
MOVE SOCIAL-SECURITY-NUMBER-FIRST-IN TO SOCIAL-SECURITY-NUMBER-FIRST-OUT
MOVE SOCIAL-SECURITY-NUMBER-MIDDLE-IN TO SOCIAL-SECURITY-NUMBER-MIDDLE-OUT
MOVE SOCIAL-SECURITY-NUMBER-LAST-IN TO SOCIAL-SECURITY-NUMBER-LAST-OUT
MOVE STUDENT-NAME-FIRST-IN TO STUDENT-NAME-FIRST-OUT
MOVE STUDENT-NAME-MIDDLE-IN TO STUDENT-NAME-MIDDLE-OUT
MOVE STUDENT-NAME-LAST-IN TO STUDENT-NAME-LAST-OUT
MOVE CLASS-STANDING-IN TO CLASS-STANDING-OUT
PERFORM 600-YEAR-PRINT
MOVE MAJOR-IN TO MAJOR-OUT
PERFORM 500-MAJOR-PRINT
MOVE CREDIT-HOURS-EARNED-IN TO HOURS-OUT
MOVE CREDIT-POINTS-EARNED-IN TO POINTS-OUT
MOVE WS-GPA TO STUDENT-GPA-OUT
MOVE DETAIL-LINE TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINES
ADD 2 TO LINES-PRINTED
COMPUTE WS-GRAND-HOURS = WS-GRAND-HOURS + CREDIT-HOURS-EARNED-IN
COMPUTE WS-GRAND-POINTS = WS-GRAND-POINTS + CREDIT-POINTS-EARNED-IN
COMPUTE WS-GRAND-GPA ROUNDED = WS-GRAND-POINTS / WS-GRAND-HOURS
PERFORM 800-PRO-GPA.
300-WRITE-HEADINGS.
ADD 1 TO PAGE-NUMBER
MOVE PAGE-NUMBER TO HL-1-PAGE-NUMBER
MOVE HEADING-LINE-1 TO STUDENTS-RECORD-OUT
IF WS-FIRST-TIME-THRU = 'YES'
WRITE STUDENTS-RECORD-OUT
MOVE 'NO' TO WS-FIRST-TIME-THRU
ELSE
WRITE STUDENTS-RECORD-OUT AFTER ADVANCING PAGE
END-IF
MOVE HEADING-LINE-2 TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 2
MOVE 3 TO LINES-PRINTED.
400-TOTALS-ROUTINE.
IF LINES-PRINTED > 57
PERFORM 300-WRITE-HEADINGS
END-IF
MOVE WS-GRAND-HOURS TO TL-GRAND-HOURS
MOVE WS-GRAND-POINTS TO TL-GRAND-POINTS
MOVE WS-GRAND-GPA TO TL-GRAND-GPA
MOVE TOTALS-LINE TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT AFTER ADVANCING 2 LINES
ADD 2 TO LINES-PRINTED.
500-MAJOR-PRINT.
EVALUATE MAJOR-OUT
WHEN = 'NES'
MOVE 'Net Security' TO MAJOR-OUT
WHEN = 'PGM'
MOVE 'Programming' TO MAJOR-OUT
WHEN = 'DIG'
MOVE 'Digital Media' TO MAJOR-OUT
WHEN OTHER
MOVE '------' TO MAJOR-OUT
END-EVALUATE.
600-YEAR-PRINT.
EVALUATE CLASS-STANDING-OUT
WHEN = '1'
MOVE 'First Yr' TO CLASS-STANDING-OUT
WHEN = '2'
MOVE 'Second Yr' TO CLASS-STANDING-OUT
WHEN OTHER
MOVE '------' TO CLASS-STANDING-OUT
END-EVALUATE.
700-GRAND-TOTALS-PROGRAMMING.
MOVE TOTALS-LINE-2A TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 4 LINES
MOVE WS-PRO-STUDENT TO TL-GRAND-PRO-STUDENT
MOVE TOTALS-LINE-2B TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE WS-PRO-GPA-NUM TO TL-GRAND-PRO-NUM-GPA
MOVE TOTALS-LINE-2C TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
COMPUTE WS-GRAND-PRO-STUDENT = (WS-PRO-GPA-NUM / WS-PRO-STUDENT) * 100
MOVE WS-GRAND-PRO-STUDENT TO TL-GRAND-PRO-GPA-PER
MOVE TOTALS-LINE-2D TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE TOTALS-LINE-3A TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 2 LINES
MOVE WS-DIG-STUDENT TO TL-GRAND-DIG-STUDENT
MOVE TOTALS-LINE-3B TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE WS-DIG-GPA-NUM TO TL-GRAND-DIG-NUM-GPA
MOVE TOTALS-LINE-3C TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
COMPUTE WS-GRAND-DIG-STUDENT = (WS-DIG-GPA-NUM / WS-DIG-STUDENT) * 100
MOVE WS-GRAND-DIG-STUDENT TO TL-GRAND-DIG-GPA-PER
MOVE TOTALS-LINE-3D TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE TOTALS-LINE-4A TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 2 LINES
MOVE WS-NES-STUDENT TO TL-GRAND-NET-STUDENT
MOVE TOTALS-LINE-4B TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
MOVE WS-NES-GPA-NUM TO TL-GRAND-NET-NUM-GPA
MOVE TOTALS-LINE-4C TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE
COMPUTE WS-GRAND-NES-STUDENT = (WS-NES-GPA-NUM / WS-NES-STUDENT) * 100
MOVE WS-GRAND-NES-STUDENT TO TL-GRAND-NET-GPA-PER
MOVE TOTALS-LINE-4D TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINE.
725-PRO-STUDENT-NUM.
EVALUATE MAJOR-IN
WHEN = 'NES'
ADD 1 TO WS-NES-STUDENT
WHEN = 'PGM'
ADD 1 TO WS-PRO-STUDENT
WHEN = 'DIG'
ADD 1 TO WS-DIG-STUDENT
WHEN OTHER
MOVE 0 TO WS-OTHER
END-EVALUATE.
800-PRO-GPA.
EVALUATE MAJOR-IN ALSO STUDENT-GPA-OUT
WHEN = 'NES' ALSO > '3.0'
ADD 1 TO WS-NES-GPA-NUM
WHEN = 'PGM' ALSO > '3.0'
ADD 1 TO WS-PRO-GPA-NUM
WHEN = 'DIG' ALSO > '3.0'
ADD 1 TO WS-DIG-GPA-NUM
WHEN OTHER
MOVE 0 TO WS-OTHER
END-EVALUATE.
You are ANDing your conditions. It seems you want to OR them. Also it seems you have your logic reversed.
I would do it this way...
[...]
FD STUDENTS-FILE-IN.
01 STUDENTS-RECORD-IN.
05 SOCIAL-SECURITY-NUMBER-FIRST-IN PIC X(3).
05 SOCIAL-SECURITY-NUMBER-MIDDLE-IN PIC X(2).
05 SOCIAL-SECURITY-NUMBER-LAST-IN PIC X(4).
05 STUDENT-NAME-FIRST-IN PIC X.
05 STUDENT-NAME-MIDDLE-IN PIC X.
05 STUDENT-NAME-LAST-IN PIC X(9).
05 PIC X(5).
05 GRADUATION-STATUS-IN PIC X.
88 STUDENT-HAS-GRADUATED VALUE 'Y'
05 CLASS-STANDING-IN PIC X.
88 CLASS-STANDING-TO-SKIP VALUES '1' '2'.
05 MAJOR-IN PIC X(3).
88 MAJOR-TO-SKIP VALUES
'DIG' 'NES' 'PGM'.
05 CREDIT-HOURS-EARNED-IN PIC 9(3).
05 CREDIT-POINTS-EARNED-IN PIC 9(3).
[...]
120-CHECK-BYPASS.
IF STUDENT-HAS-GRADUATED
OR CLASS-STANDING-TO-SKIP
OR MAJOR-TO-SKIP
CONTINUE
ELSE
PERFORM 200-PROCESS-ONE-RECORD
END-IF.
This is just freehand, I haven't tried to compile it.
I am still new to COBOL and have been working on a project for school for almost a week now. I am running OpenCobol 1.1.
When I try to compile it I get this error.
typeck.c:5912: Invalid type cast from 'null'
Tag 1 0 Tag 2 10
Aborting compile of lab4.cob at line 214
I've been frustrated because I've tried changing the code around a lot with no luck.
Procedure Division.
000-Main.
Perform 100-initialize
Perform Until EndOfFile = "Y"
Read Lab4-in-File
At End
Move "Y" To EndOfFile
Not At End
Perform 300-process
End-Read
End-Perform
Perform 900-finalize
Stop Run.
100-intialize.
Perform 110-open-files
Perform 120-get-data.
110-open-files.
Open Input Lab4-in-File
Output Ot-File.
120-get-date.
Accept WS-date from date yyyymmdd
Move WS-Year To PH-Year
Move WS-Month To PH-Month
Move WS-Day To PH-Day.
300-process.
Move Dept-no To dl-dep-no
Move Employee-no To dl-emp-no
If First-name Not = "Null"
String First-name Delimited By Size
" " Delimited By Size
Last-name Delimited By Size
Into dl-emp
else
Move Last-name To dl-emp
End-If
Move Job-title To dl-job
Move DOH To dl-doh
Move Mar-status To dl-marital
Move Dependents To dl-dependents
Move MCoverage To dl-insurance
Move DCoverage To dl-insurance
Move VCoverage To dl-insurance
Move 401K To dl-401k
Move Pay-code To dl-pay-code
If Pay-code = "C" Or "S"
Compute Pay-hold rounded =
Pay / 12
Move Pay-hold To dl-monthly-pay
else
Compute Pay-hold rounded =
Pay * HPW * 4
Move Pay-hold To dl-monthly-pay
End-If
If Pay-code = "C"
Compute Com-hold rounded =
Act-sale * C-rate
Move Com-hold To dl-commission
Else
Move 0 To dl-commission
End-If
Perform 800-print
Multiply C-rate By Act-sale Giving
total-sales
Add Pay To total-sales.
800-print.
If LineNum > LinesPerPage
Perform 825-new-page
End-If
Write Lab4-Record2 From Detail-Line
**After advancing 1 line** *> This is line 214
Add 1 To LineNum.
825-new-page.
If PageNum > 0
Write Lab4-Record2 From Blank-line
After advancing 1 line
End-If
Add 1 To PageNum
Move PageNum To PH-PageNo
Write Lab4-Record2 From Page-Header
After advancing page
Write Lab4-Record2 From Blank-line
After advancing 1 line
Write Lab4-Record2 From Column-Header
After advancing 1 line
Write Lab4-Record2 From Blank-line
After advancing 1 line
Move 5 To LineNum.
900-finalize.
Perform 950-print-monthly-total
Perform 999-close-files.
950-print-monthly-total.
If LineNum + 1 > LinesPerPage
Perform 825-new-page
End-If
Write Lab4-Record2 From Blank-line
After advancing 1 line
Move total-sales To Total-pay
Write Lab4-Record2 From Total-Line
After advancing 1 line
Add 2 To LineNum.
999-close-files.
Close Lab4-in-File Ot-File.
I would really appreciate it if someone could help me find what is causing the error. Thanks in advance!
Working-Storage Section.
01 EndOfFile Pic X Value "N".
01 Report-fields.
05 PageNum Pic 9(3) value 0.
05 LinesPerPage Pic 9(2) value 40.
05 LineNum Pic 9(2) value 41.
01 WS-date.
05 WS-Year Pic 9(4).
05 WS-Month Pic 99.
05 WS-Day Pic 99.
01 total-fields.
05 total-sales Pic 9(11)v99 Value 0.
01 Page-Header.
05 PH-Month Pic Z9/.
05 PH-Day Pic 99/.
05 PH-Year Pic 9999.
05 Pic X(7) Value Spaces.
05 Pic X(29) Value "Stomper &" &
" Wombat's Emporium"
05 Pic X(6) Value "Page:".
05 PH-PageNo Pic ZZ9.
01 Column-Header.
05 Pic X(8) Value "Dep #".
05 Pic X(15) Value "Emp #".
05 Pic X(27) Value "Employee".
05 Pic X(18) Value "Title".
05 Pic X(9) Value "DOH".
05 Pic X(9) Value "Marital".
05 Pic X(7) Value "#Deps".
05 Pic X(6) Value "Ins".
05 Pic X(6) Value "401K".
05 Pic X(6) Value "Pay".
05 Pic X(27) Value "Expected " &
"Pay + Commission".
01 Pay-hold Pic 9(9)V9(2) Value 0.
01 Com-hold Pic 9(9)V9(2) Value 0.
01 Detail-Line.
05 dl-dep-no Pic X(5).
05 Pic X(1) Value spaces.
05 dl-emp-no Pic X(5).
05 Pic X(1) Value spaces.
05 dl-emp Pic X(35).
05 Pic X(1) Value spaces.
05 dl-job Pic X(20).
05 Pic X(1) Value spaces.
05 dl-doh Pic X(8).
05 Pic X(1) Value spaces.
05 dl-marital Pic X.
05 Pic X(1) Value spaces.
05 dl-dependents Pic 9(2).
05 Pic X(1) Value spaces.
05 dl-insurance Pic X(3).
05 Pic X(1) Value spaces.
05 dl-401k Pic Z.9ZZ.
05 Pic X(1) Value spaces.
05 dl-pay-code Pic X.
05 Pic X(1) Value spaces.
05 dl-monthly-pay Pic $$$$,$$$,$$9.99.
05 Pic X(1) Value spaces.
05 dl-commission Pic $$$,$$9.99.
01 Total-Line.
05 Pic X(61) Value Spaces.
05 Pic X(24) Value "Total" &
" Expected Payroll: ".
05 Total-pay Pic $$$$,$$$,$$$,$$9.99.
01 Blank-line Pic X Value spaces.
The compiler has a broken parser. It is broken because of a coding error (still a compiler bug). In cases like this you only have the chance to either spot the error or - much better - use a newer version.
I've just put your code in an online compiler using the last release of the compiler: GnuCOBOL 2.2. I highly suggest to upgrade to at least this version.
See your code here - I've just added a minimal header and end.
Then click on "Execute" and you compile it online, leading to the following error messages:
main.cobc: 27: error: duplicate PICTURE clause
main.cobc: 27: error: duplicate VALUE clause
main.cobc: 64: error: a Z or * which is after the decimal point cannot follow 9
If you check the line 27 in this program you see
05 Pic X(29) Value "Stomper &" &
" Wombat's Emporium" *> <<- missing period
05 Pic X(6) Value "Page:".
Fixed code is also available.
I am getting errors concerning my procedure division in one of my assignments for class. It is a COBOL Program that is supposed to keep a running total of the average height and weight of applicants, number of brown-eyed applicants, number of male applicants, and number of female applicants. Also the program is supposed to print the info of applicants who meet a specific set of requirements but i'm getting errors for almost all of my perform statements
COBCH0034 Operand operand should be numeric
A numeric value is required in this context, and you have specified a nonnumeric value.
COBCH0014 Invalid operand
The operand you have specified is in some way incorrect, and cannot be processed by your COBOL system. For example, you might have specified a negative integer where only positive integers are allowed
identification division.
program-id. ELECTRA-MODELING-AGENCY.
******************************************************************
*THIS PROGRAM PRODUCES THE REPORT ACCORDING TO THE GIVEN PRINTER
*SPACING CHART *
******************************************************************
environment division.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO "INFILE.txt"
Organization is line sequential.
SELECT OUTPUT-FILE ASSIGN TO "CHOSEN-APLICANTS.TXT"
Organization is line sequential.
data division.
FILE SECTION.
FD INPUT-FILE.
01 INPUT-REC.
05 APPLICANTS-NAME PIC X(20).
05 APPLICANTS-WEIGHT PIC 9(3).
05 APPLICANTS-HEIGHT PIC 9(2).
05 APPLICANTS-EYE-CODE PIC X.
05 APPLICANTS-HAIR-CODE PIC X.
05 APPLICANTS-GENDER PIC X.
FD OUTPUT-FILE.
01 OUTPUT-REC PIC X(78).
WORKING-STORAGE SECTION.
01 EOF PIC X VALUE "N".
01 HEADING-1.
05 FILLER PIC X(41) VALUE "M"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "O"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "D"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "E"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "L"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "R"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "E"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "P"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "O"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "R"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "T"
JUSTIFIED RIGHT.
05 FILLER PIC X(16) VALUE SPACES.
01 HEADING-2.
05 FILLER PIC X(23) VALUE "NAME"
JUSTIFIED RIGHT.
05 FILLER PIC X(13) VALUE "SEX"
JUSTIFIED RIGHT.
05 FILLER PIC X(10) VALUE "WEIGHT"
JUSTIFIED RIGHT.
05 FILLER PIC X(8) VALUE "HEIGHT"
JUSTIFIED RIGHT.
05 FILLER PIC X(5) VALUE "EYE"
JUSTIFIED RIGHT.
05 FILLER PIC X(6) VALUE "COLOR"
JUSTIFIED RIGHT.
05 FILLER PIC X(6) VALUE "HAIR"
JUSTIFIED RIGHT.
05 FILLER PIC X(6) VALUE "COLOR"
JUSTIFIED RIGHT.
05 FILLER PIC X VALUE SPACES.
01 DETAIL-LINE.
05 FILLER PIC X(10) VALUE SPACES.
05 NAME-OUT PIC X(20).
05 FILLER PIC X(4) VALUE SPACES.
05 GENDER-OUT PIC X.
05 FILLER PIC X(6) VALUE SPACES.
05 WEIGHT-OUT PIC X(3).
05 FILLER PIC X(6) VALUE SPACES.
05 HEIGHT-OUT PIC XX.
05 FILLER PIC X(6) VALUE SPACES.
05 EYE-COLOR-OUT PIC X(5).
05 FILLER PIC X(6) VALUE SPACES.
05 HAIR-COLOR-OUT PIC X(6).
01 SUMMARY-LINE-01
05 FILLER PIC X(17) VALUE "AVERAGE"
JUSTIFIED RIGHT.
05 FILLER PIC X(7) VALUE "HEIGHT"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(4) VALUE "ALL"
JUSTIFIED RIGHT.
05 FILLER PIC X(12) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC X.
05 AVERAGE-HEIGHT PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
01 SUMMARY-LINE-02
05 FILLER PIC X(17) VALUE "AVERAGE"
JUSTIFIED RIGHT.
05 FILLER PIC X(7) VALUE "WEIGHT"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(4) VALUE "ALL"
JUSTIFIED RIGHT.
05 FILLER PIC X(12) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC X.
05 AVERAGE-WEIGHT PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
01 SUMMARY-LINE-03
05 FILLER PIC X(16) VALUE "NUMBER"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(11) VALUE "BROWN-EYED"
JUSTIFIED RIGHT.
05 FILLER PIC X(12) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC XX.
05 BROWN-EYED-APPLICANTS PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
01 SUMMARY-LINE-04
05 FILLER PIC X(16) VALUE "NUMBER"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(5) VALUE "MALE"
JUSTIFIED RIGHT.
05 FILLER PIC X(12) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC X(8) VALUE SPACES.
05 MALE-APPLICANTS PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
01 SUMMARY-LINE-05
05 FILLER PIC X(16) VALUE "NUMBER"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(7) VALUE "FEMALE"
JUSTIFIED RIGHT.
05 FILLER PIC X(11) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC X(6) VALUE SPACES.
05 FEMALE-APPLICANTS PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
procedure division.
100-main.
OPEN INPUT INPUT-FILE
OUTPUT OUTPUT-FILE
PERFORM UNTIL EOF = 'Y'
READ INPUT-FILE
AT END MOVE 'Y' TO EOF
NOT AT END
PERFORM 200-HEADING.
PERFORM 200-AVG-HEIGHT.
PERFORM 200-AVG-WEIGHT.
PERFORM 200-BROWN-EYED-APPS.
PERFORM 200-MALE-APPS.
PERFORM 200-FEMALE-APPS.
PERFORM 200-MALE-DETAIL-LINE.
PERFORM 200-FEMALE-DETAIL-LINE.
CLOSE INPUT-FILE, OUTPUT-FILE.
STOP RUN.
200-HEADING.
WRITE OUTPUT-REC FROM HEADING-1.
MOVE SPACES TO OUTPUT-REC.
WRITE OUTPUT-REC.
WRITE OUTPUT-REC FROM HEADING-2.
MOVE SPACES TO OUTPUT-REC.
WRITE OUTPUT-REC.
200-AVG-HEIGHT.
IF NOT AT END
ADD APPLICANTS-HEIGHT TO AVERAGE-HEIGHT
ELSE AT END
DIVIDE AVERAGE-HEIGHT BY 21.
WRITE OUTPUT-REC FROM SUMMARY-LINE-01.
200-AVG-WEIGHT.
IF NOT AT END
ADD APPLICANTS-WEIGHT TO AVERAGE-WEIGHT
ELSE AT END
DIVIDE AVERAGE-HEIGHT BY 21.
WRITE OUTPUT-REC FROM SUMMARY-LINE-02.
200-BROWN-EYED-APPS.
IF APPLICANTS-EYE-CODE = 2
ADD 1 TO BROWN-EYED-APPLICANTS
ELSE CONTINUE.
WRITE OUTPUT-REC FROM SUMMARY-LINE-03.
200-MALE-APPS.
IF APPLICANTS-GENDER = M
ADD 1 TO MALE-APPLICANTS
ELSE CONTINUE.
WRITE OUTPUT-REC FROM SUMMARY-LINE-04.
200-FEMALE-APPS.
IF APPLICANTS-GENDER = F
ADD 1 TO FEMALE-APPLICANTS
ELSE CONTINUE.
WRITE OUTPUT-REC FROM SUMMARY-LINE-05.
200-MALE-DETAIL-LINE.
IF APPLICANTS-HAIR-CODE = 1
IF APPLICANTS-EYE-CODE = 1
IF APPLICANTS-GENDER = M
IF APPLICANTS-HEIGHT >= 72
IF 185 <= APPLICANTS-WEIGHT <= 200
ELSE CONTINUE.
WRITE OUTPUT-REC FROM 01 DETAIL-LINE.
200-FEMALE-DETAIL-LINE.
IF APPLICANTS-HAIR-CODE = 2
IF APPLICANTS-EYE-CODE = 2
IF APPLICANTS-GENDER = F
IF 62 <= APPLICANTS-HEIGHT <= 64
IF 110 <= APPLICANTS-WEIGHT <= 125
ELSE CONTINUE.
WRITE OUTPUT-REC FROM 01 DETAIL-LINE.
end program ELECTRA-MODELING-AGENCY.
So you have several things that are going wrong here. Let me detail a few of them and give you some hints to fix them.
You are using periods to end statements, this is awful and bad when you mix it with some of the newer (and by newer, i mean only 30 years old) style of statements, like inline perform and read/at end/not at end/end-read.
Instead of this:
PERFORM UNTIL EOF = 'Y'
READ INPUT-FILE
AT END MOVE 'Y' TO EOF
NOT AT END
PERFORM 200-HEADING.
PERFORM 200-AVG-HEIGHT.
PERFORM 200-AVG-WEIGHT.
PERFORM 200-BROWN-EYED-APPS.
PERFORM 200-MALE-APPS.
PERFORM 200-FEMALE-APPS.
PERFORM 200-MALE-DETAIL-LINE.
PERFORM 200-FEMALE-DETAIL-LINE.
CLOSE INPUT-FILE, OUTPUT-FILE.
STOP RUN.
You need something like this:
PERFORM UNTIL EOF = 'Y' <--- This is better as an 88 level
READ INPUT-FILE
AT END MOVE 'Y' TO EOF
NOT AT END
PERFORM SOMETHING <--- You need to accumulate you data here
END-READ
END-PERFORM
PERFORM 200-HEADING
PERFORM 200-AVG-HEIGHT
PERFORM 200-AVG-WEIGHT
PERFORM 200-BROWN-EYED-APPS
PERFORM 200-MALE-APPS
PERFORM 200-FEMALE-APPS
PERFORM 200-MALE-DETAIL-LINE
PERFORM 200-FEMALE-DETAIL-LINE
CLOSE INPUT-FILE, OUTPUT-FILE
STOP RUN. <--- This is the only period you need
<--- In your mainline
You can not do this:
200-AVG-HEIGHT.
IF NOT AT END <--- NOT AT END and AT END only work
<--- in the context of a READ statement
ADD APPLICANTS-HEIGHT TO AVERAGE-HEIGHT
ELSE AT END
DIVIDE AVERAGE-HEIGHT BY 21.
WRITE OUTPUT-REC FROM SUMMARY-LINE-01.
While you are looping through the file, accumulate the total height by adding each applicants to APPLICANTS-HEIGHT and adding 1 to your APPLICANTS-COUNT. When you are ready to do your summary line for height, do this:
200-AVG-HEIGHT.
DIVIDE APPLICANTS-HEIGHT BY APPLICANTS-COUNT
WRITE OUTPUT-REC FROM SUMMARY-LINE-01
. <---- Again, you only need a single period to end a paragraph
In all of your paragraphs, you are trying to accumulate your data AND write your summary line. This does not work. See the perform loop above where I have the "Perform Something To Accumulate your data", this is the paragraph you want to put all of your code that adds up every applicant. You need separate paragraphs, as you have, to write the summary lines.
So this should happen every record:
200-MALE-DETAIL-LINE.
IF APPLICANTS-HAIR-CODE = 1
IF APPLICANTS-EYE-CODE = 1
IF APPLICANTS-GENDER = M
IF APPLICANTS-HEIGHT >= 72
IF 185 <= APPLICANTS-WEIGHT <= 200
ELSE CONTINUE. <--- you are doing nothing here
WRITE OUTPUT-REC FROM 01 DETAIL-LINE.
It is better written like this:
200-MALE-DETAIL-LINE.
IF APPLICANTS-HAIR-CODE = 1
AND APPLICANTS-EYE-CODE = 1
AND APPLICANTS-GENDER = M
AND APPLICANTS-HEIGHT >= 72
AND (185 <= APPLICANTS-WEIGHT <= 200)
WRITE OUTPUT-REC FROM 01-DETAIL-LINE
END-IF
That should get you going. You will need to apply these hints to all the other paragraphs. In brief, your program should generally look like this:
Open Files
Perform until EOF
Read a-record
not at end
Perform Do-Detail-Lines
at end
Set EOF to true
End-Read
End-Perform
Perform Do-Summary-Lines
Close files
Stop Run.
Do-Detail-Lines.
...add up all the things you are averaging and counting...
...populate detail line...
write output-rec from detail-line
.
Do-Summary-Lines.
...calculate all averages...
...populate summary line...
write output-red from summary-line
...repeat as needed for other summary-lines...
.
Happy coding :-)
I keep getting the error
"LOWMID-COMMISSION-CTR" was not a uniquely defined name. The definition
to be used could not be determined from the context.
And similar on all of my counters. I have no idea where I'm going wrong here, how is it not a uniquely defined name when it is clearly in the WORKING-STORAGE SECTION? Do I put it somewhere else so that it's a uniquely defined name? Below I have showed where I defined my counters, and where the counters are used.
IDENTIFICATION DIVISION.
PROGRAM-ID. LAB3.
AUTHOR.
******************************************************************
ENVIRONMENT DIVISION.
* defines the external files - an input file and output file
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALES-FILE ASSIGN TO DATAIN
FILE STATUS IS EF-STATUS.
SELECT REPORT-FILE ASSIGN TO DATAOUT
FILE STATUS IS PF-STATUS.
DATA DIVISION.
* has two sections - the file section that describes the files
* and the working storage section - where output lines and
* processing variables are defined
FILE SECTION.
FD SALES-FILE.
01 SALES-RECORD.
05 EMPLOYEE-NAME-IN PIC X(24).
05 SALES-IN PIC 99999.
05 FILLER PIC X(51).
FD REPORT-FILE.
01 REPORT-RECORD PIC X(80).
WORKING-STORAGE SECTION.
01 FLAGS-AND-ACCUMLATORS.
05 LOW-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 LOWMID-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 HIGHMID-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 HIGH-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 TOTAL-SALES PIC $$$,$$9.99 VALUE ZERO.
05 TOTAL-COMMISSION PIC $$$,$$9.99 VALUE ZERO.
05 END-OF-FILE PIC XXX VALUE "NO".
05 EF-STATUS PIC 99 VALUE 0.
05 PF-STATUS PIC 99 VALUE 0.
05 COMMISSION PIC 99999V99.
01 REPORT-BLANK-LINE.
05 PIC X(80).
01 HEADING-LINE-1.
05 PIC X(30) VALUE SPACES.
05 PIC X(19) VALUE
"COMPANY OF AARON".
01 HEADING-LINE-2.
05 PIC X(30) VALUE SPACES.
05 PIC X(19) VALUE
"KEARNEY, MISSOURI".
01 HEADING-LINE-3.
05 PIC X(03) VALUE SPACES.
05 PIC X(48) VALUE
"Number of employees with up to 10,000 in sales: ".
05 LOW-COMMISSION-CTR PIC 99999.
01 HEADING-LINE-4.
05 PIC X(03) VALUE SPACES.
05 PIC X(52) VALUE
"Number of employees from 10,001 to 20,000 in sales: ".
05 LOWMID-COMMISSION-CTR PIC 99999.
01 HEADING-LINE-5.
05 PIC X(03) VALUE SPACES.
05 PIC X(52) VALUE
"Number of employees from 20,001 to 30,000 in sales: ".
05 HIGHMID-COMMISSION-CTR PIC 99999.
01 HEADING-LINE-6.
05 PIC X(03) VALUE SPACES.
05 PIC X(42) VALUE
"Number of employees over 30,000 in sales: ".
05 HIGH-COMMISSION-CTR PIC 99999.
01 HEADING-LINE-7.
05 PIC X(03) VALUE SPACES.
05 PIC X(13) VALUE
"Total Sales: ".
05 TOTAL-SALES PIC $$$,$$9.99.
01 HEADING-LINE-8.
05 PIC X(03) VALUE SPACES.
05 PIC X(18) VALUE
"TOTAL COMMISSION: ".
05 TOTAL-COMMISSION PIC $$$,$$9.99.
01 COLUMN-HEADING-1.
05 PIC X(03) VALUE SPACES.
05 PIC X(24) VALUE "SALESPERSON".
05 PIC X(15) VALUE "SALES".
05 PIC X(10) VALUE "COMMISSION".
01 COLUMN-HEADING-2.
05 PIC X(14) VALUE "SUMMARY REPORT".
01 DETAIL-LINE.
05 PIC X(03) VALUE SPACES.
05 EMPLOYEE-NAME-OUT PIC X(24).
05 SALES-OUT PIC $$$,$$9.
05 PIC X(05) VALUE SPACES.
05 COMMISSION-OUT PIC $$$,$$9.99.
PROCEDURE DIVISION.
1000-MAIN-CONTROL.
PERFORM 2000-INITIALIZE.
PERFORM UNTIL END-OF-FILE = "YES"
READ SALES-FILE
AT END
MOVE "YES" TO END-OF-FILE
NOT AT END
PERFORM 3000-PROCESS
END-PERFORM
PERFORM 4000-PROCESS.
STOP RUN.
2000-INITIALIZE.
OPEN INPUT SALES-FILE
OUTPUT REPORT-FILE.
WRITE REPORT-RECORD FROM HEADING-LINE-1.
WRITE REPORT-RECORD FROM HEADING-LINE-2.
WRITE REPORT-RECORD FROM REPORT-BLANK-LINE.
WRITE REPORT-RECORD FROM COLUMN-HEADING-1.
WRITE REPORT-RECORD FROM REPORT-BLANK-LINE.
3000-PROCESS.
IF SALES-IN < 10001
MULTIPLY SALES-IN BY .04 GIVING COMMISSION
ADD 1 TO LOW-COMMISSION-CTR
ADD COMMISSION TO TOTAL-COMMISSION
END-IF.
IF SALES-IN > 10000 AND < 20001
MULTIPLY SALES-IN BY .055 GIVING COMMISSION
ADD 1 TO LOWMID-COMMISSION-CTR
ADD COMMISSION TO TOTAL-COMMISSION
END-IF.
IF SALES-IN > 20000 AND < 30000
MULTIPLY SALES-IN BY .065 GIVING COMMISSION
ADD 1 TO HIGHMID-COMMISSION-CTR
ADD COMMISSION TO TOTAL-COMMISSION
END-IF.
IF SALES-IN > 30000
MULTIPLY SALES-IN BY .075 GIVING COMMISSION
ADD 1 TO HIGH-COMMISSION-CTR
ADD COMMISSION TO TOTAL-COMMISSION
END-IF.
MOVE EMPLOYEE-NAME-IN TO EMPLOYEE-NAME-OUT.
MOVE SALES-IN TO SALES-OUT.
MOVE COMMISSION TO COMMISSION-OUT.
WRITE REPORT-RECORD FROM DETAIL-LINE.
4000-PROCESS.
WRITE REPORT-RECORD FROM REPORT-BLANK-LINE.
WRITE REPORT-RECORD FROM COLUMN-HEADING-2.
WRITE REPORT-RECORD FROM HEADING-LINE-3.
WRITE REPORT-RECORD FROM HEADING-LINE-4.
WRITE REPORT-RECORD FROM HEADING-LINE-5.
WRITE REPORT-RECORD FROM HEADING-LINE-6.
WRITE REPORT-RECORD FROM HEADING-LINE-7.
WRITE REPORT-RECORD FROM HEADING-LINE-8.
4000-TERMINATE.
CLOSE SALES-FILE, REPORT-FILE.
Thje variable LOWMID-COMMISSION-CTR is defined twice.
once in FLAGS-AND-ACCUMLATORS
01 FLAGS-AND-ACCUMLATORS.
05 LOW-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 LOWMID-COMMISSION-CTR PIC 99999 VALUE ZERO.
once in HEADING-LINE-4
01 HEADING-LINE-4.
05 PIC X(03) VALUE SPACES.
05 PIC X(52) VALUE
"Number of employees from 10,001 to 20,000 in sales: ".
05 LOWMID-COMMISSION-CTR PIC 99999.
So either
rename one of the LOWMID-COMMISSION-CTR to some thing else
01 HEADING-LINE-4.
05 PIC X(03) VALUE SPACES.
05 PIC X(52) VALUE
"Number of employees from 10,001 to 20,000 in sales: ".
05 HEADER-LOWMID-COMMISSION-CTR PIC 99999.
fully qualify the field.
Add 1
to LOWMID-COMMISSION-CTR
of FLAGS-AND-ACCUMLATORS
Same applies to other FLAGS-AND-ACCUMLATORS fields
FD STUDENTS-FILE-IN.
01 STUDENTS-RECORD-IN.
05 SSN-IN PIC X(9).
05 STUDENT-NAME-IN PIC X(11).
05 PIC X(5).
05 GRAD-STATUS-IN PIC X.
05 CLASS-STANDING-IN PIC X.
05 MAJOR-IN PIC X(3).
05 CREDIT-HOURS-IN PIC 9(3).
05 CREDIT-POINTS-IN PIC 9(3).
FD STUDENTS-FILE-OUT.
01 STUDENTS-RECORD-OUT PIC X(80).
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
01 PAGE-NUMBER PIC 99 VALUE ZERO.
01 LINE-COUNT PIC 99 VALUE ZERO.
01 SSID-BREAK.
03 FIRST-PART PIC X(3).
03 SECOND-PART PIC X(2).
03 THIRD-PART PIC X(4).
01 NAME-BREAK.
03 FIRST-LETTER PIC X(1).
03 MIDDLE-LETTER PIC X(1).
03 LAST-LETTER PIC X(10).
01 GRAD-CHECK PIC X.
01 WS-DATE.
05 RUN-YEAR PIC XX.
05 RUN-MONTH PIC XX.
05 RUN-DAY PIC XX.
01 HEADING-LINE-ONE.
05 PIC X(21) VALUE SPACES.
05 PIC X(33)
VALUE 'RHODES STATE COLLEGE GRADE REPORT'.
05 PIC X(6) VALUE SPACES.
05 HEADING-LINE-DATE.
10 MONTH-NOW PIC XX.
10 PIC X VALUE '/'.
10 DAY-NOW PIC XX.
10 PIC X VALUE '/'.
10 YEAR-NOW PIC XX.
05 PIC X(3) VALUE SPACES.
05 PIC X(4) VALUE 'PAGE'.
05 HL-1-PAGE-NUMBER PIC Z9 VALUE ZEROS.
01 HEADING-LINE-TWO.
05 PIC X(10) VALUE 'SOC SEC NO'.
05 PIC X(4) VALUE SPACES.
05 PIC X(12) VALUE 'STUDENT NAME'.
05 PIC X(3) VALUE SPACES.
05 PIC X(8) VALUE 'STANDING'.
05 PIC X(4) VALUE SPACES.
05 PIC X(5) VALUE 'MAJOR'.
05 PIC X(10) VALUE SPACES.
05 PIC X(5) VALUE 'HOURS'.
05 PIC X(2) VALUE SPACES.
05 PIC X(6) VALUE 'POINTS'.
05 PIC X(5) VALUE SPACES.
05 PIC X(3) VALUE 'GPA'.
01 DETAIL-LINE.
05 DL-SSID.
10 SSID-1 PIC X(3).
10 PIC X VALUE "-".
10 SSID-2 PIC X(2).
10 PIC X VALUE "-".
10 SSID-3 PIC X(4).
05 BLANK-B PIC X(3) VALUE SPACES.
05 DL-NAME .
10 FIRST-INI PIC X.
10 PIC X VALUE SPACES.
10 MID-INI PIC X.
10 PIC X VALUE SPACES.
10 LAST-NAME PIC X(10).
05 BLANK-C PIC X(3) VALUE SPACES.
05 YEAR-STATUS PIC X(9).
05 BLANK-D PIC X(3) VALUE SPACES.
05 STUDENT-MAJOR PIC X(13).
05 BLANK-E PIC X(5) VALUE SPACES.
05 STUDNET-HOURS PIC ZZ9.
05 BLANK-F PIC X(5) VALUE SPACES.
05 STUDENT-POINTS PIC ZZ9.
05 BLANK-G PIC X(4) VALUE SPACES.
05 STUDENT-GPA PIC 9V99.
01 TOTALS-LINE.
05 TOTALS PIC X(6) VALUE 'TOTALS'.
05 PIC X(34) VALUE SPACES.
05 HITS-TOTAL PIC ZZZ,ZZZ.
05 PIC X(9) VALUE SPACES.
05 BATS-TOTAL PIC ZZZ,ZZZ.
05 PIC X(10) VALUE SPACES.
05 AVG-TOTAL PIC .999.
PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT STUDENTS-FILE-IN
OPEN OUTPUT STUDENTS-FILE-OUT
ACCEPT WS-DATE FROM DATE
MOVE RUN-MONTH TO MONTH-NOW
MOVE RUN-DAY TO DAY-NOW
MOVE RUN-YEAR TO YEAR-NOW
PERFORM 300-WRITE-HEADINGS
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ STUDENTS-FILE-IN
AT END
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-PROCESS-ONE-RECORD
END-READ
END-PERFORM
CLOSE STUDENTS-FILE-IN
CLOSE STUDENTS-FILE-OUT
STOP RUN.
200-PROCESS-ONE-RECORD.
IF LINE-COUNT >= 53
PERFORM 300-WRITE-HEADINGS
END-IF
* IF GRAD-STATUS-IN NOT = '1' AND NOT = '2'
* PERFORM 400-WRITE-TOTALS.
* END-IF
MOVE SSN-IN TO SSID-BREAK
MOVE FIRST-PART TO SSID-1
MOVE SECOND-PART TO SSID-2
MOVE THIRD-PART TO SSID-3
MOVE STUDENT-NAME-IN TO NAME-BREAK
MOVE FIRST-LETTER TO FIRST-INI
MOVE MIDDLE-LETTER TO MID-INI
MOVE LAST-LETTER TO LAST-NAME
MOVE GRAD-STATUS-IN TO GRAD-CHECK
IF GRAD-CHECK = 'Y'
END-IF
MOVE DETAIL-LINE TO STUDENTS-RECORD-OUT
WRITE STUDENTS-RECORD-OUT
AFTER ADVANCING 1 LINES
ADD 1 TO LINE-COUNT.
The input file looks like this
307662099KRAlexander Y2NES005017
Basically certain files won't meet the requirements and we are just suppose to just skip over them. This is an example of the file that we don't want to write to the output file and skip over. I apologize if I explained this poorly but I am really struggling with COBOL.
Your 200- paragraph needs to do something like this:
IF NOT ( <condition-for-skipping )
PERFORM PROCESS-THIS-RECORD
ELSE
PERFORM IGNORE-THIS-RECORD
END-IF
You can swap the conditions easily
IF ( <condition-for-skipping )
PERFORM IGNORE-THIS-RECORD
ELSE
PERFORM PROCESS-THIS-RECORD
END-IF
All the stuff you have in the 200- paragraph currently, you put in to a new paragrpah PROCESS-THIS-RECORD. You should have a new paragraph IGNORE-THIS-RECORD. If nothing else, it can count the records which are ignored. Then if you count the records which are processed, and count the input records, at the end you can check that everything is either processed or ignored.
You should check file-statuses. It is good to use scope-delimiters (like the END-IF) and keep full-stops/periods to a minimum.
88s are good to use for conditions. Saves lots of literals hanging about to make maintenance more complex.