Presentation is loading. Please wait.

Presentation is loading. Please wait.

Edit Programs Please use speaker notes for additional information. Example: payedit.cbl payedit.cbl.

Similar presentations


Presentation on theme: "Edit Programs Please use speaker notes for additional information. Example: payedit.cbl payedit.cbl."— Presentation transcript:

1 Edit Programs Please use speaker notes for additional information. Example: payedit.cbl payedit.cbl

2 The purpose of an EDIT PROGRAM is to check data input and catch errors before they are entered into the system. Edit program input transactions Edit Program good transactions error report

3 The sample edit program has the following input and output files:  disk file input containing the records to be edited  disk file output containing the records that passed the edit tests and are to become a permanent part of our system  printer file containing the records that were found to contain errors - these records were not written on the disk file output - on our report, each error will printed on a separate line The sample program is editing payroll transactions. Each transaction record is checked for the following:  The first character of the employee id must contain an F, P, C, or T - these are set up with a level 88 for VALID- EMP-CD rather than checking for each letter within the IF statement.  The rest of the id number (4 characters) must be numeric  The work hours must be numeric and cannot be greater than 40  The overtime hours must be numeric and cannot be greater than 20  The sick hours must be numeric and cannot be greater than 40  The vacation hours must be numeric and cannot be greater than 40  The holiday hours must be numeric and cannot be greater than 8  If holiday hours = 0 then the holiday code must be blank. If there are holiday hours than the code must be N, K, M, L, T or C  Bonus pay must be numeric and cannot be greater than 1000  If employee code is F (full-time) than the some of the employee hours (regular, overtime, sick, vacation, and holiday) cannot be less than 40  The sum of the employee hours (regular, overtime, sick, vacation and holiday) cannot exceed 80 Program specifications: payedit.cbl

4 FD PAYROLL-KEYED DATA RECORD IS PAY-KEYED-REC. 01 PAY-KEYED-REC. 05 EMP-ID. 10 EMP-CD PIC X. 88 VALID-EMP-CD VALUE "F" "P" "C" "T". 10 ID-NO PIC 9(4). 10 RDF-ID-NO REDEFINES ID-NO PIC X(4). 05 WORK-HRS PIC 99. 05 RDF-WORK-HRS REDEFINES WORK-HRS PIC XX. 05 OVT-HRS PIC 99. 05 RDF-OVT-HRS REDEFINES OVT-HRS PIC XX. 05 SICK-HRS PIC 99. 05 RDF-SICK-HRS REDEFINES SICK-HRS PIC XX. 05 VACA-HRS PIC 99. 05 RDF-VACA-HRS REDEFINES VACA-HRS PIC XX. 05 HOLIDAY-HRS PIC 99. 05 RDF-HOLIDAY-HRS REDEFINES HOLIDAY-HRS PIC XX. 05 HOLIDAY-CODE PIC X. 88 VALID-HOLIDAY-CODE VALUES " " "N" "K" "M" "L" "T" "C". 05 BONUS-PAY PIC 9999V99. 05 RDF-BONUS-PAY REDEFINES BONUS-PAY PIC X(6). F12124010000000 050000 Input data described Data from 1st input record

5 F12124010000000 050000 Good record This is the first record on the file and it is a valid record as we shall see when we check the tests. IF NOT VALID-EMP-CD MOVE EMP-CD TO DATA-IN-ERR-PR MOVE "INVALID EMP-CD - MUST BE F, P, C OR T" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR. IF ID-NO NOT NUMERIC MOVE RDF-ID-NO TO DATA-IN-ERR-PR MOVE "EMPLOYEE NUMBER NOT NUMERIC" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR. 05 EMP-ID. 10 EMP-CD PIC X. 88 VALID-EMP-CD VALUE "F" "P" "C" "T". 10 ID-NO PIC 9(4). 10 RDF-ID-NO REDEFINES ID-NO PIC X(4). Note that F is a valid employee code so no error is generated. Note that 1212 is numeric so the record passes the test to make sure that ID-NO is numeric.

6 Good record F12124010000000 050000 IF WORK-HRS NOT NUMERIC MOVE RDF-WORK-HRS TO DATA-IN-ERR-PR MOVE "WORK HOURS NOT NUMERIC" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR ELSE ADD WORK-HRS TO EMP-HRS-WS IF WORK-HRS > 40 MOVE WORK-HRS TO DATA-IN-ERR-PR MOVE "ENTRY IN WORK HOURS EXCEEDS 40" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR. Since work hours are numeric and are not greater than 40, the entry is valid.

