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!

DAT files

Status
Not open for further replies.

gonzilla

Programmer
Apr 10, 2001
125
US
Hello,

Just a quick question about an input file.

I have a program that reads a CUSTOMER.DAT file into a table and searches based on either the Id or the phone number. It is in this format:

ID FIRST LAST ADDRESS CITY STATE ZIP PHONE
00039June Adams 660 Elm St. Greer OH44628(614) 444-8585


The column headings here are just fyi. I condensed the spaces so that it fit on one line in this text box, but there is NO space between ID and First. There are only 50 records in the file in ascending order by ID#. (00001 to 00050) I have the OCCURS clause set to 100 so it can be updated with new customers.

I have the program up and it works just fine searching either the Id or phone number. My question is, when I add records to the file in Notepad, or Word or even Edit (MSDOS) and then try to search it, it only returns a good search for the new records if the phone number is correct, but not the Id.

Example: I added two full records. 00051 and 00052. If I search (this is done interactively by the user with an accept) on 00051, or 00052 it returns not found, but if I search a phone number matching the new Id, it returns found and displays all of the information - EVEN THE ID#!!!

Is there a certain way to create or update a .dat file that prevents me from doing it this way? (I work on a PC with MicroFocus)

Thank you for the help.

-Tyler
 
Hi Tyler,

It depends on how you coded your program. Do you load the file every time the pgm is executed? How do you search the table? If the pgm isn't too big (and I doubt it) why not send it along for us to look at? It would save a lot of guessing.

Regards, Jack.
 
Hi again,

Well, I searched some more on this forum and found out the problem - thank you all! I fixed the problem by using a depending on clause with the occurs. I have the table large enough to load 100 records but the blank space at the end (00052 - 00100) was being searched in the SEARCH ALL. The serial SEARCH had no problem (of course) and I realize that it was just luck that 50 records worked. (half of the table!)

Below is the complete code I have without the screen sections. FYI this program is a called program. Any suggestions from anybody on what looks bad or could be better is always appreciated. Such as: are the performs structured enough? Some of the modules perform themselves (when an incorrect value is entered)

This is my second semester of COBOL and I'm always looking to better myself.

Thanks again.

-Tyler

IDENTIFICATION DIVISION.
PROGRAM-ID. CUSTINQ.
ENVIRONMENT DIVISION.
FILE-CONTROL.
SELECT CUST-FILE ASSIGN TO 'E:\CUSTOMER.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD CUST-FILE
LABEL RECORDS ARE STANDARD.
01 CUST-INFO.
05 CUST-ID PIC X(5).
05 CUST-F-NAME PIC X(15).
05 CUST-L-NAME PIC X(15).
05 CUST-ADDRESS PIC X(30).
05 CUST-CITY PIC X(15).
05 CUST-STATE PIC XX.
05 CUST-ZIP PIC X(5).
05 CUST-PHONE-NUM PIC X(14).
*
WORKING-STORAGE SECTION.
**********************************************************
01 WS-ID-IN PIC X(5) VALUE SPACES.
01 WS-PHONE-NUM.
05 WS-AREA PIC X(3) VALUE SPACES.
05 WS-CODE3 PIC X(3) VALUE SPACES.
05 WS-CODE4 PIC X(4) VALUE SPACES. *********************************************************
01 WS-FINAL-NAME PIC X(31) VALUE SPACES.
01 WS-FINAL-ADDRESS PIC X(25) VALUE SPACES.
01 WS-PHONE-LAST PIC X(14) VALUE SPACES.
**********************************************************
01 WS-SEL-CHECK PIC 9 VALUE ZEROS.
01 WS-ERROR-CT PIC 9 VALUE ZEROS.
01 QUIT-OPT PIC X(4) VALUE 'QUIT'.
01 EXIT-PROGRAM PIC X VALUE 'N'.
01 FIRST-LOAD PIC X VALUE 'Y'.
*********************************************************
01 WS-DATE.
05 CURRENT-YEAR PIC 9(4) VALUE ZEROS.
05 CURRENT-MONTH PIC 9(2) VALUE ZEROS.
05 CURRENT-DAY PIC 9(2) VALUE ZEROS.
01 WS-FINAL-DATE.
05 MONTH-OF PIC 9(2) VALUE ZEROS.
05 PIC X VALUE '/'.
05 DAY-OF PIC 9(2) VALUE ZEROS.
05 PIC X VALUE '/'.
05 YEAR-OF PIC 9(4) VALUE ZEROS. **********************************************************
01 WS-ERR-OPTION PIC X VALUE SPACES.
88 TRY-YES VALUE 'Y' 'y'.
88 OPT-MENU VALUE 'Q' 'q'.
88 EXIT-PROG VALUE 'X' 'x'.
01 WS-CHOICE PIC X VALUE SPACES.
88 CUST-SEARCH VALUE 'S' 's'.
88 OPT-SCREEN VALUE 'Q' 'q'.
01 WHICH-ENTRY PIC X VALUE SPACES.
88 PHONE VALUE 'P'.
88 CUSTID VALUE 'I'.
**********************************************************
01 CUSTOMER-TABLE VALUE SPACES.
05 EACH-CUST OCCURS 100 TIMES
DEPENDING ON CUST-CT
ASCENDING KEY T-CUST-ID
INDEXED BY X1.
10 T-CUST-ID PIC X(5).
10 T-CUST-F-NAME PIC X(15).
10 T-CUST-L-NAME PIC X(15).
10 T-CUST-ADDRESS PIC X(30).
10 T-CUST-CITY PIC X(15).
10 T-CUST-STATE PIC XX.
10 T-CUST-ZIP PIC X(5).
10 T-CUST-PHONE-NUM PIC X(14).
*********************************************************
78 BLUE VALUE 1.
78 WHITE VALUE 7.

