my program is suppose to add record to the output file if JOBCODE = S and SALES > 100,000.00. The variables are all being passed properly but when the program is finished only the last record remains in the output file and I can't figure out why. How do I add it under neath the previous record? I have also used OPEN EXTEND already and received the same result. This is what the output currently looks like:
Employee recognition for the week ending: 2022-06-22
----------------------------------------------------
Last Name First Name Store #
----------------------------------------------------
ESTERA BETHANY 0003
It should be:
Employee recognition for the week ending: 2022-06-22
----------------------------------------------------
Last Name First Name Store #
----------------------------------------------------
CAMERON STANLEY 0003
ELDOUR JOHNATHAN 0002
KENT LORENE 0001
NGUYEN CARMELO 0002
SRIVASTAVA SAM 0003
LABRIE ARMAND 0003
CHU LARISA 0001
FORLINI COREEN 0002
ESTERA BETHANY 0003
Here is my program:
program-id. Assignment6 AS "Assignment6".
environment division.
input-output section.
*INPUT FILE DECLARATION
SELECT IN-FILE ASSIGN "C:\DataFiles\dataIn.dat"
ORGANIZATION IS LINE SEQUENTIAL.
*SALES RECONGNITION OUTPUT FILE DECLARATION
SELECT OUT-FILE-SALES ASSIGN
"C:\DataFiles\SalespersonRecongnition.rpt"
ORGANIZATION IS LINE SEQUENTIAL.
*SALARY EXPENSES OUTPUT FILE DECLARATION
configuration section.
data division.
file section.
FD IN-FILE.
01 IN-RECORD.
03 IN-EMPLOYEEID PIC X(4).
03 IN-JOBCODE PIC X(1).
03 IN-LASTNAME PIC X(14).
03 IN-FIRSTNAME PIC X(14).
03 IN-STARTDATE PIC 9(8).
03 IN-STORENUM PIC 9(4).
03 IN-SALARY PIC 9(6).
03 IN-SALES PIC 9(8).
FD OUT-FILE-SALES.
01 SALES-OUT-RECORD PIC X(52).
working-storage section.
*END OF FILE
01 WS-EOF PIC 9(1) VALUE 0.
*WS IN-RECORD HOLDER
01 WS-IN-RECORD.
03 WS-IN-EMPLOYEEID PIC X(4).
03 WS-IN-JOBCODE PIC X(1).
03 WS-IN-LASTNAME PIC X(14).
03 WS-IN-FIRSTNAME PIC X(14).
03 WS-IN-STARTDATE PIC 9(8).
03 WS-IN-STORENUM PIC 9(4).
03 WS-IN-SALARY PIC 9(6).
03 WS-IN-SALES PIC 9(8).
*SALES REPORT HEADINGS STRUCTURE
01 SALES-RECORD-HEADING1.
03 FILLER PIC A(52) VALUE
"Employee recognition for the week ending: 2022-06-22".
01 SALES-RECORD-FILLER1.
03 FILLER PIC X(52) VALUE ALL '-'.
01 SALES-RECORD-HEADING2.
03 FILLER PIC X(9) VALUE "Last Name".
03 FILLER PIC X(13) VALUE SPACE.
03 FILLER PIC X(10) VALUE "First Name".
03 FILLER PIC X(10) VALUE SPACE.
03 FILLER PIC X(7) VALUE "Store #".
03 FILLER PIC X(3) VALUE SPACE.
01 SALES-RECORD-FILLER2.
03 FILLER PIC X(52) VALUE ALL "-".
*SALES RECORD ROW STRUCTURE
01 SALES-ROW.
03 WS-SALES-LASTNAME PIC X(14).
03 FILLER PIC X(8) VALUE SPACE.
03 WS-SALES-FIRSTNAME PIC X(14).
03 FILLER PIC X(8) VALUE SPACE.
03 WS-SALES-STORENUM PIC 9(4).
03 FILLER PIC X(4) VALUE SPACE.
procedure division.
*MAIN PROGRAM
PERFORM OPEN-FILES.
PERFORM READ-FILE
UNTIL WS-EOF = 1.
PERFORM CLOSE-FILES.
OPEN-FILES.
OPEN INPUT IN-FILE
OUTPUT OUT-FILE-SALES
WRITE SALES-OUT-RECORD FROM SALES-RECORD-HEADING1
WRITE SALES-OUT-RECORD FROM SALES-RECORD-FILLER1
WRITE SALES-OUT-RECORD FROM SALES-RECORD-HEADING2
WRITE SALES-OUT-RECORD FROM SALES-RECORD-FILLER2.
READ-FILE.
READ IN-FILE INTO IN-RECORD
AT END
SET WS-EOF TO 1
NOT AT END
PERFORM GOT-A-RECORD
END-READ.
GOT-A-RECORD.
MOVE IN-EMPLOYEEID TO WS-IN-EMPLOYEEID
MOVE IN-JOBCODE TO WS-IN-JOBCODE
MOVE IN-LASTNAME TO WS-IN-LASTNAME
MOVE IN-FIRSTNAME TO WS-IN-FIRSTNAME
MOVE IN-STARTDATE TO WS-IN-STARTDATE
MOVE IN-STORENUM TO WS-IN-STORENUM
MOVE IN-SALARY TO WS-IN-SALARY
MOVE IN-SALES TO WS-IN-SALES
PERFORM SALES-REPORT-ADD-RECORD.
SALES-REPORT-ADD-RECORD.
IF WS-IN-JOBCODE = "S"
AND WS-IN-SALES > 10000000
MOVE WS-IN-LASTNAME TO WS-SALES-LASTNAME
MOVE WS-IN-FIRSTNAME TO WS-SALES-FIRSTNAME
MOVE WS-IN-STORENUM TO WS-SALES-STORENUM
PERFORM WRITE-RECORD
END-IF .
WRITE-RECORD.
WRITE SALES-OUT-RECORD FROM SALES-ROW
DISPLAY SALES-ROW.
CLOSE-FILES.
CLOSE IN-FILE
OUT-FILE-SALES.
.
end program Assignment6.
Any suggestions would be appreciated!
CodePudding user response:
Your program has no explicit end, therefore it "falls through":
You likely want to add GOBACK.
at the end of your main.