Presentation is loading. Please wait.

Presentation is loading. Please wait.

Random update Please use speaker notes for additional information!

Similar presentations


Presentation on theme: "Random update Please use speaker notes for additional information!"— Presentation transcript:

1 Random update Please use speaker notes for additional information!

2 EDIT: The transactions that will be used in the update must be as error free as possible to prevent corrupting the master file. To assure the integrity of the data, the transactions can be processed in an edit program and only valid transactions should be allowed to update the master file. The output of the edit file includes the valid (good) transaction file which will be processed in the next step. Frequently transaction come in via a screen and the analyst decides that the editing will be incorporated in the update program to provide interactivity. UPDATE: The update program uses the valid transaction file to update the master file itself. No new master file is created, the changes are made to the existing master file. Reports become extremely important to provide a paper trail of records processed and also a trail of records that contained errors and were not processed. In a maintenance update there can be add, change or delete transactions so records can be added to the existing master, changed on the existing master, or deleted from the existing master. The method of physically handling deletes varies depending on the version of COBOL being used.. The update program completes the updating maintenance cycle. Note that back up does not happen automatically in a random update. Copies of the master file and the transaction file need to be made. Frequently the master is backed up directly after the update. It absolutely has to be backed up before the next update. Random Update Update

3 Data Edit Program Valid Trans Errors can be put on disk, printed, interactively corrected or any combination of solutions. Master File Update Program Errors Note: Errors can be written to disk, printed, interactively corrected or any combination of solutions. An optional paper trail can also be produced on disk, paper or another medium. Trail Systems flowchart

4 Transactions Master Random Update Program If transactions are coming in as a group from a disk file, they should be edited. If the transactions are coming from a screen, interactive editing should take place in the Random Update Program. The user will frequently try to interactively handle errors on the screen. Screen Transactions OR Errors Trail Random Update

5 Random Update Logic

6 MASTER MASTER (before) 121... 123… 222... 234… 333... 345… 444... 456… 512…TRANSACTIONS 121…C 124…A 222…C 333…D 350… C 444… A 450… D 999... MASTER MASTER (after) ERROR /TRAIL REPORT Random Update The transaction is read and then there is an attempt made to find the matching record identification number on the Master. If a match is found, changes are made to the record on the master and the record is put back on the master with a REWRITE. A trail of the change is also made. 121... 123… 222... 234… 333... 345… 444... 456… 512… 121 (trail)

7 MASTER MASTER (before) 121... 123… 222... 234… 333... 345… 444... 456… 512…TRANSACTIONS 121…C 124…A 222…C 333…D 350… C 444… A 450… D 999... MASTER MASTER (after) ERROR /TRAIL REPORT Random Update The transaction is read and then there is an attempt made to find the matching record identification number on the Master. Since no match is found and this is an add, the new record is written on the Master using a WRITE. A trail of the add is also made. 121... 123… 124... 222... 234… 333... 345… 444... 456… 512… 121 (trail) 124 (trail)

8 MASTER MASTER (before) 121... 123… 222... 234… 333... 345… 444... 456… 512…TRANSACTIONS 121…C 124…A 222…C 333…D 350… C 444… A 450… D 999... MASTER MASTER (after) ERROR /TRAIL REPORT Random Update The transaction is read and then there is an attempt made to find the matching record identification number on the Master. Since a match is found and this is an change, the change is made and the changed Master replaces the original record on the master using the REWRITE. A trail of the change is also made. 121... 123… 124... 222... 234… 333... 345… 444... 456… 512… 121 (trail) 124 (trail) 222 (trail)

9 MASTER MASTER (before) 121... 123… 222... 234… 333... 345… 444... 456… 512…TRANSACTIONS 121…C 124…A 222…C 333…D 350… C 444… A 450… D 999... MASTER MASTER (after) ERROR /TRAIL REPORT Random Update The transaction is read and then there is an attempt made to find the matching record identification number on the Master. Since a match is found and this is an change, the change is made and the changed Master replaces the original record on the master using the REWRITE. A trail of the change is also made. 121... 123… 124... 222... 234… 333... 345… 444... 456… 512… 121 (trail) 124 (trail) 222 (trail)

10 MASTER MASTER (before) 121... 123… 222... 234… 333... 345… 444... 456… 512…TRANSACTIONS 121…C 124…A 222…C 333…D 350… C 444… A 450… D 999... MASTER MASTER (after) ERROR /TRAIL REPORT Random Update The transaction is read and then there is an attempt made to find the matching record identification number on the Master. Since a match is found and this is an delete, the delete is made by removing the record from the Master using the DELETE verb. A trail of the delete is also made. 121... 123… 124... 222... 234… 345… 444... 456… 512… 121 (trail) 124 (trail) 222 (trail) 333 (trail)

