I am working on a project for college that is supposed to do the following:
take screen input for a payroll record
validate each field
if invalid allow the user to either correct or clear the screen to enter the next record
if valid write the record to a file
when no more records exit
I am having problems exiting my validate loop if the user does not want to correct the error. Here is the short version of what I have done.
PROCEDURE DIVISION.
CREATE-VALID-PAYROLL-FILE.
OPEN OUTPUT PAYROLL-FILE.
PERFORM INPUT-RECORDS UNTIL NO-MORE-RECORDS.
CLOSE PAYROLL-FILE.
STOP RUN. (THIS SECTION WORKS FINE)
INPUT-RECORDS
INITIALIZE PAYROLL-RECORD.
DISPLAY OPENING-SCREEN.
PERFORM VALIDATE-PAYROLL-RECORD.
MOVE ENTER-ANOTHER-MESSAGE TO CONFIRM-MESSAGE.
PERFORM INPUT-SCREEN-CONFIRM.
PERFORM WRITE-VALID-RECORD.
(THE VALIDATE-PAYROLL-RECORD PARAGRAPH CONTAINS A SERIES OF PERFORM STATEMENTS TO CHECK EACH FIELD INDIVIDUALLY I.E. PERFORM VALIDATE SOC-SEC-NUM, ETC. - IF THE VALIDATE PARAGRAPH ENCOUNTERS AN ERROR IT CALLS - PERFORM DISPLAY ERROR)
DISPLAY-ERROR
MOVE 'NO' TO VALID-FIELD-SWITCH.
DISPLAY ERROR-LINE.
ACCEPT ERROR-LINE.
IF QUIT (IF THE USER SAYS NO THEY DON'T WANT TO FIX THE ERROR -- QUIT is an 88 level switch)
PERFORM CLEAR-ERROR (just takes away the message)
MOVE ENTER-ANOTHER-MESSAGE TO CONFIRM-MESSAGE
DISPLAY CONFIRM-SCREEN
ACCEPT CONFIRM-SCREEN
PERFORM INPUT-RECORD (GO BACK TO BEGINNING)
END-IF.
The CONFIRM-SCREEN paragraph just displays "enter another record" and sets the switch accordingly.
This program works as long as all the records are correct or the user chooses to fix the error. However it does not work if the user encounters an error that they don't want to fix. Then the program clears the screen and goes back to the first field, however, it is not actually exiting the loop because when I get to the next correct record the program will display the "enter another" message the same number of times as there were previous errors and also save the valid record the same number of times. So, if the user had three incorrect records the next valid record saves 4 times, once for each error and once for the valid record.
What am I doing wrong. Is there some kind of 'exit perform' construct in COBOL.
Thanks.
take screen input for a payroll record
validate each field
if invalid allow the user to either correct or clear the screen to enter the next record
if valid write the record to a file
when no more records exit
I am having problems exiting my validate loop if the user does not want to correct the error. Here is the short version of what I have done.
PROCEDURE DIVISION.
CREATE-VALID-PAYROLL-FILE.
OPEN OUTPUT PAYROLL-FILE.
PERFORM INPUT-RECORDS UNTIL NO-MORE-RECORDS.
CLOSE PAYROLL-FILE.
STOP RUN. (THIS SECTION WORKS FINE)
INPUT-RECORDS
INITIALIZE PAYROLL-RECORD.
DISPLAY OPENING-SCREEN.
PERFORM VALIDATE-PAYROLL-RECORD.
MOVE ENTER-ANOTHER-MESSAGE TO CONFIRM-MESSAGE.
PERFORM INPUT-SCREEN-CONFIRM.
PERFORM WRITE-VALID-RECORD.
(THE VALIDATE-PAYROLL-RECORD PARAGRAPH CONTAINS A SERIES OF PERFORM STATEMENTS TO CHECK EACH FIELD INDIVIDUALLY I.E. PERFORM VALIDATE SOC-SEC-NUM, ETC. - IF THE VALIDATE PARAGRAPH ENCOUNTERS AN ERROR IT CALLS - PERFORM DISPLAY ERROR)
DISPLAY-ERROR
MOVE 'NO' TO VALID-FIELD-SWITCH.
DISPLAY ERROR-LINE.
ACCEPT ERROR-LINE.
IF QUIT (IF THE USER SAYS NO THEY DON'T WANT TO FIX THE ERROR -- QUIT is an 88 level switch)
PERFORM CLEAR-ERROR (just takes away the message)
MOVE ENTER-ANOTHER-MESSAGE TO CONFIRM-MESSAGE
DISPLAY CONFIRM-SCREEN
ACCEPT CONFIRM-SCREEN
PERFORM INPUT-RECORD (GO BACK TO BEGINNING)
END-IF.
The CONFIRM-SCREEN paragraph just displays "enter another record" and sets the switch accordingly.
This program works as long as all the records are correct or the user chooses to fix the error. However it does not work if the user encounters an error that they don't want to fix. Then the program clears the screen and goes back to the first field, however, it is not actually exiting the loop because when I get to the next correct record the program will display the "enter another" message the same number of times as there were previous errors and also save the valid record the same number of times. So, if the user had three incorrect records the next valid record saves 4 times, once for each error and once for the valid record.
What am I doing wrong. Is there some kind of 'exit perform' construct in COBOL.
Thanks.