Random update Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment.
Advertisements

2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
Final Total Lines in COBOL Please be sure you can see the speaker notes - they contain additional information!
Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.
Chapter 15 Indexed Sequential Files. Disk File Organization File is collection of records Three major ways records stored or organized on disk - Sequential.
Screen Section Please use speaker notes for additional information!
Processing with VSAM Files Please use speaker notes for additional information!
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Two and three dimension tables Please use speaker notes for additional information!
VSAM KSDS and COBOL Department of Computer Science Northern Illinois University August 2005 Some of the illustrations are from VSAM: Access Method Services.
15-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Chapter 15 Relative Files.  File organization that converts key field to actual disk address to find location of record No need to look up disk address.
Relative Files.. Creating a Relative File $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. CreateRelativeFromSeq. * Creates a Relative file.
Structured COBOL Programming, Stern & Stern, 9th edition
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
Chapter 13 Sequential File Processing. Master Files Set of files used to store companies data in areas like payroll, inventory Usually processed by batch.
Modifications to program Addda.cbl Please use speaker notes for additional information!
History COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. COBOL was first proposed in 1959 by the Conference.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
COBOL Cobol is one of the most robust language in the software field, so far Cobol turned 50, in 2009 Cobol has stood the test of time Common Business.
Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone:
Totals on the Screen Please use speaker notes for additional information!
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
The DATA DIVISION Chapter 3. COBOL Data Organization Field - group of characters forming a meaningful unit or basic fact –Characters in a name or digits.
3-1 Chapter 3. To familiarize you with  Ways in which data is organized in COBOL  Rules for forming data-names  Defining input and output files in.
3-1 The DATA DIVISION Chapter Chapter Objectives To familiarize you with Systems design considerations Ways in which data is organized Rules for.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File.
Array - adding to array at run time Please see speaker notes for additional information!
Basic & Advanced Reporting in TIMSNT ** Part Two **
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Indexed and Relative File Processing
Edit Programs Please use speaker notes for additional information. Example: payedit.cbl payedit.cbl.
13-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Sequential Files Chapter 13. Master Files Set of files used to store companies data in areas like payroll, inventory Set of files used to store companies.
Statement Syntax1 THE SELECT STATEMENT Purpose: designates a file and points to its physical location Syntax Definition : SELECT file-name-1 ASSIGN TO.
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
Explanation of SAMPLEIF (if88in1.cbl or if88in1.html) Please use speaker notes for additional information!
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
COBOL Screens Please use speaker notes for additional information!
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
1 Work Orders. 2 Generating a Work Order There are two methods to generating a Work Order in the WYNNE STSTEM. First method: Option 11 – 12 – 13 * Open.
VSAM ESDS and RRDS Department of Computer Science Northern Illinois University September 2005 Some of the illustrations are from VSAM: Access Method Services.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Sequential Processing to Update a File Please use speaker notes for additional information!
Sequential Update Assignment Notes Please use speaker notes for additional information!
General Introduction Algorithms. Let’s write a program  A program is a collection of statements written in a language the computer understands.  A computer.
Any Questions?.
Chapter 3 The DATA DIVISION.
Agenda Test next Week! SI or no SI? File Update Techniques – Review.
Please use speaker notes for additional information!
Programming Logic and Design Fourth Edition, Comprehensive
An Introduction to Structured Program Design in COBOL
Please use speaker notes for additional information!
Using screens and adding two numbers - addda.cbl
2 file sequential matching with multiple records allowed on file 2
Presentation transcript:

Random update Please use speaker notes for additional information!

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

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

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

Random Update Logic

MASTER MASTER (before) … … … … 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. 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 … … … … 512… 121 (trail)

MASTER MASTER (before) … … … … 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 an add, the new record is written on the Master using a WRITE. A trail of the add is also made … … … … 512… 121 (trail) 124 (trail)

MASTER MASTER (before) … … … … 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 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 … … … … 512… 121 (trail) 124 (trail) 222 (trail)

MASTER MASTER (before) … … … … 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 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 … … … … 512… 121 (trail) 124 (trail) 222 (trail)

MASTER MASTER (before) … … … … 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 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 … … 345… … 512… 121 (trail) 124 (trail) 222 (trail) 333 (trail)

MASTER MASTER (before) … … … … 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 change, no change is made to the master. A report of the change error is also made … … 345… … 512… 121 (trail) 124 (trail) 222 (trail) 333 (trail) 350 (error)

MASTER MASTER (before) … … … … 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 … … 345… … 512… 121 (trail) 124 (trail) 222 (trail) 333 (trail) 350 (error) 444 (error)

MASTER MASTER (before) … … … … 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 … … 345… … 512… 121 (trail) 124 (trail) 222 (trail) 333 (trail) 350 (error) 444 (error) 450 (error)

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.

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.

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.

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

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 999V TPRICE. 15 FILLER PIC XXXX. 15 LAST-PRICE PIC X. 10 RDF-TPRICE REDEFINES TPRICE PIC 999V TCODE PIC X. TID and TCODE are the two fields used in determining the processing to be done.

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 FILLER PIC X(3). 05 PRICE-PR PIC $ZZZ FILLER PIC X(3). 05 MSG-PR PIC X(22). 05 FILLER PIC XX.

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 999V 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.

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.

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.

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

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.

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).

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

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

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.