7 F12124010000000 050000 Good record IF OVT-HRS NOT NUMERIC MOVE RDF-OVT-HRS TO DATA-IN-ERR-PR MOVE "OVERTIME HOURS NOT NUMERIC" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR ELSE ADD OVT-HRS TO EMP-HRS-WS IF OVT-HRS > 20 MOVE OVT-HRS TO DATA-IN-ERR-PR MOVE "OVERTIME HOURS EXCEED 20" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR. IF SICK-HRS NOT NUMERIC MOVE RDF-SICK-HRS TO DATA-IN-ERR-PR MOVE "SICK HOURS NOT NUMERIC" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR ELSE ADD SICK-HRS TO EMP-HRS-WS IF SICK-HRS > 40 MOVE SICK-HRS TO DATA-IN-ERR-PR MOVE "SICK HOURS GREATER THAN 40" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR.

8 F12124010000000 050000 Good record IF VACA-HRS NOT NUMERIC MOVE RDF-VACA-HRS TO DATA-IN-ERR-PR MOVE "VACATION HOURS NOT NUMERIC" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR ELSE ADD VACA-HRS TO EMP-HRS-WS IF VACA-HRS > 40 MOVE VACA-HRS TO DATA-IN-ERR-PR MOVE "VACATION HOURS GREATER THAN 40" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR. Note that on each of the hours tests, if the hours are numeric I add them to EMP-HRS-WS. This is happening so that after all of the hours tests, I can check the total number of hours accumulated and see if this number is valid.

9 Good record F12124010000000 050000 IF HOLIDAY-HRS NOT NUMERIC MOVE RDF-HOLIDAY-HRS TO DATA-IN-ERR-PR MOVE "HOLIDAY HOURS NOT NUMERIC" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR ELSE ADD HOLIDAY-HRS TO EMP-HRS-WS IF HOLIDAY-HRS > 8 MOVE HOLIDAY-HRS TO DATA-IN-ERR-PR MOVE "HOLIDAY HOURS GREATER THAN 8" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR END-IF IF HOLIDAY-HRS = 0 IF HOLIDAY-CODE = " " NEXT SENTENCE ELSE MOVE HOLIDAY-CODE TO DATA-IN-ERR-PR MOVE "NO HOLIDAY HOURS" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR END-IF ELSE IF NOT VALID-HOLIDAY-CODE MOVE HOLIDAY-CODE TO DATA-IN-ERR-PR MOVE "INVALID HOLIDAY CODE - NOT N, K, M, L, T, C" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR END-IF END-IF. 05 HOLIDAY-HRS PIC 99. 05 RDF-HOLIDAY-HRS REDEFINES HOLIDAY-HRS PIC XX. 05 HOLIDAY-CODE PIC X. 88 VALID-HOLIDAY-CODE VALUES " " "N" "K" "M" "L" "T" "C".

10 F12124010000000 050000 Good record IF BONUS-PAY NOT NUMERIC MOVE RDF-BONUS-PAY TO DATA-IN-ERR-PR MOVE "BONUS PAY NOT NUMERIC" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR ELSE IF BONUS-PAY > 1000 MOVE BONUS-PAY TO RDF-DATA-IN-ERR-PR MOVE "BONUS PAY OUT OF RANGE - VALID TO 1000" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR. IF EMP-CD = "F" AND EMP-HRS-WS < 40 MOVE EMP-HRS-WS TO DATA-IN-ERR-PR MOVE "HOURS WORKED LESS THAN 40" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR ELSE IF EMP-HRS-WS > 80 MOVE EMP-HRS-WS TO DATA-IN-ERR-PR MOVE "HOURS WORKED GREATER THAN 80" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR. The total hours worked as stored in EMP-HRS-WS is 50 (the sum of 40 regular and 10 hours overtime). This is a valid number of hours.

11 B-200-LOOP. IF PAGE-NO = 1 OR LNCT > 55 PERFORM B-300-HDR-ROUT. MOVE "NO " TO ERROR-IND. MOVE 0 TO EMP-HRS-WS. PERFORM B-310-EDIT-RECORD IF NO-ERRORS ADD 1 TO NUM-VALID-TRANS MOVE PAY-KEYED-REC TO INFO-FROM-REC MOVE DATE-WS TO DATE-TRAN WRITE PAY-TRAN-REC ELSE ADD 1 TO NUM-INVALID-TRANS. READ PAYROLL-KEYED AT END MOVE "YES" TO EOF-IND. Good record The ERROR-IND is set to NO and the EMP-HRS-WS is set to 0 prior to checking the record. The record is checked - that is what we have seen on the last few slides. We checked each field for validity. Since the data was good, the ERROR-IND did not get changes, it remained set to NO. There were no errors so 1 was added to the NUM-VALID-TRANS and the data was moved to PAY- TRAN-REC and was written to the valid record disk file. FD PAYROLL-TRAN DATA RECORD IS PAY-TRAN-REC. 01 PAY-TRAN-REC. 05 INFO-FROM-REC PIC X(22). 05 DATE-TRAN PIC 9(6). Input Record: F12124010000000 050000 Output Record: F12124010000000 050000990317

