View previous topic :: View next topic |
Author |
Message |
rkarthik22 Beginner
Joined: 27 Sep 2008 Posts: 24 Topics: 9
|
Posted: Sun Apr 26, 2009 8:03 am Post subject: many to many match easytrieve |
|
|
I have two input files INP1 and INP2.
I have to match two files on A1 field/key (Present in both the files)
If match is found. Again i have to check if match on P1 field/key (Present in both the files)
And present in INP1 ,write in to separate file
And present in INP2, write in to separate file
If match is not found on P1 ,
And present only in INP1 ,write in to separate file
And present only in INP2, write in to separate file
If match is not found on A1
write INP1 records in to separate file
write INP2 records in to separate file
requirement:
IF match is found on A1 key
Check if match on P1 key
Write INP1 records in to separate file
Write INP2 records in to separate file
If match is not found on P1 key
And present only in INP1 ,write in to separate file
And present only in INP2, write in to separate file
ELSE
IF match is not found on A1 key
write INP1 records in to separate file
write INP2 records in to separate file
Please help me how to do this in easytrieve using Many to Many match |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Sun Apr 26, 2009 8:13 am Post subject: |
|
|
rkarthik22,
*Sigh*
1. Sort file1 with A1 P1 key combination Ascending
2. Sort file2 with A1 P1 key combination Ascending
3. Read file1
4. Read file2
5. If file1 combo key = file2 combo key , load f2 records into an internal table
6. write the output from the internal table and initialize it before every load
7. If unmatched write to the respective output files
Kolusu |
|
Back to top |
|
 |
rkarthik22 Beginner
Joined: 27 Sep 2008 Posts: 24 Topics: 9
|
Posted: Sun Apr 26, 2009 8:19 am Post subject: |
|
|
Kolusu..
I have to deliver this tomorrow...can u please help me to write Easytrieve code..
As i dont know abt this internal table concept
Thanks in advance.. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Sun Apr 26, 2009 8:30 am Post subject: |
|
|
rkarthik22 wrote: | Kolusu..
I have to deliver this tomorrow...can u please help me to write Easytrieve code..
As i dont know abt this internal table concept
Thanks in advance.. |
rkarthik22,
I am sorry I can't.
Kolusu |
|
Back to top |
|
 |
Anuj Dhawan Intermediate
Joined: 19 Jul 2007 Posts: 298 Topics: 7 Location: Mumbai,India
|
Posted: Fri May 01, 2009 9:47 am Post subject: |
|
|
Hi,
Probably if you show what you have done so far some one will be around to make you progress litltle faster. _________________ Regards,
Anuj |
|
Back to top |
|
 |
rkarthik22 Beginner
Joined: 27 Sep 2008 Posts: 24 Topics: 9
|
Posted: Sat May 09, 2009 8:22 am Post subject: |
|
|
Hi kolusu/anuj model,
I am back ....i have tries for the past 7 days to code (Many to Many match Easytrieve)
This is my requirement.
Input file 1:
INFILE1 LRECL = 149
Product 01 11 A
Account Key 12 28 A
SSN 104 09 A
Input file 2:
INFILE2 LRECL = 133
Product 01 11 A
Account Key 12 28 A
SSN 104 09 A
Match the two input files on Account key
If matches on Account key
Check if matches on Product
Write Input file 1 records to output file 1
Write Input file 2 records to output file 2
If match is not found on Product
And present only in Input file 1,move zeros to SSN field and
write the records to the same output file 1
And present only in Input file 2,move zeros to SSN field and
write the records to the same output file 2
If match is not found on account key
And present only in input file 1, write the records to output file 3
And present only in input file 2, write the records to output file 4
(Technical Tip: It will be MANY to MANY Easytrieve match, needs to be accomplished using GET file. IF MATCHED condition will not work here) |
|
Back to top |
|
 |
