There is no doubt Mainframes running COBOL powers majority of world's business transactions. Some of the firms are Financial institutions, hospitals, government and logistics.
The very first site that I worked for is (even now) a global leader on the market of business information. They collect, store and process a business's information to generate credit scores and business information reports. The scores assess the business and it helps, say, a bank to use the information in the report when deciding to offer a loan to that business.
Master file:
I was part of the application which generated the scores. We stored the scores for ~80 million businesses and we didn't maintain a database. Rather, we used a sequential Master file which was inclined to grow whenever a new business's score was generated.
In addition to that, it was necessary that we updated the scores of the existing businesses in daily basis as a business is prone to changes (there might be a change in CEO; the business might go Out of Business or Bankrupt; the business might win a Suit; trade payment changes undergone by the business and so on).
Transaction file:
Daily changes of the business were stored in a file referred to as transaction file. The transaction file had all transactions to be posted to the Master file that have occurred since the previous update. The transaction file also had a key field (the same key as that of the Master file) and all the records in the transaction file were in sequence by the key field.
Updating a Master file:
The process of making the Master file current is referred to as updating. The Master file is updated via sequential processing by reading in the Master file along with the transaction file and creating a new master file. At the end of the update process, there will be an old master and a new master; should something happen to the new master file, it can be recreated from the old. Refer to the following picture for better clarity.
Click on the image for a larger version.
The Old Master file (OLD-MASTER) contains master information that was complete and current till the previous updating cycle. The transaction file (TRANS-FILE) contains transactions or changes that occurred since the previous updating cycle. These transactions or changes must be incorporated into the master file to make it current and updated. As a result, a New Master file (NEW-MASTER) will include all OLD-MASTER data in addition to the changes stored on the TRANS-FILE that have occurred since the last update.
As all the records are in sequence by the key field, we compare the key field in the Old Master file to the same key field in the transaction file to determine if the master record is to be updated; this comparison requires both the files to be in sequence by the key field.
Let's take a look at the format of the two input files:
OLD-MASTER 📂
(in sequence by M-BUSINESS-NO)
COLS FIELD
1-9 M-BUSINESS-NO
10-39 M-BUSINESS-NAME
40-42 M-SCORE
43-100 M-FILLER
TRANS-FILE 📂
(in sequence by T-BUSINESS-NO)
COLS FIELD
1-9 T-BUSINESS-NO
10-39 T-BUSINESS-NAME
40-42 T-SCORE
43-100 T-FILLER
How input transaction and Master records are processed?
IF T-BUSINESS-NO = M-BUSINESS-NO
IF T-BUSINESS-NO > M-BUSINESS-NO
IF T-BUSINESS-NO < M-BUSINESS-NO
ID DIVISION.
PROGRAM-ID. CBL4.
AUTHOR. SRINIVASAN.
*
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OLD-MASTER ASSIGN TO OLDMAST.
SELECT NEW-MASTER ASSIGN TO NEWMAST.
SELECT TRANS-FILE ASSIGN TO TRANS.
*
DATA DIVISION.
FILE SECTION.
FD OLD-MASTER
RECORDING MODE IS F
RECORD CONTAINS 100.
01 OLD-MASTER-REC.
05 M-BUSINESS-NO PIC X(9).
05 M-BUSINESS-NAME PIC X(30).
05 M-SCORE PIC 9(3).
05 M-FILLER PIC X(58).
FD TRANS-FILE
RECORDING MODE IS F
RECORD CONTAINS 100.
01 TRANS-REC.
05 T-BUSINESS-NO PIC X(9).
05 T-BUSINESS-NAME PIC X(30).
05 T-SCORE PIC 9(3).
05 T-FILLER PIC X(58).
FD NEW-MASTER
RECORDING MODE IS F
RECORD CONTAINS 100.
01 NEW-MASTER-REC.
05 N-BUSINESS-NO PIC X(9).
05 N-BUSINESS-NAME PIC X(30).
05 N-SCORE PIC 9(3).
05 N-FILLER PIC X(58).
*
PROCEDURE DIVISION.
100-MAIN-MODULE.
PERFORM 800-INITIALIZATION-RTN
PERFORM 600-READ-MASTER
PERFORM 700-READ-TRANS
PERFORM 200-COMPARE-RTN
UNTIL M-BUSINESS-NO = HIGH-VALUES
AND T-BUSINESS-NO = HIGH-VALUES
PERFORM 900-CLOSE-FILES-RTN
STOP RUN.
*
200-COMPARE-RTN.
EVALUATE TRUE
WHEN T-BUSINESS-NO = M-BUSINESS-NO
PERFORM 300-REGULAR-UPDATE
WHEN T-BUSINESS-NO < M-BUSINESS-NO
PERFORM 400-NEW-ACCOUNT
WHEN OTHER
PERFORM 500-NO-UPDATE
END-EVALUATE.
*
300-REGULAR-UPDATE.
MOVE OLD-MASTER-REC TO NEW-MASTER-REC
WRITE NEW-MASTER-REC
PERFORM 600-READ-MASTER
PERFORM 700-READ-TRANS.
*
400-NEW-ACCOUNT.
MOVE SPACES TO NEW-MASTER-REC
MOVE T-BUSINESS-NO TO N-BUSINESS-NO
MOVE T-BUSINESS-NAME TO N-BUSINESS-NAME
MOVE T-SCORE TO N-SCORE
MOVE T-FILLER TO N-FILLER
WRITE NEW-MASTER-REC
PERFORM 700-READ-TRANS.
*
500-NO-UPDATE.
WRITE NEW-MASTER-REC FROM OLD-MASTER-REC
PERFORM 600-READ-MASTER.
*
600-READ-MASTER.
READ OLD-MASTER
AT END MOVE HIGH-VALUES TO M-BUSINESS-NO
END-READ.
*
700-READ-TRANS.
READ TRANS-FILE
AT END MOVE HIGH-VALUES TO T-BUSINESS-NO
END-READ.
*
800-INITIALIZATION-RTN.
OPEN INPUT OLD-MASTER
TRANS-FILE
OUTPUT NEW-MASTER.
*
900-CLOSE-FILES-RTN.
CLOSE OLD-MASTER
TRANS-FILE
NEW-MASTER.
*
Contents of Old Master file. |
First step of the JCL compiles the COBOL program. If the compilation is successful, the second step will run to execute the load. |
Contents of New Master file. |
Note the new record with business number as 000000004 added to the New Master file. Also, the scores of the existing businesses are updated.
Use of HIGH-VALUES for End of file conditions:
HIGH-VALUES refer to the largest value in the system's collating sequence. This is a character consisting of "all bits on" in a single storage position. All bits on in EBCDIC represents a nonstandard, nonprintable character used to specify the highest value in the system's collating sequence.
Great Work!
ReplyDeleteNice keep it up 👍
ReplyDelete