12 F28281640001608T000000 input ID 3/17/99 TRANSACTION EXCEPTION REPORT PAGE 1 ID # DATA ERROR MESSAGE F2828 40 OVERTIME HOURS EXCEED 20 FD PRINT-FILE DATA RECORD IS PRINTZ. 01 PRINTZ. 05 FILLER PIC X. 05 EMP-ID-PR PIC X(5). 05 FILLER PIC X(5). 05 DATA-IN-ERR-PR PIC X(7). 05 RDF-DATA-IN-ERR-PR REDEFINES DATA-IN-ERR-PR PIC 9999.99. 05 FILLER PIC X(4). 05 ERROR-MSG-PR PIC X(50). 05 FILLER PIC X(8). Invalid record -Output data to the printer input overtime hours LOGIC: LOGIC: IF OVT-HRS > 20 MOVE OVT-HRS TO DATA-IN-ERR-PR MOVE "OVERTIME HOURS EXCEED 20" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR.

13 IF OVT-HRS NOT NUMERIC MOVE RDF-OVT-HRS TO DATA-IN-ERR-PR MOVE "OVERTIME HOURS NOT NUMERIC" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR ELSE ADD OVT-HRS TO EMP-HRS-WS IF OVT-HRS > 20 MOVE OVT-HRS TO DATA-IN-ERR-PR MOVE "OVERTIME HOURS EXCEED 20" TO ERROR-MSG-PR PERFORM U-100-WRITE-ERROR. Checking OVT-HRS On the previous slide, we showed the check that produced the error being written to the report. In fact, there are two checks on OVT-HRS. The first checks to see if it is numeric. If it is not numeric the RDF-OVT-HRS which has a picture of XX and can therefore be used when the data contains non-numeric characters is moved to the error line along with an appropriate message. If the OVT-HRS is numeric we then add it to EMP-HRS-WS because we need to check the total hours worked. Notice we need to add the field with the PIC 99. We then check the OVT-HRS to see if it is the correct range - the subject of the previous slide.

14 U-100-WRITE-ERROR. MOVE EMP-ID TO EMP-ID-PR. WRITE PRINTZ AFTER ADVANCING 1 LINES. ADD 1 TO LNCT. MOVE "YES" TO ERROR-IND. Every time an error is encountered, the data that is in error and an appropriate message are moved to the print line and the routine U-100-WRITE-ERROR is performed. In this routine, the EMP-ID is moved to the line, the line is written and 1 is added to the LNCT and the ERROR-IND is set to YES indicating that an error was found on this record. 05 ERROR-IND PIC XXX VALUE "NO ". 88 THERE-IS-AN-ERROR VALUE "YES". 88 NO-ERRORS VALUE "NO ". The ERROR-IND has two level 88s beneath it. THERE-IS-AN-ERROR is true when the indicator contains YES and NO-ERRORS is true when the indicator contains NO. Setting ERROR-IND

15 B-200-LOOP. IF PAGE-NO = 1 OR LNCT > 55 PERFORM B-300-HDR-ROUT. MOVE "NO " TO ERROR-IND. MOVE 0 TO EMP-HRS-WS. PERFORM B-310-EDIT-RECORD IF NO-ERRORS ADD 1 TO NUM-VALID-TRANS MOVE PAY-KEYED-REC TO INFO-FROM-REC MOVE DATE-WS TO DATE-TRAN WRITE PAY-TRAN-REC ELSE ADD 1 TO NUM-INVALID-TRANS. READ PAYROLL-KEYED AT END MOVE "YES" TO EOF-IND. B-200-LOOP B-310-EDIT-RECORD is the routine that checks each field on the record for data. When an error is found, the line is written on the report and the ERROR-IND is set to yes. When the B-310-EDIT-RECORD is complete, control returns and the indicator is checked to see if one or more errors was found. This is done with: IF NO-ERRORS IF NO-ERRORS is true, then 1 is added to the number of valid transactions, the data from the input record is moved as a unit to the output record, the date is moved to the output record and the record is written. NOTE: When writing to a disk there is NO after advancing clause - that clause is only for printed reports. If the record is invalid (the error indicator contains YES), then the ELSE is processed and 1 is added to the number of invalid transactions. NOTE: The errors that were found have already been written so no error writing is needed.

16 Please read the edit notes and analyze the program called payedit.cbl in detail to assure your understanding. conclusion


Download ppt "Edit Programs Please use speaker notes for additional information. Example: payedit.cbl payedit.cbl."

Similar presentations


Ads by Google