rkarthik22 Beginner
Joined: 27 Sep 2008 Posts: 24 Topics: 9
|
Posted: Sat May 09, 2009 10:43 am Post subject: |
|
|
Here is my Code...
********************************************************************
PARM DEBUG (NODMAP FLDCHK FLOW STATE XREF LONG) +
ABEXIT (NOSNAP) VFM (4000)
********************************************************************
FILE INFILE1 FB(149 0)
I1-PRODUCT 01 11 A
I1-ACCOUNT-KEY 12 28 A
I1-SSN 104 09 A
FILE INFILE2 FB(133 0)
I2-PRODUCT 01 11 A
I2-ACCOUNT-KEY 12 28 A
I2-SSN 104 09 A
FILE OUTFIL1 FB(149 0)
PRODUCT1 01 11 A
ACCOUNT-KEY1 12 28 A
SSN1 104 09 A
FILE OUTFIL2 FB(133 0)
PRODUCT2 01 11 A
ACCOUNT-KEY2 12 28 A
SSN2 104 09 A
FILE OUTFIL3 FB(149 0)
PRODUCT3 01 11 A
ACCOUNT-KEY3 12 28 A
SSN3 104 09 A
FILE OUTFIL4 FB(133 0)
PRODUCT4 01 11 A
ACCOUNT-KEY4 12 28 A
SSN4 104 09 A
**********COUNTERS*********
WS-IN1-MATCH-COUNT W 5 P 0 VALUE +0
WS-IN2-MATCH-COUNT W 5 P 0 VALUE +0
WS-IN1-MATCH-COUNT1 W 5 P 0 VALUE +0
WS-IN2-MATCH-COUNT1 W 5 P 0 VALUE +0
WS-INFILE1-COUNT W 5 P 0 VALUE +0
WS-INFILE2-COUNT W 5 P 0 VALUE +0
***********TEMP VARIABLE***********
WS-IN1-ACCT-KEY W 28 A
WS-IN1-PRODUCT W 11 A
WS-IN1-SSN W 09 A
WS-IN1-ACCT-KEY-TEMP W 28 A
WS-IN1-PRODUCT-TEMP W 11 A
WS-IN1-SSN-TEMP W 09 A
WS-IN2-ACCT-KEY W 28 A
WS-IN2-PRODUCT W 11 A
WS-IN2-SSN W 09 A
WS-IN2-ACCT-KEY-TEMP W 28 A
WS-IN2-PRODUCT-TEMP W 11 A
WS-IN2-SSN-TEMP W 09 A
WS-INP1-EOF W 1 A VALUE 'N'
WS-INP2-EOF W 1 A VALUE 'N'
*****************************************************
JOB INPUT(NULL) +
START(INIT-PROCESS) +
FINISH(WRAP-UP)
PERFORM GET-INP1-FILE
PERFORM GET-INP2-FILE
MAIN-PROCESS.
IF WS-INP1-EOF = 'Y' AND +
WS-INP2-EOF = 'Y'
ELSE
IF WS-IN1-ACCT-KEY = WS-IN2-ACCT-KEY
IF WS-IN1-PRODUCT = WS-IN2-PRODUCT
IF WS-INP2-EOF = 'N' OR +
WS-INP1-EOF = 'N'
PRODUCT1 = WS-IN1-PRODUCT
ACCOUNT-KEY1 = WS-IN1-ACCT-KEY
SSN1 = WS-IN1-SSN
WS-IN1-MATCH-COUNT = WS-IN1-MATCH-COUNT + 1
PUT OUTFIL1
PRODUCT2 = WS-IN2-PRODUCT
ACCOUNT-KEY2 = WS-IN2-ACCT-KEY
SSN2 = WS-IN2-SSN
WS-IN2-MATCH-COUNT = WS-IN2-MATCH-COUNT + 1
PUT OUTFIL2
END-IF
WS-IN1-ACCT-KEY-TEMP = WS-IN1-ACCT-KEY
WS-IN1-PRODUCT-TEMP = WS-IN1-PRODUCT
WS-IN1-SSN-TEMP = WS-IN1-SSN
WS-IN2-ACCT-KEY-TEMP = WS-IN2-ACCT-KEY
WS-IN2-PRODUCT-TEMP = WS-IN2-PRODUCT
WS-IN2-SSN-TEMP = WS-IN2-SSN
PERFORM GET-INP2-FILE
PERFORM GET-INP1-FILE
ELSE
IF WS-IN1-PRODUCT > WS-IN2-PRODUCT
IF WS-IN1-PRODUCT-TEMP = WS-IN2-PRODUCT AND +
WS-IN1-PRODUCT-TEMP NOT SPACES AND +
WS-INP2-EOF = |
|
Back to top |
|
 |