11 MASTER MASTER (before) 121... 123… 222... 234… 333... 345… 444... 456… 512…TRANSACTIONS 121…C 124…A 222…C 333…D 350… C 444… A 450… D 999... MASTER MASTER (after) ERROR /TRAIL REPORT Random Update The transaction is read and then there is an attempt made to find the matching record identification number on the Master. Since no match is found and this is a change, no change is made to the master. A report of the change error is also made. 121... 123… 124... 222... 234… 345… 444... 456… 512… 121 (trail) 124 (trail) 222 (trail) 333 (trail) 350 (error)

12 MASTER MASTER (before) 121... 123… 222... 234… 333... 345… 444... 456… 512…TRANSACTIONS 121…C 124…A 222…C 333…D 350… C 444… A 450… D MASTER MASTER (after) ERROR /TRAIL REPORT Random Update The transaction is read and then there is an attempt made to find the matching record identification number on the Master. Since a match is found and this is a add, no change is made to the master. A report of the add error is also made. 121... 123… 124... 222... 234… 345… 444... 456… 512… 121 (trail) 124 (trail) 222 (trail) 333 (trail) 350 (error) 444 (error)

13 MASTER MASTER (before) 121... 123… 222... 234… 333... 345… 444... 456… 512…TRANSACTIONS 121…C 124…A 222…C 333…D 350… C 444… A 450… D MASTER MASTER (after) ERROR /TRAIL REPORT Random Update The transaction is read and then there is an attempt made to find the matching record identification number on the Master. Since no match is found and this is a delete, no change is made to the master. A report of the delete error is also made. 121... 123… 124... 222... 234… 345… 444... 456… 512… 121 (trail) 124 (trail) 222 (trail) 333 (trail) 350 (error) 444 (error) 450 (error)

14 Indexed file maintenance ADD Indexed file maintenance ADD WRITE record-name INVALID KEY … NOT INVALID KEY … END-WRITE When writing to an INDEXED file with RANDOM access, the INVALID KEY clause will be triggered if you attempt to write a duplicate record and the record will not be written. Therefore an ADD can be made without prior checking, any trail of the successful ADD can be put into the NOT INVALID KEY clause.

15 Indexed file maintenance CHANGE Indexed file maintenance CHANGE REWRITE record-name INVALID KEY … NOT INVALID KEY … END-WRITE The REWRITE statement replaces an existing record on the file. If you have made changes to a record in memory based on information from a transaction, these changes would now be written in place of the original record because of the REWRITE. A rewrite can change everything in the record except for the primary/record key field. An attempt to put the record back with a different key will trigger the INVALID KEY clause.

16 Indexed file maintenance DELETE Indexed file maintenance DELETE DELETE file-name INVALID KEY … NOT INVALID KEY … END-WRITE The DELETE statement deletes a record from the file. In the record does not exist, the INVALID KEY clause is triggered. IF the DELETE is successful the NOT INVALID KEY clause can be used. Note that a DELETE can be issue without a prior READ, however then the DELETE will just happen without any chance to view the record and make sure that it should be deleted. Many programmers read, check the record be either displaying it for user confirmation or checking to make sure that a second field such as name on the transaction is the same as the name on the record. This is a prudent thing to do to prevent deleting of a record because the wrong identification number was keyed in.

17 IDENTIFICATION DIVISION. PROGRAM-ID. RANUPDT. AUTHOR. GROCER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. SELECT MASTER-FILE ASSIGN TO "C:\PCOBWIN\VSAM\MSTRVSAM.DAT" ORGANIZATION IS INDEXED ACCESS IS RANDOM RECORD KEY IS MID. SELECT TRAN-FILE ASSIGN TO "C:\PCOBWIN\VSAM\TRANSN.DAT". SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD MASTER-FILE DATA RECORD IS MASTER-REC. 01 MASTER-REC. 05 MID PIC 9(3). 05 FILLER PIC X(33). myranupd.cbl