LINKAGE SECTION.
01 USER-NAME PIC X(10).
01 CUST-CT PIC 9(3).

SCREEN SECTION.
(OMMITED TO SHORTEN)

PROCEDURE DIVISION USING USER-NAME, CUST-CT.
100-MAIN-MODULE.
PERFORM 200-INITALIZE-RTN
PERFORM 400-ACCEPT-RTN
PERFORM 800-CLOSE-RTN.

200-INITALIZE-RTN.
OPEN INPUT
CUST-FILE
MOVE FUNCTION CURRENT-DATE TO WS-DATE
MOVE CURRENT-MONTH TO MONTH-OF
MOVE CURRENT-DAY TO DAY-OF
MOVE CURRENT-YEAR TO YEAR-OF
IF FIRST-LOAD = 'Y'
MOVE 'N' TO FIRST-LOAD
PERFORM 300-LOAD-TABLE-RTN
VARYING X1 FROM 1 BY 1 UNTIL X1 > CUST-CT
END-IF.

300-LOAD-TABLE-RTN.
READ CUST-FILE
AT END DISPLAY 'NOT ENOUGH TABLE RECORDS'
STOP RUN
END-READ
MOVE CUST-INFO TO EACH-CUST (X1).

400-ACCEPT-RTN.
MOVE SPACES TO WS-CHOICE, WS-PHONE-NUM, WS-ID-IN
DISPLAY CUSTINQ01-SCREEN
ACCEPT WS-ID-IN AT LINE 10 COL 41 WITH REVERSE-VIDEO
MOVE FUNCTION UPPER-CASE (WS-ID-IN) TO WS-ID-IN
IF WS-ID-IN NOT = SPACES
IF WS-ID-IN = QUIT-OPT
PERFORM 800-CLOSE-RTN
ELSE
MOVE 'I' TO WHICH-ENTRY
PERFORM 500-SEARCH-RTN
END-IF
ELSE
ACCEPT WS-PHONE-NUM AT LINE 12 COL 41
MOVE FUNCTION UPPER-CASE (WS-PHONE-NUM) TO WS-PHONE-NUM
STRING '(' DELIMITED BY SIZE
WS-AREA DELIMITED BY SIZE
') ' DELIMITED BY SIZE
WS-CODE3 DELIMITED BY SIZE
'-' DELIMITED BY SIZE
WS-CODE4 DELIMITED BY SIZE
INTO WS-PHONE-LAST
END-STRING
IF WS-PHONE-NUM = QUIT-OPT
PERFORM 800-CLOSE-RTN
ELSE
MOVE 'P' TO WHICH-ENTRY
PERFORM 500-SEARCH-RTN
END-IF
END-IF.

500-SEARCH-RTN.
IF WHICH-ENTRY = 'I'
SEARCH ALL EACH-CUST
AT END ADD 1 TO WS-ERROR-CT PERFORM 700-ERR-RTN
WHEN T-CUST-ID (X1) = WS-ID-IN
PERFORM 600-DISPLAY-CUST
END-SEARCH
END-IF
IF WHICH-ENTRY = 'P'
SET X1 TO 1
SEARCH EACH-CUST
AT END ADD 1 TO WS-ERROR-CT PERFORM 700-ERR-RTN
WHEN WS-PHONE-LAST = T-CUST-PHONE-NUM (X1)
PERFORM 600-DISPLAY-CUST
END-SEARCH
END-IF.