rkarthik22 Beginner
Joined: 27 Sep 2008 Posts: 24 Topics: 9
|
Posted: Sat May 09, 2009 10:56 am Post subject: |
|
|
I got the following outputs
OUTFIL1 4 RECORDS
OUTFIL2 5 RECORDS
OUTFIL3 12 RECORDS
OUTFIL4 6 RECORDS
OUTFIL3 has got more number of records(both input files has got only 10 records) than i expected, which is wrong
Please guide me whether my logic is correct or not?! |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Sun May 10, 2009 5:04 am Post subject: |
|
|
rkarthik22,
No offense but you made the program rather large and complex than it needs to be. It almost made me go blind!
Ps: Here is an untested code.Use this code at your own risk as I won't be answering any more questions regarding this code.
It is a basic skeleton program which does all the work as per your requirement, with minimal error checking. It is written in english like language and if you can't make this code work go back to your old code and try to figure out what went wrong with it.
Code: |
INFILE1 INFILE2
ACCT-KEY ACCT-KEY
A A
A A
B A
B
|
Easytrieve IF Matched logic(aka synchronized File Processing) would process the first INFILE1 key A against all of the INFILE2 key A records and the second key A record from INFILE1 would be presented as NOT MATCHED.
The below code will read the first key A record from INFILE1 and the first Key A record from INFILE2 and present that as a MATCH, it will then read INFILE2 record 2 and present that as a match with the first record from INFILE1. While this processing is going on, the INFILE2 records are being stored in the array. Once we read the fourth record in INFILE2 and encounter an unmatched key we then read ahead in INFILE1, since the ACCOUNT-KEY of INFILE1 matches the WS-SAVE-KEY we will process the second record from INFILE1 against the array of INFILE2 records. Record two from INFILE1 is the last duplicate which causes the array to be emptied. Processing continues to the next record in INFILE1 which now matches the current key of INFILE2, another MATCH condition.
You don't need to code DCB parms in the program, just make sure that you code them in the JCL. This applies only for the output files(outfil1 thru outfil4).
Code: |
// DCB=(LRECL=nnn,RECFM=FB,BLKSIZE=0)
|
PGM
Code: |
FILE INFILE1
I1-REC 001 149 A
I1-PRODUCT 001 011 A
I1-ACCOUNT-KEY 012 028 A
I1-SSN 104 009 A
FILE INFILE2
I2-REC 001 133 A
I2-PRODUCT 001 011 A
I2-ACCOUNT-KEY 012 028 A
I2-SSN 104 009 A
FILE OUTFIL1 FB(0 0)
O1-REC 001 149 A
O1-SSN 104 009 A
FILE OUTFIL2 FB(0 0)
O2-REC 001 133 A
O2-SSN 104 009 A
FILE OUTFIL3 FB(0 0)
FILE OUTFIL4 FB(0 0)
**********COUNTERS***********************
WS-ONLYF1-COUNT W 5 P 0 VALUE +0
WS-ONLYF2-COUNT W 5 P 0 VALUE +0
WS-F1-ACT-MATCH-COUNT W 5 P 0 VALUE +0
WS-F2-ACT-MATCH-COUNT W 5 P 0 VALUE +0
WS-PRD-MATCH-COUNT W 5 P 0 VALUE +0
WS-PRD-NOMATCH-COUNT W 5 P 0 VALUE +0
***********Array Declaration**************
ENTIRE-ARRAY W 2680 A VALUE ' '
WSB-ARRAY ENTIRE-ARRAY 0134 A OCCURS 20
WSB-PRODUCT WSB-ARRAY 0011 A
WSB-SSN WSB-ARRAY +103 0009 A
WSB-MTCH WSB-ARRAY +133 0001 A
***********TEMP VARIABLE*****************
WS-ARRAY-CNT W 02 B 0 VALUE 0
WS-ARRAY-SUB W 02 B 0 VALUE 0
WS-SAVE-KEY W 28 A
S-WRITE-CHECK W 01 A VALUE 'N'
*****************************************************
JOB INPUT (INFILE1 KEY(I1-ACCOUNT-KEY) +
INFILE2 KEY(I2-ACCOUNT-KEY)) +
FINISH (WRAP-UP)
IF MATCHED
IF FIRST-DUP INFILE1
WS-F2-ACT-MATCH-COUNT = WS-F2-ACT-MATCH-COUNT + 1
PERFORM ARRAY-LOADB
ELSE
WS-F1-ACT-MATCH-COUNT = WS-F1-ACT-MATCH-COUNT + 1
WS-F2-ACT-MATCH-COUNT = WS-F2-ACT-MATCH-COUNT + 1
IF I1-PRODUCT = I2-PRODUCT
PERFORM WRITE-PRD-MATCH
ELSE
WS-PRD-NOMATCH-COUNT = WS-PRD-NOMATCH-COUNT + 1
PERFORM WRITE-ONLYF1
O2-REC = I2-REC
PERFORM WRITE-ONLYF2
END-IF
END-IF
WS-SAVE-KEY = I1-ACCOUNT-KEY
ELSE-IF INFILE1
IF I1-ACCOUNT-KEY = WS-SAVE-KEY
PERFORM ARRAY-LOOKUP
IF LAST-DUP INFILE1
PERFORM CHECK-IN2-AND-INIT
END-IF
ELSE
WS-ONLYF1-COUNT = WS-ONLYF1-COUNT + 1
PUT OUTFIL3 FROM INFILE1
END-IF
ELSE-IF INFILE2
WS-ONLYF2-COUNT = WS-ONLYF2-COUNT + 1
PUT OUTFIL4 FROM INFILE2
END-IF
ARRAY-LOADB. PROC
WS-ARRAY-CNT = WS-ARRAY-CNT + 1
IF WS-ARRAY-CNT > 20
DISPLAY 'ARRAY OVERLOAD - INCREASE OCCURS NUMBER'
STOP EXECUTE
END-IF
WSB-ARRAY (WS-ARRAY-CNT) = I2-REC
IF I1-PRODUCT = I2-PRODUCT
WSB-MTCH(WS-ARRAY-CNT) = 'Y'
PERFORM WRITE-PRD-MATCH
ELSE
WSB-MTCH(WS-ARRAY-CNT) = 'N'
END-IF
END-PROC
WRITE-PRD-MATCH. PROC
WS-PRD-MATCH-COUNT = WS-PRD-MATCH-COUNT + 1
PUT OUTFIL1 FROM INFILE1
PUT OUTFIL2 FROM INFILE2
END-PROC
ARRAY-LOOKUP. PROC
WS-F1-ACT-MATCH-COUNT = WS-F1-ACT-MATCH-COUNT + 1
WS-ARRAY-SUB = 1
S-WRITE-CHECK = 'N'
DO WHILE WS-ARRAY-SUB LE WS-ARRAY-CNT
IF I1-PRODUCT = WSB-PRODUCT(WS-ARRAY-CNT)
WS-PRD-MATCH-COUNT = WS-PRD-MATCH-COUNT + 1
WSB-MTCH(WS-ARRAY-CNT) = 'Y'
PUT OUTFIL1 FROM INFILE1
O2-REC = WSB-ARRAY(WS-ARRAY-CNT)
PUT OUTFIL2
END-IF
S-WRITE-CHECK = 'Y'
END-DO
IF S-WRITE-CHECK = 'N'
WS-PRD-NOMATCH-COUNT = WS-PRD-NOMATCH-COUNT + 1
PERFORM WRITE-ONLYF1
END-IF
END-PROC
WRITE-ONLYF1. PROC
O1-REC = I1-REC
O1-SSN = '000000000'
PUT OUTFIL3
END-PROC
WRITE-ONLYF2. PROC
O2-SSN = '000000000'
PUT OUTFIL4
END-PROC
CHECK-IN2-AND-INIT. PROC
WS-ARRAY-SUB = 1
DO WHILE WS-ARRAY-SUB LE WS-ARRAY-CNT
IF WSB-MTCH(WS-ARRAY-CNT) = 'N'
WS-PRD-NOMATCH-COUNT = WS-PRD-NOMATCH-COUNT + 1
O2-REC = WSB-ARRAY(WS-ARRAY-CNT)
O2-SSN = '000000000'
PUT OUTFIL2
END-IF
END-DO
MOVE SPACES TO ENTIRE-ARRAY
WS-ARRAY-CNT = 0
END-PROC
WRAP-UP. PROC
DISPLAY 'NO: OF RECORDS ON INFILE1 : ' INFILE1:RECORD-COUNT
DISPLAY 'NO: OF RECORDS ON INFILE2 : ' INFILE2:RECORD-COUNT
DISPLAY ' '
DISPLAY 'NO: OF INFILE1 ACCOUNT MATCH : ' WS-F1-ACT-MATCH-COUNT
DISPLAY 'NO: OF INFILE2 ACCOUNT MATCH : ' WS-F2-ACT-MATCH-COUNT
DISPLAY ' '
DISPLAY 'NO: OF PRODUCT MATCHES : ' WS-PRD-MATCH-COUNT
DISPLAY 'NO: OF MISMATCHES ON PRODUCT : ' WS-PRD-NOMATCH-COUNT
DISPLAY ' '
DISPLAY 'ONLY IN INFILE1 FILE RECORDS : ' WS-ONLYF1-COUNT
DISPLAY 'ONLY IN INFILE2 FILE RECORDS : ' WS-ONLYF2-COUNT
END-PROC
|
|
|
Back to top |
|
 |
|
|