18 FD TRAN-FILE DATA RECORD IS TRAN-REC. 01 TRAN-REC. 05 TRAN-DATA. 10 TID PIC 9(3). 10 TITEM-NAME. 15 FILLER PIC X(19). 15 LAST-ITEM-NAME PIC X. 10 TVENDOR-CODE. 15 FILLER PIC XX. 15 LAST-VENDOR-CODE PIC X. 10 TCOST. 15 FILLER PIC XXXX. 15 LAST-COST PIC X. 10 RDF-TCOST REDEFINES TCOST PIC 999V99. 10 TPRICE. 15 FILLER PIC XXXX. 15 LAST-PRICE PIC X. 10 RDF-TPRICE REDEFINES TPRICE PIC 999V99. 05 TCODE PIC X. TID and TCODE are the two fields used in determining the processing to be done.

19 myranupd.cbl FD PRINT-FILE DATA RECORD IS PRINTZ. 01 PRINTZ. 05 FILLER PIC X. 05 ID-PR PIC 9(3). 05 FILLER PIC X(3). 05 ITEM-NAME-PR PIC X(20). 05 FILLER PIC X(3). 05 VENDOR-CODE-PR PIC XXX. 05 FILLER PIC X(3). 05 COST-PR PIC $ZZZ.99. 05 FILLER PIC X(3). 05 PRICE-PR PIC $ZZZ.99. 05 FILLER PIC X(3). 05 MSG-PR PIC X(22). 05 FILLER PIC XX.

20 WORKING-STORAGE SECTION. 01 MASTER-REC-WS. 05 ID-WS PIC 9(3). 05 ITEM-NAME-WS PIC X(20). 05 VENDOR-CODE-WS PIC XXX. 05 COST-WS PIC 999V99. 05 PRICE-WS PIC 999V99. myranupd.cbl This is the definition of the master record in working storage. This is the area where the data will be manipulated.

21 PROCEDURE DIVISION. MAINLINE. PERFORM A-100-INITIALIZE. PERFORM B-100-PROCESS. PERFORM C-100-WRAPUP. STOP RUN. A-100-INITIALIZE. OPEN I-O MASTER-FILE INPUT TRAN-FILE OUTPUT PRINT-FILE. B-100-PROCESS. PERFORM U-100-READ-TRAN-FILE. PERFORM B-200-LOOP UNTIL TID = 999. myranupd.cbl Because the master file will be read and written on, it must be opened for both input and output. That means it must be opened as an I-O file. Processing is transaction driven. That means that when there are no more transactions on the transaction file processing will be terminated. The read of the transaction file moves 999 to TID when end of file is reached. Because processing is transaction driven, the transaction is read and then used to find the correct master or confirm the absence of a master.

22 myranupd.cbl B-200-LOOP. MOVE SPACES TO PRINTZ. MOVE TID TO MID. READ MASTER-FILE INVALID KEY PERFORM B-300-NO-MSTR-THERE NOT INVALID KEY PERFORM B-310-MSTR-THERE. PERFORM U-100-READ-TRAN-FILE. B-300-NO-MSTR-THERE. IF TCODE = "A" PERFORM B-420-ADD-ROUT ELSE IF TCODE = "C" PERFORM B-440-CHANGE-ERROR-ROUT ELSE PERFORM B-450-DELETE-ERROR-ROUT. B-310-MSTR-THERE. MOVE MASTER-REC TO MASTER-REC-WS. IF TCODE = "C" PERFORM B-400-CHANGE-ROUT ELSE IF TCODE = "D" PERFORM B-410-DELETE-ROUT ELSE PERFORM B-430-ADD-ERROR-ROUT. Establish the key by moving TID to MID and then read the master record to locate the record. Read the next transaction - remember transactions control the processing. If the read is not successful, invalid key will be triggered and B-300-NO-MSTR-THERE will be processed. If the read is successful, not invalid key will be triggered and B-310-MSTR- THERE will be processed. If the read was unsuccessful the only valid transaction is an ADD. It the read was successful, the CHANGE and the DELETE are valid transactions. The ADD is an invalid transaction.

23 B-400-CHANGE-ROUT. MOVE SPACES TO PRINTZ. MOVE ID-WS TO ID-PR. MOVE ITEM-NAME-WS TO ITEM-NAME-PR. MOVE VENDOR-CODE-WS TO VENDOR-CODE-PR. MOVE COST-WS TO COST-PR. MOVE PRICE-WS TO PRICE-PR. MOVE "BEFORE CHANGES" TO MSG-PR. WRITE PRINTZ AFTER ADVANCING 2 LINES. IF TITEM-NAME NOT = SPACES IF LAST-ITEM-NAME = "-" MOVE SPACES TO ITEM-NAME-WS, ITEM-NAME-PR ELSE MOVE TITEM-NAME TO ITEM-NAME-WS, ITEM-NAME-PR. IF TVENDOR-CODE NOT = SPACES IF LAST-VENDOR-CODE = "-" MOVE SPACES TO VENDOR-CODE-WS, VENDOR-CODE-PR ELSE MOVE TVENDOR-CODE TO VENDOR-CODE-WS, VENDOR-CODE-PR. myranupd.cbl

