View previous topic :: View next topic
|
Author |
Message |
dunkinjonats
New User
Joined: 14 Aug 2008 Posts: 2 Location: Philippines
|
|
|
|
Hi,
I'm a newbie here and just starting to learn about cobol.
I need to extract records from 3 sequential files namely CURRENT, INSURANCE and ACCOUNTS files.
The first file that needs to be read is the CURRENT file until EOF then look for its matching records in INSURANCE and ACCOUNTS files using the ACCOUNT-NO.
Can someone help me on how to do read and match files? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
The first file that needs to be read is the CURRENT file until EOF then look for its matching records |
This makes absolutely no sense -- why would you read until end-of-file on a file you're trying to match records on?
One possibility: ensure the files are sorted and use the two-file match provided in the sticky against two of your files to produce a temporary file that is then matched against the third file in a second application of the same technique.
Or, take the two-file solution and generalize it by adding the third file logic. This definitely gets trickier though since instead of three key conditions to worry about you have 9 to think through. |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
Hi dunkinjonats !
You could also achieve this by using the SORT utility. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Basically, you have one loop on the main file.
There are few methods for doing this, maybe your shop has standards.
The code in the loop will be executed once for each record in CURRENT.
This code will contain access to the 2nd and 3rd file, then will get a new record for the next pass:
Code: |
PERFORM F10-READ-FIRST-CURRENT
PERFORM UNTIL FLAG-EOF-CURRENT
DISPLAY 'PROCESSING ACCOUNT NUMBER ' ACCOUNT-NO OF CURRENT
PERFORM F30-READ-INSURANCE-BY-KEY
PERFORM F40-READ-ACCOUNTS-BY-KEY
PERFORM D10-DO-MAIN-THING
PERFORM F20-READ-NEXT-CURRENT
END-PERFORM |
When you reach D10 for the 1st time, you have in W-S the 3 records:
CURRENT (from F10), INSURANCE (from F30) and ACCOUNTS (from F40).
After that, you reach D10 again but with another CURRENT record (from F20) with new matching companions.
FLAG-EOF-CURRENT is set to true in the AT END clause in F10 and F20. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Keep this page bookmarked (seriously, you will need it. Print it if you can, too). |
|
Back to top |
|
|
|