Chapter 13: Sequential File Processing:
SYSTEMS OVERVIEW OF SEQUENTIAL FILE PROCESSING:
A master file is the major collection of data pertaining to a specific
application.
Companies will have master files in application areas such as payroll, accounts receivable, accounts payable.
A master file also could be a dump from the table.
Companies will have master files in application areas such as payroll, accounts receivable, accounts payable.
A master file also could be a dump from the table.
A sequential file is one that is processed by reading the first record,
operating on it,then reading the second record, operating on it, and so on.
If a file is organized for sequential processing, it must always be read in sequence.
If a file is organized for sequential processing, it must always be read in sequence.
When tapes were first introduced, they had to be processed
sequentially, which, as you will see, is a serious limitation on their
capabilities and one major reason why they have been phased out.
If a file is always to be accessed in some sequence, it is simpler to
use sequential file processing.
Different departments may need the same file to be sorted in a specific
order. Example: One system might need a file to be sorted in sequence of
employee_no and other might require it sorted in dept_no.
A sequential file can be sorted into any sequence using a field on the file.
A sequential file can be sorted into any sequence using a field on the file.
TYPICAL MASTER FILE PROCEDURES: A
SYSTEMSOVERVIEW
When a business system is computerized, the systems analyst and
programmer decide whether the master file is to be organized for sequential
processing or for random processing.
As noted, sequential organization is used for files that are always processed in some sequence.
If a file needs to be accessed randomly, it must have a method of organization that permits random access.
As noted, sequential organization is used for files that are always processed in some sequence.
If a file needs to be accessed randomly, it must have a method of organization that permits random access.
Designing a Master File for
Sequential Processing in Batch Mode
The following are elements to consider when designing a master file:
1. The first field or fields in the record should be key fields that
uniquely identify the record.
2. Where possible, key fields should consist of numbers
3. Secondary key fields (e.g., Name) should follow primary key fields in a record.
4. Fields should appear in a master file in order of importance (e.g., Employee Name and Address before Birth Date, etc.).
5. Be sure that fields are large enough to accommodate the data
6.Use coded fields where possible to save space (e.g., codes are used for Marital Status, Insurance Plan Option, etc.).
2. Where possible, key fields should consist of numbers
3. Secondary key fields (e.g., Name) should follow primary key fields in a record.
4. Fields should appear in a master file in order of importance (e.g., Employee Name and Address before Birth Date, etc.).
5. Be sure that fields are large enough to accommodate the data
6.Use coded fields where possible to save space (e.g., codes are used for Marital Status, Insurance Plan Option, etc.).
Creating a Master File for Sequential
Processing in Batch Mode:
When a new system is implemented, or used for the first time, a master
file must be initially created.
This procedure can be performed by entering all master file data interactively using a keyboard or other data entry device.
Creating a master file is a one-time procedure.
The primary objective of a program that creates a master file is ensuring data integrity.
A master file is only useful if it contains valid and reliable data; hence, a creation program must be designed so that it minimizes input errors.
This procedure can be performed by entering all master file data interactively using a keyboard or other data entry device.
Creating a master file is a one-time procedure.
The primary objective of a program that creates a master file is ensuring data integrity.
A master file is only useful if it contains valid and reliable data; hence, a creation program must be designed so that it minimizes input errors.
Creating a Transaction File for
Sequential Processing in Batch Mode:
For sequential processing in batch mode, change records are stored in a
file referred to as a transaction file, which is also typically stored on disk.
File design considerations, as specified for master files, should be applied to the transaction file as well. Also, the transaction file should be validated to ensure data integrity.
File design considerations, as specified for master files, should be applied to the transaction file as well. Also, the transaction file should be validated to ensure data integrity.
Updating a Master File for Sequential
Processing in Batch Mode:
The process of making a master file current is referred to as updating.
With sequential file processing in batch mode, the master file is updated by incorporating the changes from the transaction records.
Sequential batch updates process transaction records that are stored in sequence in a file, rather than entered randomly and processed interactively.
With sequential file processing in batch mode, the master file is updated by incorporating the changes from the transaction records.
Sequential batch updates process transaction records that are stored in sequence in a file, rather than entered randomly and processed interactively.
Creating a Master file:
Normally we would have a interactive program to write to a master file.
On my system where i can use only run in batch following is an example of cobol program.
On my system where i can use only run in batch following is an example of cobol program.
JCL:
*****************************
Top of Data ******************************
//TESTJCL1
JOB (EWDS),'TEST JCL',NOTIFY=&SYSUID
//DWJ030C0
EXEC PGM=TESTPGM1
//STEPLIB
DD DSN=CMN.EDWS.STGO.#001621.LOD,DISP=SHR
//MINPUT DD
DSN=SM017R.TESTFILE.MASTER2,DISP=(OLD,CATLG,CATLG),
//
DCB=(LRECL=80,RECFM=FB,BLKSIZE=)
//SYSIN DD *
12
SUKUL
MAHADIK
35000
Y
30
DUSHYANT
JADAV
67000
Y
40
MAHENDRA
GAREWAL
20000
N
000022
/*
******
**************************** Bottom of Data ****************************
PROGRAM:
******
***************************** Top of Data ***********************
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. TESTPGM1.
000300 AUTHOR. SUKUL MAHADIK.
000400 ENVIRONMENT DIVISION.
000500 CONFIGURATION SECTION.
000600 SOURCE-COMPUTER. IBM-370.
000700 OBJECT-COMPUTER. IBM-370.
000800 INPUT-OUTPUT SECTION.
000900 FILE-CONTROL.
001000 * SELECT STATEMENT STARTS IN DIVISION
B
001100 SELECT MASTER-FILE ASSIGN TO
MINPUT
001200 ORGANIZATION IS SEQUENTIAL
001300 FILE STATUS IS
WS-MASTER-FILE-STATUS.
001400 * NOTE NO - BETWEEN FILE AND
STATUS
001500 DATA DIVISION.
001600 FILE SECTION.
001700 FD MASTER-FILE
001800 * RECORDING,LABEL,BLOCK,RECORD SHOULD
NOT BEGIN IN AREA A
001900 RECORDING MODE IS F
002000 LABEL RECORDS ARE STANDARD
002100 BLOCK CONTAINS 0 RECORDS
002200 RECORD CONTAINS 80
CHARACTERS.
002300 01 MASTER-REC.
002400 05 SOC-SEC-NO PIC 9(9).
002500 05 LAST-NAME PIC X(20).
002600 05 FIRST-NAME PIC X(10).
002700 05 SALARY PIC 9(6).
002800 WORKING-STORAGE SECTION.
002900 01
WS-MASTER-FILE-STATUS PIC
XX.
003000 01
KEYED-DATA.
003100 05 SOC-SEC-NO-IN PIC 9(9).
003200 05 LAST-NAME-IN PIC X(20).
003300 05 FIRST-NAME-IN PIC X(10).
003400 05 SALARY-IN PIC 9(6).
003500 05 MOREIP PIC X(1).
003600 01
IS-DATA-OK PIC X(1) VALUE 'Y'.
003700 88 DATA-OK VALUE 'Y'.
003800 88 DATA-NOT-OK VALUE 'N'.
003900 01
MORE-DATA PIC X(1) VALUE 'Y'.
004000 PROCEDURE DIVISION.
004100 100-MAIN-MODULE.
004200 DISPLAY 'PROGRAM STARTED'
004300 PERFORM 200-INITIALIZATION
004400 PERFORM 300-ACCEPT-INPUT UNTIL
MORE-DATA IS EQUAL TO 'N'
004500 STOP RUN.
004600 200-INITIALIZATION.
004700 OPEN OUTPUT MASTER-FILE.
004800 300-ACCEPT-INPUT.
004900 MOVE 'N' TO MORE-DATA
005000 ACCEPT SOC-SEC-NO-IN
005100 ACCEPT LAST-NAME-IN
005200 ACCEPT FIRST-NAME-IN
005300 ACCEPT SALARY-IN
005400 ACCEPT MOREIP
005500 DISPLAY SOC-SEC-NO-IN
005600 DISPLAY LAST-NAME-IN
005700 DISPLAY FIRST-NAME-IN
005800 DISPLAY SALARY-IN
005900 DISPLAY MOREIP
006000 PERFORM 400-VALIDATION
006100 IF DATA-OK
006200 MOVE SOC-SEC-NO-IN TO
SOC-SEC-NO
006300 MOVE LAST-NAME-IN TO
LAST-NAME
006400 MOVE FIRST-NAME-IN TO
FIRST-NAME
006500 MOVE SALARY-IN TO SALARY
006600 WRITE MASTER-REC
006700 DISPLAY 'RECORD INSERTED.'
006800 END-IF
006900 MOVE MOREIP TO MORE-DATA
007000 DISPLAY MORE-DATA.
007100 400-VALIDATION.
007200 IF LAST-NAME-IN = SPACE OR FIRST-NAME-IN = SPACE
007300 DISPLAY 'NAMES INCORRECT.'
007400 MOVE 'N' TO IS-DATA-OK
007500 END-IF.
******
**************************** Bottom of Data ****************************
|
SEQUENTIAL FILE UPDATING—CREATING A NEW MASTER
FILE USING A PREVIOUS MASTER FILE AND A TRANSACTION FILE:
The files used:
Master files that have been designed and created for sequential
processing can be updated by reading in the master file along with a
transaction file and creating a new master file.
This means that the sequential update procedure uses three files.
Most often, a fourth print file that produces a control listing or audit trail
This means that the sequential update procedure uses three files.
Most often, a fourth print file that produces a control listing or audit trail
Input Master file:
The input master file is current through the previous updating period.
That is, if updates are performed weekly, the input master file is the file that was created the previous week as the master.
Say OLD-MASTER.
The input master file is current through the previous updating period.
That is, if updates are performed weekly, the input master file is the file that was created the previous week as the master.
Say OLD-MASTER.
The transaction file:
The transaction file contains data to be used for updating the master file that we call OLD-MASTER.
The input transaction file contains all changes that have occurred since OLD-MASTER was created.
Say TRANS-FILE.
The transaction file contains data to be used for updating the master file that we call OLD-MASTER.
The input transaction file contains all changes that have occurred since OLD-MASTER was created.
Say TRANS-FILE.
The Output Master File:
The output master file becomes the new master as a result of the updating procedure.
The output master file will integrate data from the OLD-MASTERand the TRANS-FILE.
Say NEW-MASTER.
The output master file becomes the new master as a result of the updating procedure.
The output master file will integrate data from the OLD-MASTERand the TRANS-FILE.
Say NEW-MASTER.
Transcation from the transfile must be incorporated into master to make
it current.
The NEW-MASTER will include all OLD-MASTERdata in addition to the changes stored on the TRANS-FILE that have occurred since the last update.
The NEW-MASTER will become OLD-MASTER during the next cycle.
The NEW-MASTER will include all OLD-MASTERdata in addition to the changes stored on the TRANS-FILE that have occurred since the last update.
The NEW-MASTER will become OLD-MASTER during the next cycle.
In a sequential master file, all records are in sequence by a key
field, such as account number, Social Security number, or part number,
depending on the type of master file.
This key field uniquely identifies each master record. We compare the key field in the master to the same key field in the transaction file to determine if the master record is to be updated.
Very importantly this comparison requires both files to be in sequence by the key field.
This key field uniquely identifies each master record. We compare the key field in the master to the same key field in the transaction file to determine if the master record is to be updated.
Very importantly this comparison requires both files to be in sequence by the key field.
THE PROCEDURES USED FOR SEQUENTIAL UPDATES:
Let us consider the updating of a sequential master accounts receivable
file.
Key field for master file: account number(M-ACCT-NO)
All records in OLD-MASTER is sequenced by M-ACCT-NO.
Key field for master file: account number(M-ACCT-NO)
All records in OLD-MASTER is sequenced by M-ACCT-NO.
Key field for transaction file: account number(T-ACCT-NO)
All records in TRANS-FILE is sequenced by T-ACCT-NO.
All records in TRANS-FILE is sequenced by T-ACCT-NO.
Each transaction record contains the totalamount transacted during the
current period for a specific master record.
Hence, there will be one transaction record for each master record to be updated.
(multiple transaction records, We will learn later)
Hence, there will be one transaction record for each master record to be updated.
(multiple transaction records, We will learn later)
Keep in mind that records within OLD-MASTER are in sequence by
M-ACCT-NO and that records within TRANS-FILE are in sequence by T-ACCT-NO.
Records must be in sequence by key field so that when we compare key fields we can determine if a given master record is to be updated.
Records must be in sequence by key field so that when we compare key fields we can determine if a given master record is to be updated.
Following is the program that could do this:
*****************************
Top of Data ******************************
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTPGM2.
*PROGRAM ID IDENTIFIES THE PROGRAM
AUTHOR. SUKUL MAHADIK.
*AUTHOR IS NOT COMPULSORY. BUT IS A
GOOD COMMENT
ENVIRONMENT DIVISION.
*ENVIRONMENT DIVISION HAS CONFIG
SECTIONS AND I-O SECTION
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-370.
OBJECT-COMPUTER. IBM-370.
INPUT-OUTPUT SECTION.
*FILE-CONTROL IS A PARAGRAPH
FILE-CONTROL.
* SELECT STATEMENT STARTS IN DIVISION
B
SELECT OLD-MASTER ASSIGN TO
OMASTER
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS
WS-OLD-MASTER-FILE-STATUS.
SELECT NEW-MASTER ASSIGN TO
NMASTER
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS
WS-NEW-MASTER-FILE-STATUS.
SELECT TRANS-FILE ASSIGN TO
TRANFILE
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS
WS-TRANSFILE-FILE-STATUS.
* NOTE NO - BETWEEN FILE AND
STATUS
DATA DIVISION.
FILE SECTION.
FD OLD-MASTER
* RECORDING,LABEL,BLOCK,RECORD SHOULD
NOT BEGIN IN AREA A
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80 CHARACTERS.
01 OLD-MASTER-REC.
05 OM-ACCT-NO PIC 9(9).
05 OM-AMOUNT PIC 9(4)V99.
05 FILLER
PIC X(65).
FD NEW-MASTER
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80
CHARACTERS.
01 NEW-MASTER-REC.
05 NM-ACCT-NO PIC 9(9).
05 NM-AMOUNT PIC 9(4)V99.
05 FILLER
PIC X(65).
FD TRANS-FILE
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80
CHARACTERS.
01 TRANS-REC.
05 TR-ACCT-NO PIC 9(9).
05 TR-AMOUNT PIC 9(4)V99.
05 FILLER
PIC X(65).
WORKING-STORAGE SECTION.
01
WS-OLD-MASTER-FILE-STATUS PIC XX.
01
WS-NEW-MASTER-FILE-STATUS PIC XX.
01
WS-TRANSFILE-FILE-STATUS PIC XX.
* END OF FILE INDICATOR
01
WS-OLD-MASTER-EOF PIC X VALUE
'N'.
01
WS-TRANSFILE-EOF PIC X VALUE 'N'.
* FILE STATUS IS ALWAYS 2
CHARACTERS
PROCEDURE DIVISION.
100-MAIN-MODULE.
DISPLAY 'PROGRAM STARTED'
PERFORM 200-INITIALIZATION
PERFORM 400-READ-OLD-MASTER
DISPLAY 'OM-ACCT-NO:'
OM-ACCT-NO
PERFORM 500-READ-TRANSFILE
DISPLAY 'TR-ACCT-NO:' TR-ACCT-NO
PERFORM 300-COMPARE
UNTIL WS-OLD-MASTER-EOF='Y'
AND
WS-TRANSFILE-EOF='Y'
* ITS IS RECOMMENED THAT WE HAVE A
SPACE BETWEEN FIELD NAME
* AND = SIGN AND ALSO BETWEEN = AND
THE LITERAL.
* COMPILER GENERATES A WARNING IF WE
DONT DO SO.
STOP RUN.
200-INITIALIZATION.
OPEN INPUT OLD-MASTER
OPEN OUTPUT NEW-MASTER
OPEN INPUT TRANS-FILE.
300-COMPARE.
DISPLAY 'COMPARING RECORDS.'.
EVALUATE TRUE
WHEN TR-ACCT-NO <
OM-ACCT-NO
PERFORM
600-NEW-ACCT
WHEN TR-ACCT-NO =
OM-ACCT-NO
PERFORM 700-UPDATE
WHEN TR-ACCT-NO >
OM-ACCT-NO
PERFORM
800-NO-UPDATE
END-EVALUATE.
600-NEW-ACCT.
MOVE TRANS-REC TO
NEW-MASTER-REC
WRITE NEW-MASTER-REC
PERFORM 500-READ-TRANSFILE.
/*Once we
find a new record from the transaction file we move on and read the next
record from the transaction file*/
700-UPDATE.
MOVE OLD-MASTER-REC TO
NEW-MASTER-REC
DISPLAY 'OM-AMOUNT:'
OM-AMOUNT
DISPLAY 'TR-AMOUNT:'
TR-AMOUNT
COMPUTE NM-AMOUNT = OM-AMOUNT -
TR-AMOUNT
DISPLAY 'NM-AMOUNT:'
NM-AMOUNT
WRITE NEW-MASTER-REC
PERFORM 500-READ-TRANSFILE
PERFORM 400-READ-OLD-MASTER.
/* When we
find a match we read next record from both the files. This is assuming that
we only have one transaction record for a given master record.*/
800-NO-UPDATE.
MOVE OLD-MASTER-REC TO
NEW-MASTER-REC
WRITE NEW-MASTER-REC
PERFORM 400-READ-OLD-MASTER.
400-READ-OLD-MASTER.
READ OLD-MASTER
AT END MOVE 'Y' TO
WS-OLD-MASTER-EOF P
MOVE 999999999 TO
OM-ACCT-NO.
*
DISPLAY OLD-MASTER-REC.
* WE COULD ALSO MOVE HIGH VALUES TO
INDICATE END OF FILE.
* HOWEVER HIGH-VALUES CAN WORK ONLY
WITH ALPHANUMERIC FIELDS
500-READ-TRANSFILE.
READ TRANS-FILE
AT END MOVE 'Y' TO
WS-TRANSFILE-EOF
MOVE 999999999 TO
TR-ACCT-NO.
**************************** Bottom of Data
****************************
JCL:
*****************************
Top of Data ******************************
//TESTJCL2
JOB (EWDS),'TEST JCL',NOTIFY=&SYSUID
//DWJ030C0
EXEC PGM=TESTPGM2
//STEPLIB
DD DSN=CMN.EDWS.STGO.#001621.LOD,DISP=SHR
//OMASTER
DD DSN=SM017R.OMASTER,DISP=(SHR)
//TRANFILE
DD DSN=SM017R.TRANFILE,DISP=(SHR)
//NMASTER
DD DSN=SM017R.NMASTER5,DISP=(NEW,CATLG,CATLG),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=)
****************************
Bottom of Data ****************************
OMASTER:
AA00 SM017R.OMASTER Columns
00001 00072
Command
===> Scroll ===>
CSR
******
***************************** Top of Data
000100
000000004765678
000200
000000007234556
000300
766786777234444
******
**************************** Bottom of Data
TRANSFILE:
AA00 SM017R.TRANFILE Columns
00001 00072
Command
===> Scroll ===>
CSR
******
***************************** Top of Data
000100
000000002345680
000200
000000004323786
000300
000000007412122
******
**************************** Bottom of Data
NMASTER:
AA00 SM017R.NMASTER5 Columns
00001 00072
Command
===> Scroll ===>
CSR
******
***************************** Top of Data
000001
000000002345680
000002
000000004441892
000003
000000007177566
000004
766786777234444
******
**************************** Bottom of Data
|
> If the account numbers are equal, this means that a transaction
record exists with the same account number that is on the master file.
If this condition is met, we perform update of the OLD-MASTER-REC.
That is, the transaction data is posted to the master record
After a NEW-MASTER-RECis written, another record from both OLD-MASTER and TRANS-FILE must be read.
If this condition is met, we perform update of the OLD-MASTER-REC.
That is, the transaction data is posted to the master record
After a NEW-MASTER-RECis written, another record from both OLD-MASTER and TRANS-FILE must be read.
Here, again, we are assuming that a master record can be updated with
at most one transaction record.
> if the transaction account number is greater then the master file
account number, it means that a master
record exists for which there is no corresponding transaction record.
That is, the master record has had no activity or changes during the current update cycle and should be written onto the NEW-MASTER file as is
Once we write the NEW-MASTER-REC from the OLD-MASTER-REC we read another records from the OLD-MASTER.
That is, the master record has had no activity or changes during the current update cycle and should be written onto the NEW-MASTER file as is
Once we write the NEW-MASTER-REC from the OLD-MASTER-REC we read another records from the OLD-MASTER.
Since we have not yet processed the last transaction record that caused
transaction account number to be greater than the master account number we should not read another transaction
record.
> Since both files are in sequence by account number a condition of
transaction account number being smaller than master account number means
that a transaction record exists for
which there is no corresponding master record.
Depending on the type of update procedure being performed, this could
mean either
(1) a new account is to be processed from the TRANS-FILE or
(2) an error has occurred; that is, the T-ACCT-NO is wrong.
(1) a new account is to be processed from the TRANS-FILE or
(2) an error has occurred; that is, the T-ACCT-NO is wrong.
For applications for which transaction record with no corresponding master
record means a new account.
In this instance, a new master record is created entirely from the transaction record.
Then the next transaction record is read. We do notread another record from OLD-MASTERat this time, since we have not yet processed the master record that compared greater than T-ACCT-NO
In this instance, a new master record is created entirely from the transaction record.
Then the next transaction record is read. We do notread another record from OLD-MASTERat this time, since we have not yet processed the master record that compared greater than T-ACCT-NO
For some applications,all account numbers on the transaction file must
have corresponding master records with the same account numbers. For these
applications, new accounts are handled by a different program and are not part
of the update procedure.
Generally an error routine is executed.
Generally an error routine is executed.
The Use of HIGH-VALUES for End-of-File
Conditions:
With two input files, you cannot assume that both will reach AT ENDconditions
at the same time.
It is likely that we will run out of records from one file before the other has been completely read.
First, an AT END condition for the TRANS-FILE may occur before we have reached the end of the OLD-MASTERfile.
Or, we may run out of OLD-MASTER records before we reach the end of the TRANS-FILE.
We must account for both possibilities in our program.
It is likely that we will run out of records from one file before the other has been completely read.
First, an AT END condition for the TRANS-FILE may occur before we have reached the end of the OLD-MASTERfile.
Or, we may run out of OLD-MASTER records before we reach the end of the TRANS-FILE.
We must account for both possibilities in our program.
When the OLD-MASTER file has reached the end, there may be additional transaction
records to process.
Hence, we would not want to automatically terminate all processing at an OLD-MASTER end-of-file condition;
Instead, we want to continue processing transaction records as new accounts.
To accomplish this, we place HIGH-VALUES in the account ids for both the files when their end is reached.
Hence, we would not want to automatically terminate all processing at an OLD-MASTER end-of-file condition;
Instead, we want to continue processing transaction records as new accounts.
To accomplish this, we place HIGH-VALUES in the account ids for both the files when their end is reached.
(note that we did not do this is our program as account_id was not
alphanumeric in our program.
Instead we move 999999999 to the account id field. This technique is
not recommended)
This is a character consisting of “all bits on” in a single storage
position.
All bits on, in either EBCDIC or ASCII, represents a nonstandard, nonprintable character used to specify the highest value in the computer’s collating sequence.
HIGH-VALUES in OM-ACCT-NO ensures that subsequent attempts to compare the TR-ACCT-NO of new transaction records to this OM-ACCT-NO will always result in a “less than” condition.
All bits on, in either EBCDIC or ASCII, represents a nonstandard, nonprintable character used to specify the highest value in the computer’s collating sequence.
HIGH-VALUES in OM-ACCT-NO ensures that subsequent attempts to compare the TR-ACCT-NO of new transaction records to this OM-ACCT-NO will always result in a “less than” condition.
With the use of HIGH VALUES we
continue to process records at 200-COMP-RTN even if one of the two input files
has reached an AT END condition. Only when both AT END conditions have been reached
would control return to the main module where the program is terminated.
HIGH-VALUES is a figurative constant that may be used only with fields
that are defined as alphanumeric.
Thus M-ACCT-NO, T-ACCT-NO, and ACCT-NO-OUT must be defined with a PIC of Xs rather than 9s even though they typically contain numeric data.
This does not affect the processing, since 9s are required only if a field is to be used in an arithmetic operation.
Thus M-ACCT-NO, T-ACCT-NO, and ACCT-NO-OUT must be defined with a PIC of Xs rather than 9s even though they typically contain numeric data.
This does not affect the processing, since 9s are required only if a field is to be used in an arithmetic operation.
It may have occurred to you that moving 99999to M-ACCT-NO or T-ACCT-NO
on an end-of-file condition would produce the same results as moving
HIGH-VALUES. That is, a trailer record of 9s in an account number field will
always compare higher than any other number.
This use of 9s in the key field is only possible, however, if the key field could not have a valid value of 9s.
That is, if an account number of 99999 is a possible entry, moving 99999 to an account number when an end-of-file condition is reached could produce erroneous results.
This use of 9s in the key field is only possible, however, if the key field could not have a valid value of 9s.
That is, if an account number of 99999 is a possible entry, moving 99999 to an account number when an end-of-file condition is reached could produce erroneous results.
(We used this technique in our program and should be avoided)
In summary, HIGH-VALUES means “all bits on,” which is not a printable
character and which has a nonnumeric value greater than all 9s.
Using it on an end-of-file condition will ensure correct file handling regardless of the actual values that the account numbers can assume.
This is because an incoming account number will always compare “less than” HIGH-VALUES.
Using it on an end-of-file condition will ensure correct file handling regardless of the actual values that the account numbers can assume.
This is because an incoming account number will always compare “less than” HIGH-VALUES.
SELF-TEST
1. What do we call the major collection of data pertaining to a
specific application?
Answer: Master File
Answer: Master File
2. Changes to be made to a master file are placed in a separate file
called a _______file.
Answer: Transaction file
Answer: Transaction file
3. In a sequential update procedure, we use three files called
_______,_______, and_______.
Answer: Transaction, OLD master, New master
Answer: Transaction, OLD master, New master
4. (T or F ) In a sequential update procedure, all files must be in
sequence by the same key field.
Answer: Very true
Answer: Very true
5. In a sequential update procedure, the key field in the transaction
file is compared to the key field in the _______.
Answer: Old master file
Answer: Old master file
6. In Question 5, if the key fields are equal, a _______procedure is
performed. Describe this procedure.
Answer: Update.
Answer: Update.
7. In Question 5, if the transaction key field is greater than the
master key field, a _______ procedure is performed. Describe this procedure.
Answer: no change . write the old master record to new master
Answer: no change . write the old master record to new master
8. In Question 5, if the transaction key field is less than the master
key field, a _______procedure is performed. Describe this procedure.
Answer: New account
Answer: New account
9. The statement READ TRANS-FILE AT END MOVE HIGH-VALUES TO T-ACCT-NO
...moves_______if there are no more records in TRANS-FILE. To contain
HIGH-VALUES, T-ACCT-NO must be defined with a PICof _______.
Answer: HIGH-VALUES. All bits 1 . Un printable character. The field must be alphanumeric
Answer: HIGH-VALUES. All bits 1 . Un printable character. The field must be alphanumeric
10. (T or F ) Disk files can be created for either sequential or random
access.
Answer: True
Answer: True
VALIDITY CHECKING IN UPDATE PROCEDURES:
Because updating results in changes to master files, data entry errors
must be kept to an absolute minimum.
There are two ways we can process a transaction record with account number less than master account number.
There are two ways we can process a transaction record with account number less than master account number.
> For some applications, transaction records should always have
corresponding master records; in this case, if T-ACCT-NO ? M-ACCT-NO, we treat
this as an error.
> For other applications, if T-ACCT-NO ? M-ACCT-NO, the transaction
record could be a new account to be added to the NEW-MASTER file.
However, without any additional checking could result in an error,
since the possibility exists that TR-ACCT-NO was coded incorrectly and that the
transaction record, in fact, is not a new account.
To verify that a TRANS-REC is a new account, we usually include a coded
field in the TRANS-REC itself that definitively specifies the record as a new
account.
100 CODE-IN (1 ? NEW-ACCT; 2
?REGULAR-UPDATE)
Thus, if TR-ACCT-NO IS LESS THAN OM-ACCT-NO, we would process the
transaction record as a new account only if it also contains a 1 in CODE-IN.
Following is how the new-record Para look like with a CODE-IN
600-NEW-ACCT.
EVALUATE TRUE
WHEN CODE-IN = 1
MOVE TRANS-REC TO
NEW-MASTER-REC
WRITE NEW-MASTER-REC
WHEN OTHER
PERFORM 900-ERROR-ROUTINE
END-EVALUATE
PERFORM 500-READ-TRANSFILE.
|
Following is how the update record Para look like with CODE-IN
700-UPDATE.
EVALUATE TRUE
WHEN CODE-IN = 2
MOVE OLD-MASTER-REC TO
NEW-MASTER-REC
DISPLAY 'OM-AMOUNT:'
OM-AMOUNT
DISPLAY 'TR-AMOUNT:' TR-AMOUNT
COMPUTE NM-AMOUNT = OM-AMOUNT -
TR-AMOUNT
DISPLAY 'NM-AMOUNT:'
NM-AMOUNT
WRITE NEW-MASTER-REC
WHEN OTHER
PERFORM 900-ERROR-ROUTINE
END-EVALUATE
PERFORM 500-READ-TRANSFILE
PERFORM 400-READ-OLD-MASTER.
|
It is better still to establish CODE-IN in the DATA DIVISIONwith
condition-names as follows:
05 CODE-IN PIC 9.
88 NEW-ACCT VALUE 1.
88 UPDATE-CODE VALUE 2.
88 NEW-ACCT VALUE 1.
88 UPDATE-CODE VALUE 2.
CHECKING FOR DELETE CODES AND DELETING RECORDS
FROM A SEQUENTIAL MASTER FILE:
We may use the technique of a coded transaction field as described earlier
to accomplish this.
We could add a code of ‘3’ to indicate that a record is to be deleted.
We could add a code of ‘3’ to indicate that a record is to be deleted.
100 CODE-IN (1 ? NEW-ACCT; 2
? UPDATE-CODE; 3 ?DELETE-THE-RECORD)
Following is how the update para look like.
700-UPDATE.
EVALUATE TRUE
WHEN CODE-IN = 2
MOVE OLD-MASTER-REC TO
NEW-MASTER-REC
DISPLAY 'OM-AMOUNT:'
OM-AMOUNT
DISPLAY 'TR-AMOUNT:'
TR-AMOUNT
COMPUTE NM-AMOUNT = OM-AMOUNT -
TR-AMOUNT
DISPLAY 'NM-AMOUNT:'
NM-AMOUNT
WRITE NEW-MASTER-REC
WHEN CODE-IN = 3
CONTINUE
WHEN OTHER
PERFORM 900-ERROR-ROUTINE
END-EVALUATE
PERFORM 500-READ-TRANSFILE
PERFORM 400-READ-OLD-MASTER.
|
When the CODE-IN is 3 which
indicates a delete, we do not write that record to new master file.
Continue skips to EDW-EVALUATE an next records are read.
Thus not writing that record automatically deletes it.
Continue skips to EDW-EVALUATE an next records are read.
Thus not writing that record automatically deletes it.
SUMMARY OF HOW TRANSACTION RECORDS ARE
PROCESSED IN SEQUENTIAL UPDATE:
(NOte : Its very imp for records to be in sorted by sequence of the
keys)
A.T-KEY ? M-KEY
1.Delete the master record if T-CODEindicates deletion.
2.Change or update the master record if T-CODE indicates update.
3.Process the transaction record as an error if T-CODE indicates new record.
2.Change or update the master record if T-CODE indicates update.
3.Process the transaction record as an error if T-CODE indicates new record.
B.T-KEY ? M-KEY
1.Add the transaction record to the master file if T-CODE indicates a new record.
2.Process the transaction record as an error if T-CODE does not indicate a new record.
2.Process the transaction record as an error if T-CODE does not indicate a new record.
C.T-KEY ? M-KEY
1.Rewrite the master record as is.
UPDATE PROCEDURES WITH MULTIPLE TRANSACTION
RECORDS FOR EACH MASTER RECORD:
We have thus far focused on an update procedure in which a single
transaction record is used to update the contents of a master record.
For other applications, there may be a need to process more than one change for each master record during each update cycle.
For example, a master accounts receivable file may be updated with transaction records where a single transaction record is created for each purchase or credit charged to a customer.
For other applications, there may be a need to process more than one change for each master record during each update cycle.
For example, a master accounts receivable file may be updated with transaction records where a single transaction record is created for each purchase or credit charged to a customer.
If a customer has purchased 12 items during the current updating cycle,
then there will be 12 transaction records for that one master customer record
The update procedure described earlier is suitable only if one transaction
per masteris permitted.
If more than one transaction had the same account number as a master record, the second transaction would be handled incorrectly.
Since an equal condition between the key fields in TRANS-REC and OLD-MASTER-REC causes a NEW-MASTER-REC to be written and a new TRANS-REC and MASTER-REC to be read, the processing would not be performed properly if multiple transaction records per master record were permissible.
If more than one transaction had the same account number as a master record, the second transaction would be handled incorrectly.
Since an equal condition between the key fields in TRANS-REC and OLD-MASTER-REC causes a NEW-MASTER-REC to be written and a new TRANS-REC and MASTER-REC to be read, the processing would not be performed properly if multiple transaction records per master record were permissible.
(This is what had happened with DWCCX503)
For
testing we got a transaction file having multiple records for same account
id:
Example:
AA00 SM017R.TRANFILE
Command
===>
******
***************************** Top of Data ******
000100
000000002345680
000200
000000004323786
000210
000000004100000
000300 000000007412122
000400
000000007100000
******
**************************** Bottom of Data ****
When we
run the program designed to work with
single transaction record per account number, following is how the
master file looks like:
AA00 SM017R.NMASTER8 Columns
00001 00072
Command
===>
Scroll ===> CSR
******
***************************** Top of Data ******************************
000001
000000002345680
000002
000000004441892
000003
000000004100000
000004
000000007177566
000005
000000007100000
000006
766786777234444
******
**************************** Bottom of Data ****************************
Note that
multiple rows for inserted for same account id.
The reason
is the program is not designed to handle multiple records from same account
id ina a transaction file.
The 2nd
record for each multiple occurring
account id is assumed to be an insert which is wrong.
Following
is the source code for program able to handle multiple transaction records
per account id.
Program:
*****************************
Top of Data ******************************
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTPGM3.
*PROGRAM ID IDENTIFIES THE PROGRAM
*PURPOSE OF THIS PROGRAM IS TO UPDATE
MASTER FILE WITH
*MULTIPLE TRANSACTION RECORDS3
AUTHOR. SUKUL MAHADIK.
*AUTHOR IS NOT COMPULSORY. BUT IS A
GOOD COMMENT
ENVIRONMENT DIVISION.
*ENVIRONMENT DIVISION HAS CONFIG
SECTIONS AND I-O SECTION
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-370.
OBJECT-COMPUTER. IBM-370.
INPUT-OUTPUT SECTION.
*FILE-CONTROL IS A PARAGRAPH
FILE-CONTROL.
* SELECT STATEMENT STARTS IN DIVISION
B
SELECT OLD-MASTER ASSIGN TO
OMASTER
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS
WS-OLD-MASTER-FILE-STATUS.
SELECT NEW-MASTER ASSIGN TO
NMASTER
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS
WS-NEW-MASTER-FILE-STATUS.
SELECT TRANS-FILE ASSIGN TO
TRANFILE
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS
WS-TRANSFILE-FILE-STATUS.
* NOTE NO - BETWEEN FILE AND
STATUS
DATA DIVISION.
FILE SECTION.
FD OLD-MASTER
* RECORDING,LABEL,BLOCK,RECORD SHOULD
NOT BEGIN IN AREA A
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80
CHARACTERS.
01 OLD-MASTER-REC.
05 OM-ACCT-NO PIC 9(9).
05 OM-AMOUNT PIC 9(4)V99.
05 FILLER
PIC X(65).
FD NEW-MASTER
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80
CHARACTERS.
01 NEW-MASTER-REC.
05 NM-ACCT-NO PIC 9(9).
05 NM-AMOUNT PIC 9(4)V99.
05 FILLER
PIC X(65).
FD TRANS-FILE
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80
CHARACTERS.
01 TRANS-REC.
05 TR-ACCT-NO PIC 9(9).
05 TR-AMOUNT PIC 9(4)V99.
05 FILLER
PIC X(65).
WORKING-STORAGE SECTION.
01
WS-OLD-MASTER-FILE-STATUS PIC XX.
01
WS-NEW-MASTER-FILE-STATUS PIC XX.
01
WS-TRANSFILE-FILE-STATUS PIC XX.
* END OF FILE INDICATOR
01
WS-OLD-MASTER-EOF PIC X VALUE
'N'.
01
WS-TRANSFILE-EOF PIC X VALUE 'N'.
* FILE STATUS IS ALWAYS 2
CHARACTERS
PROCEDURE DIVISION.
100-MAIN-MODULE.
DISPLAY 'PROGRAM STARTED'
PERFORM 200-INITIALIZATION
PERFORM 400-READ-OLD-MASTER
DISPLAY 'OM-ACCT-NO:'
OM-ACCT-NO
PERFORM 500-READ-TRANSFILE
DISPLAY 'TR-ACCT-NO:'
TR-ACCT-NO
PERFORM 300-COMPARE
UNTIL WS-OLD-MASTER-EOF='Y'
AND
WS-TRANSFILE-EOF='Y'
* ITS IS RECOMMENED THAT WE HAVE A
SPACE BETWEEN FIELD NAME
* AND = SIGN AND ALSO BETWEEN = AND
THE LITERAL.
* COMPILER GENERATES A WARNING IF WE
DONT DO SO.
STOP RUN.
200-INITIALIZATION.
OPEN INPUT OLD-MASTER
OPEN OUTPUT NEW-MASTER
OPEN INPUT TRANS-FILE.
300-COMPARE.
DISPLAY 'COMPARING
RECORDS.'.
EVALUATE TRUE
WHEN TR-ACCT-NO <
OM-ACCT-NO
PERFORM
600-NEW-ACCT
WHEN TR-ACCT-NO =
OM-ACCT-NO
PERFORM 700-UPDATE
WHEN TR-ACCT-NO >
OM-ACCT-NO
PERFORM
800-NO-UPDATE
END-EVALUATE.
600-NEW-ACCT.
MOVE TRANS-REC TO
NEW-MASTER-REC
WRITE NEW-MASTER-REC
PERFORM 500-READ-TRANSFILE.
700-UPDATE.
MOVE OLD-MASTER-REC TO
NEW-MASTER-REC
PERFORM UNTIL TR-ACCT-NO NOT EQUAL TO OM-ACCT-NO
COMPUTE NM-AMOUNT = OM-AMOUNT - TR-AMOUNT
MOVE NM-AMOUNT TO OM-AMOUNT
PERFORM 500-READ-TRANSFILE
END-PERFORM
WRITE NEW-MASTER-REC
PERFORM 400-READ-OLD-MASTER.
800-NO-UPDATE.
MOVE OLD-MASTER-REC TO
NEW-MASTER-REC
WRITE NEW-MASTER-REC
PERFORM 400-READ-OLD-MASTER.
400-READ-OLD-MASTER.
READ OLD-MASTER
AT END MOVE 'Y' TO
WS-OLD-MASTER-EOF
MOVE 999999999 TO OM-ACCT-NO.
* DISPLAY OLD-MASTER-REC.
* WE COULD ALSO
MOVE HIGH VALUES TO INDICATE END OF FILE.
* HOWEVER
HIGH-VALUES CAN WORK ONLY WITH ALPHANUMERIC FIELDS
500-READ-TRANSFILE.
READ TRANS-FILE
AT END MOVE 'Y' TO
WS-TRANSFILE-EOF
MOVE 999999999 TO TR-ACCT-NO.
**************************** Bottom of Data
****************************
JCL:
*****************************
Top of Data ******************************
//TESTJCL2
JOB (EWDS),'TEST JCL',NOTIFY=&SYSUID
//DWJ030C0
EXEC PGM=TESTPGM3
//STEPLIB
DD DSN=CMN.EDWS.STGO.#001621.LOD,DISP=SHR
//OMASTER
DD DSN=SM017R.OMASTER,DISP=(SHR)
//TRANFILE
DD DSN=SM017R.TRANFILE,DISP=(SHR)
//NMASTER
DD DSN=SM017R.NMASTER9,DISP=(NEW,CATLG,CATLG),
//
DCB=(RECFM=FB,LRECL=80,BLKSIZE=)
****************************
Bottom of Data ****************************
Output
Master File:
******
***************************** Top of Data *****
000100
000000004765678
000200
000000007234556
000300
766786777234444
******
**************************** Bottom of Data ***
Input
transaction file:
******
***************************** Top of Data *
000100
000000002345680
000200
000000004323786
000210
000000004100000
000300
000000007412122
000400
000000007100000
******
**************************** Bottom of Data
Output
updated master file:
******
***************************** Top of Data
000001
000000002345680
000002
000000004341892
000003
000000007077566
000004
766786777234444
******
**************************** Bottom of Data
|
SEQUENTIAL FILE UPDATING—REWRITING RECORDS ON A
DISK
THE REWRITE STATEMENT FOR A DISK FILE OPENED AS I-O:
It is possible to read a disk record, make changes directly to the same
record, and rewrite it or update it in place.
With this capability of disks, we need use only two files:
With this capability of disks, we need use only two files:
Open as Name of File
I-O MASTER-FILE
INPUT TRANS-FILE
A disk file, then, can be opened as I-O, which means records from the
disk will be accessed, read, changed, and rewritten
We read each disk record in sequence; when a record is to be updated, we make the changes directly to the MASTER-FILE record and REWRITEit.
Following program updates the master record in place using rewrite.
We read each disk record in sequence; when a record is to be updated, we make the changes directly to the MASTER-FILE record and REWRITEit.
Following program updates the master record in place using rewrite.
Program:
***************************** Top of Data
*****************************
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTPGM4.
AUTHOR. SUKUL MAHADIK.
*AUTHOR IS NOT
COMPULSORY. BUT IS A GOOD COMMENT
ENVIRONMENT DIVISION.
*ENVIRONMENT
DIVISION HAS CONFIG SECTIONS AND I-O SECTION
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-370.
OBJECT-COMPUTER. IBM-370.
INPUT-OUTPUT SECTION.
*FILE-CONTROL
IS A PARAGRAPH
FILE-CONTROL.
* SELECT
STATEMENT STARTS IN DIVISION B
* WE DONT NEED
NEW MASTER FILE AS WE WOULD BE UPDATING THE EXIST
* ING ONE IN
PLACE USING REWRITE
SELECT OLD-MASTER ASSIGN TO OMASTER
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS WS-OLD-MASTER-FILE-STATUS.
SELECT TRANS-FILE ASSIGN TO TRANFILE
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS WS-TRANSFILE-FILE-STATUS.
* NOTE NO -
BETWEEN FILE AND STATUS
DATA DIVISION.
FILE SECTION.
FD OLD-MASTER
*
RECORDING,LABEL,BLOCK,RECORD SHOULD NOT BEGIN IN AREA A
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80 CHARACTERS.
01 OLD-MASTER-REC.
05 OM-ACCT-NO PIC 9(9).
05 OM-AMOUNT PIC 9(4)V99.
05 FILLER PIC X(65).
FD TRANS-FILE
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80 CHARACTERS.
01 TRANS-REC.
05 TR-ACCT-NO PIC 9(9).
05 TR-AMOUNT PIC 9(4)V99.
05 FILLER PIC X(65).
WORKING-STORAGE SECTION.
01 WS-OLD-MASTER-FILE-STATUS
PIC XX.
01 WS-TRANSFILE-FILE-STATUS PIC
XX.
* END OF FILE
INDICATOR
01 WS-OLD-MASTER-EOF PIC X VALUE 'N'.
01 WS-TRANSFILE-EOF PIC X VALUE
'N'.
* FILE STATUS
IS ALWAYS 2 CHARACTERS
PROCEDURE DIVISION.
100-MAIN-MODULE.
PERFORM 200-INITIALIZATION
PERFORM 500-READ-TRANSFILE
* FIRST READ
ONE RECORD FROM TRASNFILE
PERFORM 300-COMPARE-RTN UNTIL TR-ACCT-NO = 999999999
PERFORM 900-CLEANUP
STOP RUN.
200-INITIALIZATION.
OPEN I-O OLD-MASTER
* TO BE ABLE
TO REWRITE THE RECORD WE NEED TO OPEN THE FILE IN
* I-O
MODE.
OPEN INPUT TRANS-FILE.
300-COMPARE-RTN.
PERFORM 400-READ-OLD-MASTER
UNTIL
TR-ACCT-NO < OM-ACCT-NO
* THIS WOULD
MEAN RECORD NOT ON MASTER AND WILL BE CONSIDERED
* AS ERROR BY
THIS PROGRAM
OR
TR-ACCT-NO = OM-ACCT-NO
OR
OM-ACCT-NO = 999999999
EVALUATE TRUE
WHEN TR-ACCT-NO = OM-ACCT-NO
DISPLAY 'INITIAL AMOUNT:' OM-AMOUNT
COMPUTE OM-AMOUNT = OM-AMOUNT - TR-AMOUNT
DISPLAY 'AMOUNT AFTER CALCULATION:' OM-AMOUNT
REWRITE OLD-MASTER-REC
WHEN TR-ACCT-NO < OM-ACCT-NO
DISPLAY 'ACCT NO ' TR-ACCT-NO 'NOT ON MASTER.ERROR'
END-EVALUATE.
PERFORM 500-READ-TRANSFILE.
400-READ-OLD-MASTER.
READ OLD-MASTER
AT END MOVE 'Y' TO WS-OLD-MASTER-EOF
MOVE 999999999 TO OM-ACCT-NO.
* DISPLAY OLD-MASTER-REC.
* WE COULD
ALSO MOVE HIGH VALUES TO INDICATE END OF FILE.
* HOWEVER
HIGH-VALUES CAN WORK ONLY WITH ALPHANUMERIC FIELDS
500-READ-TRANSFILE.
READ TRANS-FILE
AT END MOVE 'Y' TO WS-TRANSFILE-EOF
MOVE 999999999 TO TR-ACCT-NO.
900-CLEANUP.
CLOSE OLD-MASTER
CLOSE TRANS-FILE .
**************************** Bottom of Data
****************************
|
Since the same master file is used for rewriting, note that there is no
master file available for backup.
Thus if the master file gets damaged then there is no way to recreating
the data.
Therefore its suggested that we create a copy of the master file before
we update them using rewrite.
Using activity status field for designating
records to be deleted:
When we use a separate master file in sequential update procedure, we
can delete a record by not writing it to the new master file( remember the use of Continue)
However when we are updating the master file in place by using rewrite
we need to use a different technique to delete the records.
Common technique is to precede each record with the one character
activity status code that precedes the key field.
This field would have specific value for active records and a different
value for a deactivated record.
We can use something as follows:
05 ACTIVITY-STATUS PIC X.
88 ACTIVE VALUE LOW-VALUES.
88 INACTIVE VALUE HIGH-VALUES.
88 ACTIVE VALUE LOW-VALUES.
88 INACTIVE VALUE HIGH-VALUES.
HIGH-VALUES which is a figurative constant can indicate inactive
records and LOW-VALUES can indicate active records.
(Even 1 for active and 2 for inactive could also have been used)
Normally when master record is created it would have LOW-VALUES for
activity status field. We would move
HIGH-VALUES to this field only when we want to deactivate this field.
Many organizations keep such inactive records so that :
1) They can be updated back to active records if needed.
2) To be used for analysis
1) They can be updated back to active records if needed.
2) To be used for analysis
This is advantage of marking rows as inactive instead of physically
deleting them.
Note that there is a difference between records that have been
deactivated and records that have been physically deleted from a file; inactive
records still appear in the file. This means that inactive records could easily
be reactivated if the need arose or if the records were incorrectly
deactivated.
On the other hand, if a record has been physically deleted, it would be
more difficult to keep track of inactive records.
But having inactive records on the file, as opposed to deleting such
records, could eventually result in less efficient processing. When processing
time increases greatly because of a large number of inactive records on a file,
it is time to perform a file “cleanup,” where only the active records on a file
are rewritten onto a new master file.
Using the extend option to add records to the
end of the file:
Earlier where we used an input
master and an output master if a
transaction record existed for which there was no corresponding master, we were
able to add it to the NEW-MASTER in its proper sequence. This is not, however,
possible when rewriting records onto a disk opened as I-O.
Suppose the first two master disk records have CUST-NO 00001and 00006.
If a transaction record with T-CUST-NO of 00003 is read and it is a new
account, there is no physical space to insert it in its proper place on the
master file. Thus, when a sequential file is opened as I-O we can rewrite
records and deactivate records, but we cannot add records so that they are
physically located in their correct place in sequence.
It is, however, possible to write a separate program or separate
procedure to add records to the end of a sequential disk (or tape) fileif you
use EXTEND with OPEN statement
When the OPEN EXTEND statement is executed, the disk is positioned at
the end of the file, immediately after the last record.
A WRITE statement, then, will add records to the end of this file.
If all records to be added have key fields in sequence that are greater than those currently on the master, then the entire file will be in the correct order. If the records that are added are not in sequence, the file must be sorted before it is processed again.
If all records to be added have key fields in sequence that are greater than those currently on the master, then the entire file will be in the correct order. If the records that are added are not in sequence, the file must be sorted before it is processed again.
Basically to add records to the records to an existing file we must use
a separate program or procedure and open file in EXTEND mode.
We can perform updates and extend in the same program. But for that we
need to open the file first in I-O mode and perform updates using REWRITE then
close the file and open it again in EXTEND mode and write the records to the
END of the file.
***************************** Top of Data
******************************
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTPGM5.
AUTHOR. SUKUL MAHADIK.
*AUTHOR IS NOT COMPULSORY. BUT IS A GOOD COMMENT
ENVIRONMENT DIVISION.
*ENVIRONMENT DIVISION HAS CONFIG SECTIONS AND I-O SECTION
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-370.
OBJECT-COMPUTER. IBM-370.
INPUT-OUTPUT SECTION.
*FILE-CONTROL IS A PARAGRAPH
FILE-CONTROL.
SELECT OLD-MASTER ASSIGN TO OMASTER
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS WS-OLD-MASTER-FILE-STATUS.
SELECT TRANS-FILE ASSIGN TO TRANFILE
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS WS-TRANSFILE-FILE-STATUS.
*
NOTE NO - BETWEEN FILE AND STATUS
DATA DIVISION.
FILE SECTION.
FD OLD-MASTER
*
RECORDING,LABEL,BLOCK,RECORD SHOULD NOT BEGIN IN AREA A
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80 CHARACTERS.
01 OLD-MASTER-REC.
05 OM-ACCT-NO PIC 9(9).
05
OM-AMOUNT PIC 9(4)V99.
05 FILLER PIC X(65).
FD TRANS-FILE
RECORDING MODE IS F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80 CHARACTERS.
01 TRANS-REC.
05 TR-ACCT-NO PIC 9(9).
05 TR-AMOUNT PIC 9(4)V99.
05 FILLER PIC X(65).
WORKING-STORAGE SECTION.
01
WS-OLD-MASTER-FILE-STATUS
PIC XX.
01 WS-TRANSFILE-FILE-STATUS PIC
XX.
* END OF FILE INDICATOR
01 WS-OLD-MASTER-EOF PIC X VALUE 'N'.
01 WS-TRANSFILE-EOF PIC X VALUE
'N'.
*
FILE STATUS IS ALWAYS 2 CHARACTERS
PROCEDURE DIVISION.
100-MAIN-MODULE.
PERFORM 200-INITIALIZATION
PERFORM 500-READ-TRANSFILE
*
IN ORDER TO PREVENT THE LAST RECORD FROM PROCESSING TWICE
*
WE SHOULD FIRST READ ONE TRANSACTION RECORD BEFORE STARTING
*
THE LOOP. AND AT THE END ON OF THE LOOP (AFTER PROCESING THE
*
RECORD ), WE SHOUDL READ THE NEXT RECORD.
*
THIS TECHNIUEQ WOULD PREVENT LAST RECORD FROM BEING PROCESSED
*
TWICE.
PERFORM UNTIL TR-ACCT-NO =
999999999
WRITE OLD-MASTER-REC FROM
TRANS-REC
PERFORM 500-READ-TRANSFILE
END-PERFORM
PERFORM 900-CLEANUP
STOP RUN.
200-INITIALIZATION.
OPEN EXTEND OLD-MASTER
*
TO BE ABLE TO WRITE AT THE END OF THE FILE THE FILE SHOULD
*
BE OPEN IN EXTEND MODE.
OPEN INPUT TRANS-FILE.
500-READ-TRANSFILE.
READ TRANS-FILE
AT END MOVE 'Y' TO
WS-TRANSFILE-EOF
MOVE 999999999 TO TR-ACCT-NO.
900-CLEANUP.
CLOSE OLD-MASTER
CLOSE TRANS-FILE .
**************************** Bottom of Data
****************************
JCL:
***************************** Top of Data
******************************
//TESTJCL2 JOB (EWDS),'TEST
JCL',NOTIFY=&SYSUID
//DWJ030C0 EXEC PGM=TESTPGM5
//STEPLIB DD
DSN=CMN.EDWS.STGO.#001621.LOD,DISP=SHR
//OMASTER DD
DSN=SM017R.NMASTER1,DISP=(SHR)
//TRANFILE DD
DSN=SM017R.TRANFILE,DISP=(SHR)
**************************** Bottom of Data
****************************
Master file before running the program:
***************************** Top of Data
******************************
000000004205680
000000007177566
766786777234444
**************************** Bottom of Data
****************************
Transaction File:
***************************** Top of Data
******************************
000000002345680
000000004323786
000000007412122
**************************** Bottom of Data
****************************
Master File after running the program:
***************************** Top of Data
******************************
000000004205680
000000007177566
766786777234444
000000002345680
000000004323786
000000007412122
**************************** Bottom of Data
****************************
|
The following is a chart of permissible input/output statements
depending on how a sequential file was opened:
SUMMARY: UPDATING A MASTER DISK IN PLACE
•Open the file as I-O.
•Read a master record to be updated, make changes, and then REWRITE the record in place.
• Instead of deleting master records, establish each record with an activity code that indicates either an active record or an inactive record (e.g., 1in CODE-X for active or 2in CODE-X for inactive). All master records are initially active (1in CODE-X) unless the transaction record indicates that the master should be deactivated. To deactivate the master record, change the activity code: e.g. MOVE 2 TO CODE-X.
•Read a master record to be updated, make changes, and then REWRITE the record in place.
• Instead of deleting master records, establish each record with an activity code that indicates either an active record or an inactive record (e.g., 1in CODE-X for active or 2in CODE-X for inactive). All master records are initially active (1in CODE-X) unless the transaction record indicates that the master should be deactivated. To deactivate the master record, change the activity code: e.g. MOVE 2 TO CODE-X.
To add records to the end of an existing sequential master file in a
separate program or procedure:
•Open the file as EXTEND. If the file was already opened as I-O for
updating, it must be closed and then reopened.
• WRITE the new records to the end of the file.
• The file will need to be sorted if the added records are not in sequence.
• WRITE the new records to the end of the file.
• The file will need to be sorted if the added records are not in sequence.
File management Tips:
Ø The SELECT statement begins by specifying the
file-name as it is known to the COBOL program—SELECT PAYROLL-FILE ...means that
we will have an FDfor PAYROLL-FILE, an OPEN and a CLOSE statement for
PAYROLL-FILE.
The ASSIGN TO clause
specifies the implementor-name of the file, as it is known to the operating
system.
Since operating systems
have different rules for forming implementor-file-names, the ASSIGN TO clause
will vary from computer to computer.
Ø The file is organized for sequential
processing, meaning that the first record will be read, followed by the second
record, and so on. If the file is created by a COBOL program, rather than by
simply typing in the file, ORGANIZATION IS SEQUENTIAL should be used.
If you type the file and press the enter key to end each physical record, use the clause ORGANIZATION IS LINE SEQUENTIAL in the SELECT statement.
If you type the file and press the enter key to end each physical record, use the clause ORGANIZATION IS LINE SEQUENTIAL in the SELECT statement.
Ø If a file does not physically exists and if we
try to open it in I-O or input mode then an OPEN error occurs.
Sometimes you may be testing a program that
assumes the existence of an INPUT or I-O file that has not yet been created.
You do not want an error to occur on opening these files. You may add the word
OPTIONAL to the SELECT statement to avoid OPEN errors:
SELECT OPTIONAL PAYROLL-FILE
ASSIGN TO ’C:\CHAPTER13\MASTER.DAT’
ORGANIZATION IS SEQUENTIAL.
If this statement is coded in the ENVIRONMENT
DIVISION, then the OPEN statement for PAYROLL-FILE will not cause an error. If
the file is opened as INPUT and OPTIONAL is used, a blank file with the
implementor-file-name will be automatically created.
Ø When we open a file in OUTPUT mode and if the
file already exists then old file is destroyed. When opening the file in EXTEND
mode if the file exists which is expected the processing continues and if the
file does not exists then the file is created.
ReplyDeleteThanks so much!! Your site looks nice. Wikidot sounds perfect!
Image Processing
check this mframes.blogspot.com
ReplyDelete