Re: multiple file reads and sorts

From: Richard (riplin_at_Azonic.co.nz)
Date: 01/06/04

  • Next message: Pierra: "Re: (not entirely...) OT: OPINION... chicken entrails, runic stones, and crystal balls... WAS CoBOL moved to OO"
    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.


  • Next message: Pierra: "Re: (not entirely...) OT: OPINION... chicken entrails, runic stones, and crystal balls... WAS CoBOL moved to OO"

    Relevant Pages

    • Re: simple ln question
      ... that makes it so the contents of file1 are the same as of file2, and if you change the contents of 1, the other ... prints the inode number for the file foobar. ...
      (Fedora)
    • RE: data conundrum
      ... in your spens you'll want to keep field names consistent. ... the specs will be the most tedious, but once theyr're done once they're done. ... in other words, you have file1, file2, file3..... ...
      (microsoft.public.access.externaldata)
    • RE: data conundrum
      ... let's say file1 looks like this: ... and let's say file2 looks like this: ... then you will probably have to create import specs for all 100 ... create from the .csv files) as opposed to using a form, ...
      (microsoft.public.access.externaldata)
    • Re: Need Help
      ... eg: file1, file2, file3 etc ... into, max 5-6, chunk files and then loading these chunk files into ...
      (comp.unix.shell)
    • Re: egrep question
      ... I personally would not use grep but awk instead, especially if file1 and file2 ... If you use egrep, ... Tom Sawyer in file2. ...
      (AIX-L)