View previous topic :: View next topic |
Author |
Message |
bade_miya Beginner
Joined: 10 Dec 2003 Posts: 110 Topics: 38
|
Posted: Fri Oct 14, 2005 3:29 am Post subject: Easytrieve File Matching Question |
|
|
Hi all,
I am new to easytrieve. I am trying to write a program which compares two files and writes the matching and non matching records to two different files. I will illustrate my requirement.
Code: |
file1
-----
field1
3
5
8
file2(Look up file)
-----
field1------field2
1------------a
2------------b
3------------c
4------------d
5------------e
6------------f
|
I want to compare file1 with the lookup file to get the matching records and write field1 and field2 to an output file. If the record is not present in the lookup file(file2), the record(field1) should be written into an error file. In our example, records 3 and 5 should come in output file and 8 should come in error file.
Now i did a search to find out an easytrieve which suits my purpose. I found the below code.
Code: |
JOB INPUT(INFILE1 KEY (IN1-ERR-CDE) +
INFILE2 KEY(IN2-ERR-CDE)) +
FINISH (EOJ-REPORT)
IF MATCHED
WS-REC-NOTMATC-CNT = 0
WS-REC-READ-INFILE1 = WS-REC-READ-INFILE1 + 1
WS-REC-READ-INFILE2 = WS-REC-READ-INFILE2 + 1
WS-REC-MATC-CNT = WS-REC-MATC-CNT + 1
PUT OUTFILE FROM INFILE1
ELSE
IF INFILE1
WS-REC-READ-INFILE1 = WS-REC-READ-INFILE1 + 1
ELSE
WS-REC-READ-INFILE2 = WS-REC-READ-INFILE2 + 1
END-IF
WS-REC-NOTMATC-CNT = WS-REC-NOTMATC-CNT + 1
end-if. |
But i am not able to understand what exactly it does. Also when i tried it out, it gave me undesiered results. Can anyone please explain this. Also, the easytrieve tutorial link in the main page is not working. If this code will not serve my purpose, can anyone help me out.
Thanks
bade_miya[/list] |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Fri Oct 14, 2005 4:33 am Post subject: |
|
|
Quote: |
Also when i tried it out, it gave me undesiered results. Can anyone please explain this.
|
In easytrieve the syncronized file processing(SFP) only works when both the input files are sorted on the Key in the JOB statement. Make sure that your input files are sorted on the key.
Quote: |
If the record is not present in the lookup file(file2), the record(field1) should be written into an error file.
|
In your code you are not writting to the error file. Add the contents in bold to your code.
Quote: |
IF MATCHED
WS-REC-NOTMATC-CNT = 0
WS-REC-READ-INFILE1 = WS-REC-READ-INFILE1 + 1
WS-REC-READ-INFILE2 = WS-REC-READ-INFILE2 + 1
WS-REC-MATC-CNT = WS-REC-MATC-CNT + 1
PUT OUTFILE FROM INFILE1
ELSE
IF INFILE1
PUT ERRFILE FROM INFILE1
WS-REC-READ-INFILE1 = WS-REC-READ-INFILE1 + 1
ELSE
WS-REC-READ-INFILE2 = WS-REC-READ-INFILE2 + 1
END-IF
WS-REC-NOTMATC-CNT = WS-REC-NOTMATC-CNT + 1
end-if.
|
Quote: |
Also, the easytrieve tutorial link in the main page is not working. If this code will not serve my purpose, can anyone help me out.
|
I just checked and *is* working perfectly. The manual link is a PDF document. Make sure that you have ADOBE reader installed on your machine.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
Phantom Data Mgmt Moderator
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Fri Oct 14, 2005 5:26 am Post subject: |
|
|
Bade_Miya,
Eazytrieve can handle One-One / One-Many / Many-One Matching. But for Many-Many you need to write custom logic. You never mentioned anything about duplicates in your key field in your original post.
Do you have any duplicates in any of your input files ? if so, you need to take care of this.
Thanks,
Phantom |
|
Back to top |
|
|
bade_miya Beginner
Joined: 10 Dec 2003 Posts: 110 Topics: 38
|
Posted: Fri Oct 14, 2005 5:35 am Post subject: |
|
|
Hi Kolusu,
Thanks for the quick reply. This was a code i got from one of the previous posts int this forum. Thats why i posted it as it is. In fact i had added the statement
Quote: |
PUT ERRFILE FROM INFILE1
|
in my program. Sorry for the confusion caused. It is infact writing into the error file. But the problem is that its writing more records that i expected when i tested the code. I had manipulated the input so as to make 10 recs go into the error file for testing my code. But more than 10 (37recs) where there in error file when the program completed.
But the purpose of this post was to understand the meaning of this code given below.
and
What does this code mean? As i said, i was new to easytrieve and how i interpreted the code given below
Code: | IF MATCHED
WS-REC-NOTMATC-CNT = 0
WS-REC-READ-INFILE1 = WS-REC-READ-INFILE1 + 1
WS-REC-READ-INFILE2 = WS-REC-READ-INFILE2 + 1
WS-REC-MATC-CNT = WS-REC-MATC-CNT + 1
PUT OUTFILE FROM INFILE1
ELSE
IF INFILE1
put errorfile from infile1
ELSE
put errorfile from infile2
END-IF |
is something like this
Code: | if file1 matches file2
write outfile
else
if it is not matching
if it is in file1 and not in file2
write to error file from file1
else
if it is in file2 and not in file1
write to error file from file2
end-if
end-if
end-if
end-if |
Sorry if i am making this code look complicated or if my interpretation is wrong. . Please correct me if i am wrong.
Thanks
bade_miya |
|
Back to top |
|
|
bade_miya Beginner
Joined: 10 Dec 2003 Posts: 110 Topics: 38
|
Posted: Fri Oct 14, 2005 5:37 am Post subject: |
|
|
Hi Phantom,
Thanks for the reply. I forgot to mention that there will not be any duplicates in both the files.
thanks
bade_miya |
|
Back to top |
|
|
Phantom Data Mgmt Moderator
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Fri Oct 14, 2005 6:00 am Post subject: |
|
|
Bade_Miya,
Quote: |
Sorry if i am making this code look complicated or if my interpretation is wrong. . Please correct me if i am wrong.
|
Your interpretation is absolutely correct. If you have used the correct variables and if you still get un-expected results in the output, please post the actual JCL - YOU USED and the sample input and output files.
Thanks,
Phantom |
|
Back to top |
|
|
bade_miya Beginner
Joined: 10 Dec 2003 Posts: 110 Topics: 38
|
Posted: Fri Oct 14, 2005 6:25 am Post subject: |
|
|
Hi Phantom,
Thanks for the clarification. I used the correct variables. The only thing i am not sure about is the statement
Code: | JOB INPUT(INFILE1 KEY (IN1-ERR-CDE) +
INFILE2 KEY(IN2-ERR-CDE)) + |
Can anyone tell me whether there will be an impact(and what the impact is if there is one) if i change the order of infile. What i meant to say is that, will it mean the same if i wrote this code as
Code: | JOB INPUT(INFILE2 KEY(IN2-ERR-CDE)) +
INFILE1 KEY (IN1-ERR-CDE) + |
File2 is my lookup file and it has more records than file1.
At present i am trying to test the same, if its not successful, i will post the jcl i used.
Thanks
bade_miya |
|
Back to top |
|
|
Phantom Data Mgmt Moderator
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Fri Oct 14, 2005 6:28 am Post subject: |
|
|
Bade_miya,
The order of files given in the JOB INPUT statement does NOT AFFECT your code unless you have duplicates in any one of the file.
Since, you already said that there are NO Dups in BOTH the files, there is no difference in having FILE 2 first followed by FILE 1. Number of records in the files have no significance over this. You only need to be concerned on the duplicate key.
Thanks,
Phantom |
|
Back to top |
|
|
bade_miya Beginner
Joined: 10 Dec 2003 Posts: 110 Topics: 38
|
Posted: Fri Oct 14, 2005 7:41 am Post subject: |
|
|
Hi Phantom/Kolusu,
Its working perfectly now. Thanks for all the clarifications. There was a logical error in my program which caused problems. I rectified it and tested my code.
thanks
Bade_miya |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Fri Oct 14, 2005 7:50 am Post subject: |
|
|
bade_miya,
The following JCL will give you a very clear idea about matching in easytrieve. Look at the sysout for Outfile and errfile.
Code: |
//STEP0100 EXEC PGM=EZTPA00
//*
//STEPLIB DD DSN=EASYTREV.LOADLIB,
// DISP=SHR
//EZTVFM DD UNIT=SYSDA,SPACE=(CYL,(50,50),RLSE)
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSSNAP DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//INFILE1 DD *
3
5
8
//INFILE2 DD *
1------------A
2------------B
3------------C
4------------D
5------------E
6------------F
//OUTFILE DD SYSOUT=*,
// DCB=(LRECL=80,RECFM=FB,BLKSIZE=0)
//ERRFILE DD SYSOUT=*,
// DCB=(LRECL=80,RECFM=FB,BLKSIZE=0)
//SYSIN DD *
FILE INFILE1
IN1-REC 01 80 A
IN1-ERR-CDE 01 01 A
FILE INFILE2
IN2-REC 01 80 A
IN2-ERR-CDE 01 01 A
FILE OUTFILE FB(0 0)
OUT-REC 01 80 A
OUT-COMMENT 40 40 A
FILE ERRFILE FB(0 0)
ERR-REC 01 80 A
ERR-COMMENT 40 40 A
WS-MATCH-COUNT W 09 N 0 VALUE 0
WS-ERR-INFILE1-COUNT W 09 N 0 VALUE 0
WS-ERR-INFILE2-COUNT W 09 N 0 VALUE 0
**********************************************************************
* PROCESSES AREA
**********************************************************************
JOB INPUT(INFILE1 KEY (IN1-ERR-CDE) +
INFILE2 KEY(IN2-ERR-CDE)) +
FINISH (EOJ-REPORT)
IF MATCHED
OUT-REC = IN1-REC
OUT-COMMENT = 'THIS RECORD IS FOUND IN BOTH FILE'
PUT OUTFILE
WS-MATCH-COUNT = WS-MATCH-COUNT + 1
ELSE
IF INFILE1
ERR-REC = IN1-REC
ERR-COMMENT = 'THIS RECORD IS FOUND ONLY IN INFILE1'
PUT ERRFILE
WS-ERR-INFILE1-COUNT = WS-ERR-INFILE1-COUNT + 1
ELSE
ERR-REC = IN2-REC
ERR-COMMENT = 'THIS RECORD IS FOUND ONLY IN INFILE2'
PUT ERRFILE
WS-ERR-INFILE2-COUNT = WS-ERR-INFILE2-COUNT + 1
END-IF
END-IF.
EOJ-REPORT. PROC
DISPLAY 'THE TOTAL NO: OF MATCHED RECORDS : ' WS-MATCH-COUNT
DISPLAY 'THE TOTAL ERROR RECORDS ON INFILE1: ' WS-ERR-INFILE1-COUNT
DISPLAY 'THE TOTAL ERROR RECORDS ON INFILE2: ' WS-ERR-INFILE2-COUNT
END-PROC
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
bade_miya Beginner
Joined: 10 Dec 2003 Posts: 110 Topics: 38
|
Posted: Fri Oct 14, 2005 9:42 am Post subject: |
|
|
Hi Kolusu,
Thank you so much for the code. It made things very clear. I am really impressed with easytrieve. I think in quick job(which i was using earlier) we will have to do more complex coding to accomplish the same task. By the way, what u said about the link was correct. The site which i am working right now dosent have PDF. I guess i will have to access the easytrieve link in this site from elsewhere. nyways thanks again.
bade_miya. |
|
Back to top |
|
|
Phantom Data Mgmt Moderator
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Fri Oct 14, 2005 9:49 am Post subject: |
|
|
Bade_Miya,
Quote: |
we will have to do more complex coding to accomplish the same task
|
I am not good in Quikjob, But I don't think that quikjob requires a complex logic for this case. Have you used the TABLE option of Quikjob ??? I think that is really easy to use.
If you have the quikjob, please post it here. We can see if that could be tweaked.
Thanks,
Phantom |
|
Back to top |
|
|
bade_miya Beginner
Joined: 10 Dec 2003 Posts: 110 Topics: 38
|
Posted: Fri Oct 14, 2005 11:06 am Post subject: |
|
|
Hi Phantom,
No, i havent used the TABLE options in quick job. Even i am not good in quick job. When this kind of requirment came in my previous co, i remember we used quick job for that. There was an existing program then. So we tweaked that one. But the only thing i remember is that that coding was much more complex than this one. Does quick job has an inbuild logic for file comparison as ezytrieve?
Regards
bade_miya |
|
Back to top |
|
|
Phantom Data Mgmt Moderator
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Sat Oct 15, 2005 8:08 am Post subject: |
|
|
Bade_Miya,
Quote: |
Does quick job has an inbuild logic for file comparison as ezytrieve?
|
Yep !!! it indeed has. But the table key field must be unique. Post your jcl and input file data, We will see how that could be tweaked.
Thanks,
Phantom |
|
Back to top |
|
|
bade_miya Beginner
Joined: 10 Dec 2003 Posts: 110 Topics: 38
|
Posted: Tue Oct 18, 2005 3:10 am Post subject: |
|
|
Hi Phantom,
Sorry for the late reply. As i said, i had that quikjob in my previous co. In my present co, i dont have it.But if i come across any such code, i will post here and we will give it a try. Thanks again for the help
thanks
bade_miya |
|
Back to top |
|
|
|
|