600-DISPLAY-CUST.
MOVE ZEROS TO WS-ERROR-CT
IF WS-SEL-CHECK IS > 0
DISPLAY 'PLEASE MAKE A VALID SELECTION' AT LINE 23 COL 25
MOVE ZEROS TO WS-SEL-CHECK
ELSE
MOVE ZEROS TO WS-SEL-CHECK
MOVE SPACES TO WS-FINAL-NAME
MOVE SPACES TO WS-FINAL-ADDRESS
STRING T-CUST-F-NAME (X1) DELIMITED BY ' '
' ' DELIMITED BY SIZE
T-CUST-L-NAME (X1) DELIMITED BY ' '
INTO WS-FINAL-NAME
END-STRING
STRING T-CUST-CITY (X1) DELIMITED ' '
' ' DELIMITED BY SIZE
T-CUST-STATE (X1) DELIMITED BY SIZE
', ' DELIMITED BY SIZE
T-CUST-ZIP (X1) DELIMITED BY SIZE
INTO WS-FINAL-ADDRESS
END-STRING
DISPLAY FOUND-SCREEN
END-IF
ACCEPT WS-CHOICE AT LINE 1 COL 1 WITH AUTO SECURE
EVALUATE TRUE
WHEN CUST-SEARCH PERFORM 400-ACCEPT-RTN
WHEN OPT-SCREEN PERFORM 800-CLOSE-RTN
WHEN OTHER ADD 1 TO WS-SEL-CHECK
PERFORM 600-DISPLAY-CUST
END-EVALUATE.

700-ERR-RTN.
IF WS-ERROR-CT > 2
MOVE ZEROS TO WS-ERROR-CT
DISPLAY ERROR-2-SCREEN
EVALUATE TRUE
WHEN PHONE DISPLAY WS-PHONE-LAST AT LINE 8 COL 39
WHEN CUSTID DISPLAY WS-ID-IN AT LINE 8 COL 39
END-EVALUATE
ACCEPT WS-ERR-OPTION AT LINE 24 COL 1 WITH SECURE AUTO
EVALUATE TRUE
WHEN TRY-YES PERFORM 400-ACCEPT-RTN
WHEN OPT-MENU PERFORM 800-CLOSE-RTN
WHEN EXIT-PROG MOVE 'Y' TO EXIT-PROGRAM
PERFORM 800-CLOSE-RTN
WHEN OTHER PERFORM 700-ERR-RTN
END-EVALUATE
ELSE
DISPLAY ERROR-1-SCREEN
EVALUATE TRUE
WHEN PHONE DISPLAY WS-PHONE-LAST AT LINE 8 COL 39
WHEN CUSTID DISPLAY WS-ID-IN AT LINE 8 COL 39
END-EVALUATE
ACCEPT WS-ERR-OPTION AT LINE 24 COL 1 WITH SECURE AUTO
EVALUATE TRUE
WHEN TRY-YES PERFORM 400-ACCEPT-RTN
WHEN OPT-MENU PERFORM 800-CLOSE-RTN
WHEN EXIT-PROG MOVE 'Y' TO EXIT-PROGRAM
PERFORM 800-CLOSE-RTN
WHEN OTHER PERFORM 700-ERR-RTN
END-EVALUATE
END-IF.

800-CLOSE-RTN.
CLOSE CUST-FILE
MOVE SPACES TO WS-CHOICE
IF EXIT-PROGRAM = 'Y'
DISPLAY END-SCREEN
STOP RUN
END-IF
EXIT PROGRAM.
 
Gonzilla,

i have no experience with using screens in a COBOL program, but your code looks pretty structured. I would however strongly recommend not performing paragraphs from within paragraphs without returning properly, especially performing paragraphs from within themselves !
How this is implemented in the environment it is compiled for varies, but usually when a perform is executed, the return address is placed on a stack of some sort, and only removed when execution is returned in the proper order. Executing performs outside this order may leave the stack filled with return addresses, or they might even get mixed up. Anyway: best avoid it !

Try to maintain a flow of execution in your program: for instance, in 400-ACCEPT-RTN you perform 800-CLOSE-RTN when WS-ID-IN = QUIT-OPT. Not doing anything when this condition is true will result in the exact same, namely performing 800-CLOSE-RTN,
which follows right behind it !

There are more such examples; try and find them yourself.

Good luck,
Ronald.
 
Hi Tyler,

Your code looks good. I have a suggestion that may or may not be applicable to this situation. If your cust-ids range from 1 - 52 successively, you could use the following approach:

In 500-search-rtn, instead of doing a search all when
ws-which-entry = 'i', you could just:

set x1 to ws-id-in-9 and perform 600-...

Note that you must redefine ws-id-in to a 9(4) comp field.

The advantage of this approach, of course, is that you avoid doing a costly search and it simplifies the pgm logic.

The disadvantage is that you limit the contents of the id field to numerics only and that it only works if you keep a 1 to 1 correspondence between the key value and its position in the table.

In any case, its a technique that can be extremely valuable in the right situation and its worth keeping in mind.

Hope this helps, Jack.
 
Hi Tyler,

I wrongly suggested to redefine ws-id-in to a 9(4) comp field. It s/b 9(5) only.
 
Thank you all for your help! I really appreciate it.

Slade - just so you know, this Customer Inquiry Program has certain specs we have to follow - like: SEARCH ALL for id searches and SERIAL for phone numbers :-(

Our next program (the 5 labs combined make a Customer Service Program) is a Customer Maintenance area where you can add, delete or change customer info. It looks like it is a bit more challenging...Any tips or know of any good reference material (besides my text book) before I start?

Again, thanks for all of your help.

-Tyler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top