24 IF TCOST = SPACES OR RDF-TCOST = 0 NEXT SENTENCE ELSE IF LAST-COST = "-" MOVE 0 TO COST-WS, COST-PR ELSE MOVE RDF-TCOST TO COST-WS, COST-PR. IF TPRICE = SPACES OR RDF-TPRICE = 0 NEXT SENTENCE ELSE IF LAST-PRICE = "-" MOVE 0 TO PRICE-WS, PRICE-PR ELSE MOVE RDF-TPRICE TO PRICE-WS, PRICE-PR. REWRITE MASTER-REC FROM MASTER-REC-WS INVALID KEY MOVE "CHANGES REJECTED" TO MSG-PR NOT INVALID KEY MOVE "AFTER CHANGES" TO MSG-PR. WRITE PRINTZ AFTER ADVANCING 1 LINES. myranupd.cbl Note that the REWRITE is taking what is in MASTER-REC-WS and writing it out on MASTER-REC. Notice also that REWRITE uses the record name.

25 B-410-DELETE-ROUT. MOVE SPACES TO PRINTZ. MOVE MID TO ID-PR. MOVE ITEM-NAME-WS TO ITEM-NAME-PR. MOVE VENDOR-CODE-WS TO VENDOR-CODE-PR. MOVE COST-WS TO COST-PR. MOVE PRICE-WS TO PRICE-PR. DELETE MASTER-FILE INVALID KEY MOVE "DELETED REJECTED" TO MSG-PR NOT INVALID KEY MOVE "RECORD DELETED" TO MSG-PR. WRITE PRINTZ AFTER ADVANCING 2 LINES. myranupd.cbl The DELETE writes the file (the FD name).

26 B-420-ADD-ROUT. MOVE TRAN-DATA TO MASTER-REC. MOVE TID TO ID-PR. MOVE TITEM-NAME TO ITEM-NAME-PR. MOVE TVENDOR-CODE TO VENDOR-CODE-PR. MOVE RDF-TCOST TO COST-PR. MOVE RDF-TPRICE TO PRICE-PR. WRITE MASTER-REC INVALID KEY MOVE "ADD REJECTED" TO MSG-PR NOT INVALID KEY MOVE "RECORD ADDED" TO MSG-PR. WRITE PRINTZ AFTER ADVANCING 2 LINES. The WRITE statement uses the record name as always. myranupd.cbl

27 B-430-ADD-ERROR-ROUT. MOVE SPACES TO PRINTZ. MOVE TID TO ID-PR. MOVE TITEM-NAME TO ITEM-NAME-PR. MOVE TVENDOR-CODE TO VENDOR-CODE-PR. MOVE RDF-TCOST TO COST-PR. MOVE RDF-TPRICE TO PRICE-PR. MOVE "**RECORD NOT ADDED**" TO MSG-PR. WRITE PRINTZ AFTER ADVANCING 2 LINES. B-440-CHANGE-ERROR-ROUT. MOVE SPACES TO PRINTZ. MOVE TID TO ID-PR. MOVE TITEM-NAME TO ITEM-NAME-PR. MOVE TVENDOR-CODE TO VENDOR-CODE-PR. MOVE RDF-TCOST TO COST-PR. MOVE RDF-TPRICE TO PRICE-PR. MOVE "**RECORD NOT CHANGED**" TO MSG-PR. WRITE PRINTZ AFTER ADVANCING 2 LINES. B-450-DELETE-ERROR-ROUT. MOVE SPACES TO PRINTZ. MOVE TID TO ID-PR. MOVE "**RECORD NOT DELETED**" TO MSG-PR. WRITE PRINTZ AFTER ADVANCING 2 LINES. myranupd.cbl

28 C-100-WRAPUP. CLOSE MASTER-FILE TRAN-FILE PRINT-FILE. U-100-READ-TRAN-FILE. READ TRAN-FILE AT END MOVE 999 TO TID. myranupd.cbl When end of file is reached on the transaction file, 999 is moved to TID. This will terminate processing.


Download ppt "Random update Please use speaker notes for additional information!"

Similar presentations


Ads by Google