Re: multiple file reads and sorts
From: Richard (riplin_at_Azonic.co.nz)
Date: 01/06/04
- Previous message: Doug Scott: "Re: (not entirely...) OT: OPINION... chicken entrails, runic stones, and crystal balls... WAS CoBOL moved to OO"
- In reply to: ritchie: "Re: multiple file reads and sorts"
- Next in thread: ritchie: "Re: multiple file reads and sorts"
- Reply: ritchie: "Re: multiple file reads and sorts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 6 Jan 2004 11:21:45 -0800
ritchie_s01@yahoo.com (ritchie) wrote
> .......
> SORT-INPUT.
> READ File1
> INVALID KEY DISPLAY "INVALID KEY"
> SET EOF TO TRUE
> NOT INVALID SET NOT-EOF TO TRUE
> MOVE File1KEY TO File2KEY
> START File2 KEY >= File2KEY
>
> PERFORM UNTIL EOF
> READ File2 NEXT
> AT END SET EOF TO TRUE
> NOT AT END
> IF File2KEY = File1KEY
> MOVE CUSTOMER-NUMBER TO SORT-NUMBER
> MOVE CUSTOMER-NAME TO SORT-NAME
> ...
> RELEASE sort-rec
> END-IF
> END-READ
> END-PERFORM.
>
There is only ONE READ for File1 and it is a Random READ without the
key being specified. This means that the code will READ File1 _once_
and then read all of file2 sequentially starting at where it was
STARTed with the key from File1 until EOF only outputting the
record(s) that had the same key as File1.
If you were to put in the END-READ for the File1 READ you would see it
was _after_ the END-PERFORM.
You need to PERFORM the whole paragraph until the end of File1 and
within that PERFORM until no more File2 records of the same key.
You also may have a design fault in your file keys. An indexed file
can only have _ONE_ record of a particular key. If a second record
with the same key is attempted to be written it will fail with a
file-status of '22' (duplicate).
This why you only got 1 record. You only read File1 _once_ and then
read 'all' those in File2 with the same key and there was only one.
Put a File status on the program writing these files and CHECK IT.
IT seems that File1 is some sort of master, and File2 is supposed to
be a transaction file. You need to have File2 with a key that is more
than just the File1 key, it also needs to have a unique reference or a
sequence number of something.
01 Account-File. (File1)
02 Account-Key PIC X(6).
02 Account-Name .....
01 Transaction-File. (File2)
02 Transaction-Key.
03 Transaction-Account PIC X(6).
03 Transaction-Date PIC X(8). (yyyymmdd)
03 Transaction-Type PIC X.
03 Transaction-Ref PIC X(6). (eg invoice
number)
02 Transaction-Value .....
You then must check Account-Key and Transaction-Account for equality.
Also use _two_ separate EOF indicators (I use HIGH-VALUES in the keys)
and recode to get rid of nesting the READs.
- Previous message: Doug Scott: "Re: (not entirely...) OT: OPINION... chicken entrails, runic stones, and crystal balls... WAS CoBOL moved to OO"
- In reply to: ritchie: "Re: multiple file reads and sorts"
- Next in thread: ritchie: "Re: multiple file reads and sorts"
- Reply: ritchie: "Re: multiple file reads and sorts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|