View previous topic :: View next topic
|
Author |
Message |
rkarthik22
New User
Joined: 18 Apr 2009 Posts: 47 Location: India
|
|
|
|
Hi all,
I have two files file1 and file2
File1 LRECL is 250 bytes (duplicates is there)
emp-key1 which is of 28 bytes
File2 LRECL is 500 (duplicates are not there)
emp-key2 which is of 28 bytes
I have to match this two file on emp-key
Requirement:
READ ONE fILE( say file1)
SCAN THE WHOLE File for the 2nd File (say file2) if matching on emp key
Match is found- write the records to Matched File- records from File1, Records from file2
if match is not found- implies record is present only on the input file 1
write the record in the output1 file
this is what i tried..
I should not use IF MATCHED condition here
Quote: |
FILE FILE1 FB (250 0)
INP1-REC 01 250 A
EMP-KEY1 13 28 A
FILE FILE2 FB (500 0)
INP2-REC 01 500 A
EMP-KEY2 01 28 A
FILE OUTPUT FB (800 0)
OUT-REC1 01 800 A
FILE OUTPUT1 (500 0)
OUT-REC2 01 500 A
JOB INPUT(NULL) +
START(FST-PROCESS) +
FINISH(LAST)
DO WHILE NOT EOF FILE1 AND WS-CNT LE 10
GET FILE1
DISPLAY 'READ FILE1'
DO WHILE NOT EOF FILE2
GET FILE2
DISPLAY 'READ FILE2'
PERFORM CHANGE-MAN-DIFF
END-DO
WS-CNT = WS-CNT + 1
END-DO
FST-PROCESS. PROC
WS-RECORD-CNT = 0
WS-RECORD-CNT1 = 0
WS-CNT = 0
END-PROC
CHANGE-MAN-DIFF. PROC
IF EMP-KEY1 = EMP-KEY2
DISPLAY 'MATCH COND'
[i am moving all the matched input records to the output file]
PUT OUTPUT
WS-RECORD-CNT = WS-RECORD-CNT + 1
ELSE
OUT-REC2 = INP2-REC
PUT OUTPUT1
WS-RECORD-CNT1 = WS-RECORD-CNT1 + 1
END-IF
END-PROC
LAST. PROC
DISPLAY 'NO OF MATCHED RECORDS : ', WS-RECORD-CNT
DISPLAY 'NO OF FFDONLY RECORDS : ', WS-RECORD-CNT1
END-PROC |
my inner DO WHILE loop is working fine..i.e..(DO WHILE NOT EOF FILE2)
its processing fine for the first record in input file1.
But the outer loop is not working...i mean after completing the process for the first record ...the control is not moving to the second record of the input
file 1.. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Please do not post the same topic on multiple helpboards. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I should not use IF MATCHED condition here |
Probably should. . . After ensuring both files are in proper sequence. |
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
What output (displays) are you getting?
It looks to me that this code should:
read 1 record from file1
read and process all of the records from file2
read 9 more records from file1
end
Is this what the displays show?
Is this what you want it to do? |
|
Back to top |
|
|
rkarthik22
New User
Joined: 18 Apr 2009 Posts: 47 Location: India
|
|
|
|
when i execute this code...i got invalid file reference - FILE2. erorr
The inner Do-while loop is working....dut it doesnt come out and read the second record of the FILE1..[/quote] |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I should not use IF MATCHED condition here |
To repeat. . . . You probably should use MATCH. . .
Sort both files on the "key" and match them.
Quote: |
i got invalid file reference - FILE2. erorr |
As expected. . .
Why is there such determination to not use the provided match feature? |
|
Back to top |
|
|
rkarthik22
New User
Joined: 18 Apr 2009 Posts: 47 Location: India
|
|
|
|
dick scherrer
This time i sorted both the files...eventhough i got the same error
invalid file reference - FILE2
(input file 1 - sorted, with duplicates)
(input file 2 - sorted, without duplicates) |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
DId you also use the built-in match function or did you try to read file2 multiple times?
I the data is in key sequence, one pass thru the data should be all that is needed. |
|
Back to top |
|
|
rkarthik22
New User
Joined: 18 Apr 2009 Posts: 47 Location: India
|
|
|
|
ok..
instead of this complicated (i feel!!) DO - WHILE, i used IF NOT EOF logic
Quote: |
JOB INPUT(NULL) +
START(INIT-PROCESS) +
FINISH(WRAP-UP)
IF NOT EOF FFDFILE
GET FFDFILE
DISPLAY 'READING FFDFILE'
IF NOT EOF CARAWCC
GET CARAWCC
DISPLAY 'READING CARAWCC'
PERFORM CHANGE-MAN-DIFF
IF CARA-EOF = 'Y'
END-IF
END-IF
IF WS-FFD-EOF = 'Y'
END-IF
WS-CNT = WS-CNT + 1
END-IF |
This is reading two files....
First its reading 1 records from Ffdfile and scanning/reading all the records from carawcc file...
if match is found its writing to the output file...
My problem after reading all the records from carawcc file ...its not coming out of that inner loop and its not reading the second record from ffd file...
is this looping is correct?! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
First its reading 1 records from Ffdfile and scanning/reading all the records from carawcc file... |
You have been told repeatedly that this is not how to meet your requirement.
Quote: |
is this looping is correct?! |
NO.
Match the files by the key that is common to both files. . . .
If you had properly matched the files when it was first suggested, your process would be running now. . .
There is a big difference between persistence and stubbornness.
There is also a "Sticky" near the top of the cobol part of the forum that demonstrates how to write a 2-file match/merge without using a builtin MATCH function. It is all done in the code. |
|
Back to top |
|
|
rkarthik22
New User
Joined: 18 Apr 2009 Posts: 47 Location: India
|
|
|
|
dick scherrer wrote: |
Hello,
Quote: |
First its reading 1 records from Ffdfile and scanning/reading all the records from carawcc file... |
You have been told repeatedly that this is not how to meet your requirement.
Quote: |
is this looping is correct?! |
NO.
Match the files by the key that is common to both files. . . .
If you had properly matched the files when it was first suggested, your process would be running now. . .
There is a big difference between persistence and stubbornness.
There is also a "Sticky" near the top of the cobol part of the forum that demonstrates how to write a 2-file match/merge without using a builtin MATCH function. It is all done in the code. |
Hi d.sch,
The requirement itself changed , and i got the expected output files after implementing a simple IF MATCHED logic in EZT.
Thanks titan for your effort!! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
You're welcome - good to hear it is working
Thank you for letting us know.
Someone will be here if there are questions later.
d |
|
Back to top |
|
|
|