|
|
| Author |
Message |
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 41 Location: India
|
|
|
|
Hi,
Below are the two files. The key for both files are first seven digit and 3 digit field.
file 1 will have single occurence of the key where as the file 2 will multiple occurence. I need to compare the key first if it matches then i need to compare the third col between the files and if also matches then i need to move the four col from file1 to third column in file2.
Since it is a multi occurence.
I have used this logic ( both the files are in sorted order)
if no match found
perform read file 2 until key2 <= key1 and end of file = 'n'
peform update.
UPDATE.
READ READ FILE 1
EXIT.
INS LINE TRIGGER FILE
| Code: |
AZDGHFG XDR 100 200
AZDGHFT XDR 100 500
BGDXDRY XDR 100 600
GYTRTUV XDR 100 700 |
CEDED CLAIM CHAR UNLOAD FILE
| Code: |
AAAAAAA XDR 100
ABSSSSS XDR 100
AV11111 XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFT XDR 100
AZDGHFT XDR 100
BGDXDRY XDR 100
BGDXDRY XDR 100
BGDXDRY XDR 100
GYTRTUV XDR 100
GYTRTUV XDR 100 |
I guess below logic will update only single occurrence.
first method:
| Code: |
IF KEY2 = KEY 1
THEN
READ FILE1
READ FILE2
ELSE
IF KEY2 < KEY 1
READ FILE2
ELSE
READ FILE1
END-IF
END-IF |
second method:
| Code: |
IF KEY1 = KEY 2
THEN
READ FILE1
READ FILE2
ELSE
IF KEY1 < KEY 2
READ FILE1
ELSE
READ FILE2
END-IF
END-IF |
|
|
| Back to top |
|
 |
References
|
|
 |
dick scherrer
Global Moderator
Joined: 23 Nov 2006 Posts: 15176 Location: 221 B Baker St
|
|
|
|
Hello,
There is tested sample code to accomplish a 2-file match/merge posted as a "Sticky" at the top of the COBOL part of the forum.
Download this to your pc and then upload to your source library (use Right-Click, Save. . .).
Change this for your records/keys and implement the logic you need beyond the match/merge. |
|
| Back to top |
|
 |
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 41 Location: India
|
|
|
|
Hi,
Thanks. But I need to write for all the matching records whereas that logic will match single occurence and then it will read the other records of the next file which should not be. that's why i gave all the three logic and whether first one is correct or the second or the third. |
|
| Back to top |
|
 |
dick scherrer
Global Moderator
Joined: 23 Nov 2006 Posts: 15176 Location: 221 B Baker St
|
|
|
|
Hello,
The sample will properly handle a one-to-many match/merge. . .
Suggest you post the output you want from those 2 sets of input.
Your posts will be more effective when you use the "Code" tag. . . |
|
| Back to top |
|
 |
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 41 Location: India
|
|
|
|
| Code: |
INS LINE TRIGGER FILE
AZDGHFG XDR 100 200
AZDGHFT XDR 100 500
BGDXDRY XDR 100 600
GYTRTUV XDR 100 700
CEDED CLAIM CHAR UNLOAD FILE
AAAAAAA XDR 100
ABSSSSS XDR 100
AV11111 XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFG XDR 100
AZDGHFT XDR 100
AZDGHFT XDR 100
BGDXDRY XDR 100
BGDXDRY XDR 100
BGDXDRY XDR 100
GYTRTUV XDR 100
GYTRTUV XDR 100
above two are my input files.
output files:
AAAAAAA XDR 100
ABSSSSS XDR 100
AV11111 XDR 100
AZDGHFG XDR 200
AZDGHFG XDR 200
AZDGHFG XDR 200
AZDGHFG XDR 200
AZDGHFG XDR 200
AZDGHFT XDR 500
AZDGHFT XDR 500
BGDXDRY XDR 100
BGDXDRY XDR 600
BGDXDRY XDR 600
GYTRTUV XDR 700
GYTRTUV XDR 700 |
[img][/img] |
|
| Back to top |
|
 |
dick scherrer
Global Moderator
Joined: 23 Nov 2006 Posts: 15176 Location: 221 B Baker St
|
|
|
|
Hello,
Suggest you look at this bit of the sample code:
| Code: |
100-CAP-ELIG-MATCH.
* these may change depending on how duplicates are handled.
* MOVE 'Y' TO NEED-CAP, NEED-ELG.
MOVE 'Y' TO NEED-ELG. |
If you change the code to only read the file with duplicates rather than automatically reading both files, it should do what you want. . . - once your custom code is added. |
|
| Back to top |
|
 |
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2216 Location: At my coffee table
|
|
|
|
| venkatatcts wrote: |
| that's why i gave all the three logic and whether first one is correct or the second or the third. |
What 'third'?
Hasn't anybody taught you how to design such a program?
Start with the middle where both files are in the middle of processing, do compares and process.
Then figure how to get the initial states set with opens and initial reads.
Then figure how to handle end-of-files from either and finish the writes and close. |
|
| Back to top |
|
 |
dick scherrer
Global Moderator
Joined: 23 Nov 2006 Posts: 15176 Location: 221 B Baker St
|
|
|
|
Hi Bill,
The "third" is actually first and is sort of pseudo-code and text and i didn't "Code" it. . .
The reason i posted that Sticky so long ago is that many new people are not being shown this most basic process during training. . .
d |
|
| Back to top |
|
 |
|
|