View previous topic :: View next topic
|
Author |
Message |
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 55 Location: India
|
|
|
|
Hi,
I have three input file which has key in 1 to 7 and 36 to 39 in sorted order.
I need to take first file and check an indicator if it is Y then i need to check the key of the first with second if it matches then need to write to file and same to next file.
for example,
A000072 A000068 A000068
A000078 A000072 A000069
A000079 A000073 A000072
I need to take first record and find the second file exact and write some output file with some variables from first record.
how to do this,
Thanks,
Venkatraman B |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
You need to post sample data from both input files and the output you want from that sample input data. If either file can contain duplicates, show this also.
Clearly explain the "rules" for your process. |
|
Back to top |
|
|
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 55 Location: India
|
|
|
|
Hi,
Code: |
File 1 file 2 file 3
A000072........................ A000068.................... A000068......................
A000078........................ A000072.................... A000069.....................
A000079........................ A000073.................... A000072 ..................... |
A000072 matches with second record of seond file take that and write some information from A000072 to output file.
A000072 some inforamtion - first output file.
A000078 is not matched and should be written to error file.
A000068 No need to do anything with A000068 in first file |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
How many records will there be in each of the files?
What you are looking for is a 3-file match/merge - not so common. . . 2-file match/merge is very common and there is a working example of the code in the "Sticky" near the top of the COBOL part of the forum.
If one of the files is always very small, it might be read into an array and used from there. If 2 of the files could be combined, the sample code from the "Sticky" could be used.
If you start from scratch, it may take a bit of work to create the 3-file match/merge code. Due to more and more direct accrss to data, i've not needed a 3-file match/merge for over 30 years so i don't have an example. . . |
|
Back to top |
|
|
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 55 Location: India
|
|
|
|
Hi,
I am reading three sequential file on which one key is same which is 10 bit field and all the three fields are in sorted order.
I need to read the first file and match the second file and third file by key and update the records if there is no match from second file and third file to first file.
If there is no match need to write it to error record.
I am reading all the three files first record.
Code: |
IF FIRST FILE INDICATOR1 = Y AND FIRST FILE INDICATOR2 = Y
PERFORM P1300-xxx-READ THRU P1300-EXIT
UNTIL FIRST-FILE-KEY <= SECOND-FILE-KEY OR UNTIL FIRST FILE EOF
IF FIRST-KEY = SECOND FILE KEY AND SECOND FILE AND second Not EOF
COMPARE THE SOME FILEDS AND IF MATCHES
PERFORM UPDATE
ELSE
PERFORM ERROR
PERFORM SECOND FILE READ
ELSE (indicator is N and N in first file)
then same logic is perfomed against the 1 and third file. |
The above logic works and i got the output. But for the scenario,
first file 10 record with the same key and second and third file as only one file for that key.
File 1 (IND) FILE 2 FILE 3
XXXXXX1 Y Y XXXXXX1 XXXXXX1
XXXXXX1 Y Y
XXXXXX1 N N
XXXXXX1 N N
First file will check with second file but there are two records in that which will not be compared as my code will read the next record one it matches. So i need to check the both the records with file2 and same for file3
Please help me out in this |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
all the three fields are in sorted order. |
think you mean that all three files are sorted based on same field.
Quote: |
and update the records if there is no match from second file and third file to first file. |
Quote: |
COMPARE THE SOME FILEDS AND IF MATCHES
PERFORM UPDATE |
not really sure of the rules of your game.
1. can there be duplicates in any of the files? - does file1 have dups
- does file2 have dups
- does file3 have dups
2. can a key exist in file2 or 3 that does not exist in file1?
3. when is an output record generated? I assume that is what you mean by update?
since the solution is predicated on the answer to the above questions,
provide an answer. |
|
Back to top |
|
|
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 55 Location: India
|
|
|
|
hi,
1. file 1 has duplicates
2. file 1 has all the key which is in 2 and 3
3. when key matches and some comparison after that
Thanks. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
The above logic works and i got the output. But . . . |
As i mentioned in your duplicate topic - you need to test with a more complete set of sample data. I believe you will find the posted code will not even come close.
Suggest you find a way to combine files 2 & 3 before your process (using a record ndicator in addition to the keys/data) or (if one of them will always be small) load this into an array so that you are back to a 2-file match process. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
ok,
what output is generated when:- key1 = key2 & key1 = key3
- key1 = key2 & Key1<> key3
- key1 <> key2 & key1 = key3
- key1 <> key2 & Key1 <> key3
<> key means there is no match.
when file1 has duplicates, that means the above holds true for second file1 (the dup).
what output is generated?
and the other comparisons that you mention, what are they?
those also have to do with the logic. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
dbzTHEdinosauer wrote: |
- key1 = key2 & key1 = key3
- key1 = key2 & Key1<> key3
- key1 <> key2 & key1 = key3
- key1 <> key2 & Key1 <> key3
|
OK, so that is what the "List" tag does, neet... |
|
Back to top |
|
|
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 55 Location: India
|
|
|
|
Hi,
Input file :
Ln code is the comparison after the code
Key1 Ln Bi pd key2 Ln Bi PD key 3 Ln Bi Pd
10001 40 01 00 10001 40 01 00 10002 50 10 10
10001 40 01 00 10002 50 10 10
10001 50 10 10
10001 50 10 10
Before that a claim indicator is checked if it is Y then file1 is compared with file2 else file1 is compared with file3.
If key 1 = key 2
then
compare the bi of first file with second file FIRST-FILE-KEY <= SECOND-FILE-KEY OR UNTIL FIRST FILE EOF
if it matches write record
else write it to error file
compare the pd of first file with second file FIRST-FILE-KEY <= SECOND-FILE-KEY OR UNTIL FIRST FILE EOF
if it matches write record
else write it to error file
ELSE
Same logic for 1 file vs 3 file.
If the file1 key matched with file 2 it should write to output. since there are two records with the same key in first file i need to write both the record to output. But my code will not do that.
Actually i need to have a hold variable to to hold the second file key and then check the next first file comparison (LN and PD) if it matches then again i need to write.
For example the output should be like this,
output file :
Key1 Ln Bi pd updated value from key1 or key 3
10001 40 01 00 XXX
10001 40 01 00 YYYYYYY
10001 50 10 10 dddfdd
10001 50 10 10 dsfdssd
Please suggest on this,
Thanks,
venkat |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
What did you want?
This:
venkatatcts wrote: |
Key1 Ln Bi pd key2 Ln Bi PD key 3 Ln Bi Pd
10001 40 01 00 10001 40 01 00 10002 50 10 10
10001 40 01 00 10002 50 10 10
10001 50 10 10
10001 50 10 10
.
.
.
Key1 Ln Bi pd updated value from key1 or key 3
10001 40 01 00 XXX
10001 40 01 00 YYYYYYY
10001 50 10 10 dddfdd
10001 50 10 10 dsfdssd |
Or this:
Code: |
Key1 Ln Bi pd key2 Ln Bi PD key 3 Ln Bi Pd
10001 40 01 00 10001 40 01 00 10002 50 10 10
10001 40 01 00 10002 50 10 10
10001 50 10 10
10001 50 10 10
.
.
.
Key1 Ln Bi pd updated value from key1 or key 3
10001 40 01 00 XXX
10001 40 01 00 YYYYYYY
10001 50 10 10 dddfdd
10001 50 10 10 dsfdssd |
Please refer to [code]Suggestion Whenever indentation representation needed |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
You seem to be determined to continue with the same approach you started with. I believe if you continue and do get something running this way, it will not work for all situations than could be encountered in real data.
The main problem i see with this approach is that your "driver" has no way to stay in sync between the 3 files. . .
If your system has Easytrieve, you might get what you want more quickly using the MATCH function of Easytrieve.
Or look for a way to make the main process work with only 2 files by combining 2 of them before this main step or storing one in an internal array (depending on size). |
|
Back to top |
|
|
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 55 Location: India
|
|
|
|
Hi William,
I want the second one.
Thanks,
Venkat |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
You do understand that what Bill posted is both the same thing - just a different display (Quote versus Code). Did you click on the link he provided (where it says Please refere to. . .)?
You too can post in a more readable way by using the Code tag. . . |
|
Back to top |
|
|
|