Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add/update/delete using screen input

Status
Not open for further replies.

gonzilla

Programmer
Apr 10, 2001
125
US
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.
 
Hi Tyler,

Using a seq file to add/update/delete recs interactively is highly unusual. Some form of direct access (indexed) file or DBMS is usually the way to go. I realize this is a class project and the data file sizes are very small so the seq approach can be used as an exercise. Have you covered direct access files yet? You may want to talk this over w/your prof.

Regards, Jack.
 
Slade,

Actually, we have not yet covered this in clss, but I like to stay ahead. I am sure that we are using the same file as we have used so far (which is a sequential file) for this part of the lab. We have not covered direct access yet. I'm guessing that won't be covered until I take DB2. I was really starting to think that I was missing something in the book. I'll get with my teacher as well.
The CUSTOMER.DAT we will be using contains only 50 records. For now, I guess any suggestions would give me a clue. Is my approach correct at all?

Thanks again.

-Tyler
 
Hi Tyler,

Is there a relationship between the lab assignments and the text that you can pinpoint? That is, can you say, "If this is lab #4, we should have finished chapt #12".

If you can, look through the index to see what topics are covered up to that point. I find it hard to believe that this kind of pgm would have been assigned using a seq file.

Let me know. If you're sure that's the way your prof wants it, I'll try to help. But it does seem like a waste of time, and the beginning of some bad pgmming practices.

Jack
 
Slade,

I'll ask him. There is a relationship in the lab and the text. We are now doing the chapters on Data Validation and Sequential File Processing. Of course, there is nowhere in the book anything to do with interactive updating of files...

Thank you for the warning. I will look into it.

-Tyler
 
Hi Tyler,

Just to give you an idea of how an interactive application works (I'm not familiar with PC based screen I/O). The general process goes like this:

Send a screen requesting info (e.g., acct#, cust-id, $ amt, porcess code - a/d/u). User inputs all data required for the xaction. Note:

At user term -
add - inputs all required rec info
delete - inputs key info (enough to id the rec)
Change - same as delete

In pgm -
add - verifies rec info; fills O/P rec; inserts rec
delete - moves key info to key; reads rec;displays rec;
asks for verification; if yes, deletes; if no
begins process again. Note some apps just delete.

Change - moves key info to key; reads rec;displays rec;
(user changes rec info)
verifies new info; fills O/P rec; rewrites rec

There's also a browse function, but the above mimic what you were attempting.

Some of the new things you see here are terms like insert, and rewrite, and key. These are terms related to indexed files and/or databases.

Trying to these things with a seq file is clumsey bordering on impossible. Example:

What do you do if the user has ten changes to make? Open the file for I-O;read up the file till you find the record; show it to the user; accept the changes; rewrite the rec; close the file; ask for the next id; open, etc, 9 more times? Not too good.

Delete 10 recs? Recreate the file 10 times? Count on the user to sort the delete requests so you only have to create the file once? In your dreams!

Get my point?

Regards, Jack.
 
Hey Slade,

You were right! (of course) We just went over chapter 13 (sequential file processing) in which the teacher said we are learning this but we won't be using it in the lab. Instead, chapter 15 is about indexed file processing which we will be using for this part of the lab. I guess I should read ahead a little more than I already am. I did read a little of 15 and it looks much more simple in regards to updating files interactively.

Question: in your experience in the industry, is the sequential file processing/balanced line algorithm technique still used alot? My teacher (who is a little older) said it really isn't used but may exist in programs that are still needed.

Thanks

-Tyler
 
Hi Tyler,

Your prof is right when he says the BL is not used much, but not because it's outmoded. I think it's because most were never exposed to it. The same can be said about control break processing. If he's saying it's not important, he's wrong; doing something well is always important.

With that said, batch processing has been on the wane for the last 40 years, with the advent of on-line processing in general and the internet/intranet in particular. Maybe that's what he had in mind.

Regards, Jack.
 
Jack, Tyler,

i work for the ICT department of a large bank, and we still use a lot of batch processing where sequential file processing and balanced line constructs are used all over the place. Although the amount of transactions processed in batch decreases to give way to online processing, for database wide actions (like cleaning up, recovery, etc.) there still is nothing as fast as bare bones seq file processing !

Regards,
Ronald.
 
Hi Ronald,

As a consultant, I've worked at many, many shops and I've only seen one pgm (except for mine, of course, ah-hem) that used the, for want of a better term, "cascading perform" control break. Only a handful of the "balanced line" file match technique.

Over the years I'd struggled through trial and error to develope and refine these techniques, and a year ago I found that I "reinvented" them. I was surfing the web and saw them in a reprint of someone's masters thesis from 1964.

As I've mentioned before in this forum, they're rarely used. I've got to fault the teaching community for this, and not necessarily at the college/univ level; the hardware vendors and vocational schools should assume a lion's share of the responsibility too.

Regards, Jack.
 
I must be missing something - I have been an AP on IBM AS400 and Mainframes for the last 5 years writing interactive and batch update routines - what the heck is the balanced line algorithm??

Must admit, only ever did one formal course in Cobol and I can't remember anyone mentioning this. Oh dear, I am ignorant.

pipk
 
Hi Pip,

You probably have been doing this for your entire career, but didn't have a name for it. I know I didn't. We used to call it the file match algorithm. This may be a particular form of that, I don't know, but what's in a name. Umm... sounds familiar.

Anyway, I'm sure you know this. But for the uninitiated, it's basically running up one file or the other until you get a match, e.g.:

Code:
00114      PERFORM 200-MATCH-DAILY-MASTER-RECS
00115        UNTIL BOTH-FILES-EOF


00119 *****************************
00120  200-MATCH-DAILY-MASTER-RECS.
           DISPLAY 'DEBUG-  200-MATCH-DAILY-MASTER-RECS.'
00121 *****************************
00122      EVALUATE TRUE
00123      WHEN WS-DAILY-COMPARE-KEY = WS-MASTER-COMPARE-KEY
00124           PERFORM 210-UPDATE-MASTER-REC
00125           PERFORM 700-GET-BOTH-COMPARE-KEYS THRU 700-EXIT
00126      WHEN WS-DAILY-COMPARE-KEY > WS-MASTER-COMPARE-KEY
00127 *===> I.E., NO DAILY ACCRETION RECORD
00129           PERFORM 220-REWRITE-MASTER-REC
00130           PERFORM 700-GET-MASTER-COMPARE-KEY
00131      WHEN OTHER
00132 *===> I.E., NEW DAILY ACCRETION RECORD, ADD TO MASTER FILE
00134           WRITE MASTER-ACCRET-REC-OP        FROM WS-DAILY-DTL
00135           ADD  +1                             TO WS-NO-MASTER-CNT
00136           PERFORM 700-GET-DAILY-COMPARE-KEY
00137      END-EVALUATE
00138      .

The code presumes a priming read of both files to get things started. The 700-... routines read the files, at EOF moves HI-VALS to the key to force a valid compare, and set up the key fields. I'm sure there are thousands of variations, but this is my story and I'm stickin' to it.

Regards, Jack.
P.S.
You can do this for more than 2 files, but you need a "find low rec" routine before the evaluate. Then code the evaluate relative to the low rec.
 
aah, that old chestnut.

my feeling of ignorance has been washed away.

many thanks

pipk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top