Hello,
I have just started doing a program that can add, update or delete customer records. The old-master file is sorted by the id x(5). I have a few questions.
First of all, there is no transaction file to use for updating the master file (which is the only example in my text book). This program needs to take data entered on the screen to do the maintenance work. I have the code below that works for adding a new customer using the OPEN EXTEND – but I'm not sure if there is a better way. And, how is updating and deleting done when you aren't comparing the master file to a transaction file? Again, this is done using screen input.
Second question is this: when adding a new customer, we have to generate an ID for the new customer. Right now, I'm just counting the records and adding one to get the new ID. But, we can't re-use records - so that if ID 00004 is deleted, but it was also the highest record, it will be re-used in error. There must be a better way. Is a coded active/inactive field used in this case or is there another way?
Any help would be appreciated. The code below isn't finished and doesn’t represent the files we will really be using – this was just for me to help learn this technique.
Thanks.
-Tyler
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE.
AUTHOR. TYLER BALL.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OLD-MASTER ASSIGN TO 'I:\OLDMAST.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT NEW-MASTER ASSIGN TO 'I:\NEWMAST.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD OLD-MASTER
LABEL RECORDS ARE STANDARD.
01 OLD-MASTER-REC.
05 ID-IN PIC X(5).
05 AMT-IN PIC 9(4)V99.
05 PIC X(89).
FD NEW-MASTER
LABEL RECORDS ARE STANDARD.
01 NEW-MASTER-REC.
05 ID-OUT PIC X(5).
05 AMT-OUT PIC 9(4)V99.
05 PIC X(89).
WORKING-STORAGE SECTION.
01 WS-CODE PIC 9 VALUE ZEROS.
01 WS-CONTROL-KEY PIC X(5) VALUE SPACES.
01 WS-SWITCH PIC X VALUE 'Y'.
01 EOF PIC X VALUE 'N'.
01 WS-COUNT PIC 99 VALUE ZEROS.
01 FIRST-TIME PIC X VALUE 'Y'.
01 WS-GENERATE-ID PIC 9(5) VALUE ZEROS.
01 WS-CUST.
05 CUST-ID PIC X(5).
05 CUST-AMT PIC 9(4)V99.
05 PIC X(89).
SCREEN SECTION.
01 CHOICE-SCREEN BACKGROUND-COLOR IS 1
FOREGROUND-COLOR IS 7.
05 BLANK SCREEN.
05 CHOICE-SEC HIGHLIGHT.
10 LINE 10 COL 20 VALUE 'ADD NEW CUSTOMER'.
10 LINE 12 COL 20 VALUE 'UPDATE CUSTOMER'.
10 LINE 14 COL 20 VALUE 'DELETE CUSTOMER'.
10 LINE 16 COL 20 VALUE 'MAIN MENU'.
05 OPTIONS-SEC HIGHLIGHT BLINK FOREGROUND-COLOR IS 6.
10 LINE 10 COL 18 VALUE '1'.
10 LINE 12 COL 18 VALUE '2'.
10 LINE 14 COL 18 VALUE '3'.
10 LINE 16 COL 18 VALUE '4'.
01 ADD-NEW-SCREEN BACKGROUND-COLOR IS 1
FOREGROUND-COLOR IS 7.
05 BLANK SCREEN.
05 WORD-SEC HIGHLIGHT.
10 LINE 10 COL 25 VALUE 'NEW ID:'.
10 LINE 12 COL 24 VALUE 'NEW AMT:'.
05 VALUE-SEC REVERSE-VIDEO HIGHLIGHT.
10 LINE 10 COL 33 PIC X(5) FROM WS-GENERATE-ID.
10 LINE 12 COL 33 PIC 9(4).99 TO CUST-AMT REQUIRED.
PROCEDURE DIVISION.
100-MAIN-MODULE.
PERFORM 700-INITIALIZATION-RTN
PERFORM 200-CHOICE-RTN
UNTIL WS-SWITCH = 'N'
PERFORM 1000-END-RTN.
200-CHOICE-RTN.
INITIALIZE WS-CUST
DISPLAY CHOICE-SCREEN
ACCEPT WS-CODE AT LINE 1 COL 1 WITH SECURE AUTO
EVALUATE WS-CODE
WHEN 1 PERFORM 400-ADD-NEW-RTN
WHEN 2 PERFORM 500-UPDATE-RTN
WHEN 3 PERFORM 600-DELETE-RTN
WHEN 4 PERFORM 1000-END-RTN
END-EVALUATE.
400-ADD-NEW-RTN.
MOVE 'N' TO EOF
IF FIRST-TIME = 'Y'
MOVE 'N' TO FIRST-TIME
OPEN INPUT NEW-MASTER
PERFORM UNTIL EOF = 'Y'
READ NEW-MASTER
AT END
MOVE 'Y' TO EOF
NOT AT END
ADD 00001 TO WS-GENERATE-ID
END-READ
END-PERFORM
CLOSE NEW-MASTER
END-IF
PERFORM 450-GENERATE-ID
DISPLAY ADD-NEW-SCREEN
ACCEPT ADD-NEW-SCREEN
PERFORM 900-PROCESS-RTN 1 TIMES.
450-GENERATE-ID.
MOVE CUST-CT TO WS-GENERATE-ID
COMPUTE WS-GENERATE-ID = WS-GENERATE-ID + 00001
MOVE WS-GENERATE-ID TO CUST-ID.
500-UPDATE-RTN.
600-DELETE-RTN.
700-INITIALIZATION-RTN.
OPEN INPUT OLD-MASTER
OUTPUT NEW-MASTER
PERFORM UNTIL EOF = 'Y'
READ OLD-MASTER
AT END
MOVE 'Y' TO EOF
NOT AT END
WRITE NEW-MASTER-REC FROM OLD-MASTER-REC
END-READ
END-PERFORM
CLOSE OLD-MASTER
CLOSE NEW-MASTER.
800-EXTEND-OPEN.
OPEN EXTEND NEW-MASTER.
900-PROCESS-RTN.
IF WS-CODE = 1
PERFORM 800-EXTEND-OPEN
WRITE NEW-MASTER-REC FROM WS-CUST
CLOSE NEW-MASTER
END-IF
IF WS-CODE = 2
CONTINUE
END-IF
IF WS-CODE = 3
CONTINUE
END-IF.
1000-END-RTN.
STOP RUN.
I have just started doing a program that can add, update or delete customer records. The old-master file is sorted by the id x(5). I have a few questions.
First of all, there is no transaction file to use for updating the master file (which is the only example in my text book). This program needs to take data entered on the screen to do the maintenance work. I have the code below that works for adding a new customer using the OPEN EXTEND – but I'm not sure if there is a better way. And, how is updating and deleting done when you aren't comparing the master file to a transaction file? Again, this is done using screen input.
Second question is this: when adding a new customer, we have to generate an ID for the new customer. Right now, I'm just counting the records and adding one to get the new ID. But, we can't re-use records - so that if ID 00004 is deleted, but it was also the highest record, it will be re-used in error. There must be a better way. Is a coded active/inactive field used in this case or is there another way?
Any help would be appreciated. The code below isn't finished and doesn’t represent the files we will really be using – this was just for me to help learn this technique.
Thanks.
-Tyler
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE.
AUTHOR. TYLER BALL.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OLD-MASTER ASSIGN TO 'I:\OLDMAST.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT NEW-MASTER ASSIGN TO 'I:\NEWMAST.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD OLD-MASTER
LABEL RECORDS ARE STANDARD.
01 OLD-MASTER-REC.
05 ID-IN PIC X(5).
05 AMT-IN PIC 9(4)V99.
05 PIC X(89).
FD NEW-MASTER
LABEL RECORDS ARE STANDARD.
01 NEW-MASTER-REC.
05 ID-OUT PIC X(5).
05 AMT-OUT PIC 9(4)V99.
05 PIC X(89).
WORKING-STORAGE SECTION.
01 WS-CODE PIC 9 VALUE ZEROS.
01 WS-CONTROL-KEY PIC X(5) VALUE SPACES.
01 WS-SWITCH PIC X VALUE 'Y'.
01 EOF PIC X VALUE 'N'.
01 WS-COUNT PIC 99 VALUE ZEROS.
01 FIRST-TIME PIC X VALUE 'Y'.
01 WS-GENERATE-ID PIC 9(5) VALUE ZEROS.
01 WS-CUST.
05 CUST-ID PIC X(5).
05 CUST-AMT PIC 9(4)V99.
05 PIC X(89).
SCREEN SECTION.
01 CHOICE-SCREEN BACKGROUND-COLOR IS 1
FOREGROUND-COLOR IS 7.
05 BLANK SCREEN.
05 CHOICE-SEC HIGHLIGHT.
10 LINE 10 COL 20 VALUE 'ADD NEW CUSTOMER'.
10 LINE 12 COL 20 VALUE 'UPDATE CUSTOMER'.
10 LINE 14 COL 20 VALUE 'DELETE CUSTOMER'.
10 LINE 16 COL 20 VALUE 'MAIN MENU'.
05 OPTIONS-SEC HIGHLIGHT BLINK FOREGROUND-COLOR IS 6.
10 LINE 10 COL 18 VALUE '1'.
10 LINE 12 COL 18 VALUE '2'.
10 LINE 14 COL 18 VALUE '3'.
10 LINE 16 COL 18 VALUE '4'.
01 ADD-NEW-SCREEN BACKGROUND-COLOR IS 1
FOREGROUND-COLOR IS 7.
05 BLANK SCREEN.
05 WORD-SEC HIGHLIGHT.
10 LINE 10 COL 25 VALUE 'NEW ID:'.
10 LINE 12 COL 24 VALUE 'NEW AMT:'.
05 VALUE-SEC REVERSE-VIDEO HIGHLIGHT.
10 LINE 10 COL 33 PIC X(5) FROM WS-GENERATE-ID.
10 LINE 12 COL 33 PIC 9(4).99 TO CUST-AMT REQUIRED.
PROCEDURE DIVISION.
100-MAIN-MODULE.
PERFORM 700-INITIALIZATION-RTN
PERFORM 200-CHOICE-RTN
UNTIL WS-SWITCH = 'N'
PERFORM 1000-END-RTN.
200-CHOICE-RTN.
INITIALIZE WS-CUST
DISPLAY CHOICE-SCREEN
ACCEPT WS-CODE AT LINE 1 COL 1 WITH SECURE AUTO
EVALUATE WS-CODE
WHEN 1 PERFORM 400-ADD-NEW-RTN
WHEN 2 PERFORM 500-UPDATE-RTN
WHEN 3 PERFORM 600-DELETE-RTN
WHEN 4 PERFORM 1000-END-RTN
END-EVALUATE.
400-ADD-NEW-RTN.
MOVE 'N' TO EOF
IF FIRST-TIME = 'Y'
MOVE 'N' TO FIRST-TIME
OPEN INPUT NEW-MASTER
PERFORM UNTIL EOF = 'Y'
READ NEW-MASTER
AT END
MOVE 'Y' TO EOF
NOT AT END
ADD 00001 TO WS-GENERATE-ID
END-READ
END-PERFORM
CLOSE NEW-MASTER
END-IF
PERFORM 450-GENERATE-ID
DISPLAY ADD-NEW-SCREEN
ACCEPT ADD-NEW-SCREEN
PERFORM 900-PROCESS-RTN 1 TIMES.
450-GENERATE-ID.
MOVE CUST-CT TO WS-GENERATE-ID
COMPUTE WS-GENERATE-ID = WS-GENERATE-ID + 00001
MOVE WS-GENERATE-ID TO CUST-ID.
500-UPDATE-RTN.
600-DELETE-RTN.
700-INITIALIZATION-RTN.
OPEN INPUT OLD-MASTER
OUTPUT NEW-MASTER
PERFORM UNTIL EOF = 'Y'
READ OLD-MASTER
AT END
MOVE 'Y' TO EOF
NOT AT END
WRITE NEW-MASTER-REC FROM OLD-MASTER-REC
END-READ
END-PERFORM
CLOSE OLD-MASTER
CLOSE NEW-MASTER.
800-EXTEND-OPEN.
OPEN EXTEND NEW-MASTER.
900-PROCESS-RTN.
IF WS-CODE = 1
PERFORM 800-EXTEND-OPEN
WRITE NEW-MASTER-REC FROM WS-CUST
CLOSE NEW-MASTER
END-IF
IF WS-CODE = 2
CONTINUE
END-IF
IF WS-CODE = 3
CONTINUE
END-IF.
1000-END-RTN.
STOP RUN.