Page 1 of 1

JOINKEYS to find non matched records

PostPosted: Wed Mar 30, 2016 10:20 am
by Papya013
Hi Team,

I have two input files as mentioned below. On non matching condition the input file FLAG which is at position 10 has to be overwritten with 'J'.

FILE1:

1234 ABCD N 9999


FILE2:

2345 ABCD J 9999
2356 ABCD N 9999


I tried with below mentioned SORT card but its not giving the results as expected instead I am getting the below mentioned output.
SORT CARD:
JOINKEYS FILES=F1,FIELDS=(12,4,A,5,4,A,10,1,A)          
JOINKEYS FILES=F2,FIELDS=(12,4,A,5,4,A,10,1,A)          
JOIN UNPAIRED,F1,ONLY                                    
REFORMAT FIELDS=(F1:1,16)                              
SORT FIELDS=(1,4,CH,A,5,4,CH,A)                          
OUTREC IFTHEN=(WHEN=(10,1,CH,EQ,C'N'),OVERLAY=(10:C'J'))


Current output:
1234 ABCD N 9999


Expected output:
1234 ABCD J 9999


Could anyone help me out with this ?

Re: JOINKEYS to find non matched records

PostPosted: Wed Mar 30, 2016 11:13 am
by Aki88
Hello,

Couple of minor changes to your SORT card; with your current SYSIN statement, no SORTOUT is generated since there are no unpaired records for the positions you've mentioned against your input data.
With updated offset and addition of first 4 bytes in the JOINKEYS statement in SYSIN:


 JOINKEYS FILES=F1,FIELDS=(13,4,A,6,4,A,11,1,A,1,4,A)    
 JOINKEYS FILES=F2,FIELDS=(13,4,A,6,4,A,11,1,A,1,4,A)    
 JOIN UNPAIRED,F1,ONLY                                  
 REFORMAT FIELDS=(F1:1,16)                              
 SORT FIELDS=(1,4,CH,A,6,4,CH,A)                        
 OUTREC IFTHEN=(WHEN=(11,1,CH,EQ,C'N'),OVERLAY=(11:C'J'))
 


It gives:

1234 ABCD J 9999


Hth.

Re: JOINKEYS to find non matched records

PostPosted: Wed Mar 30, 2016 12:10 pm
by BillyBoyo
Papya013,

As Aki88 pointed out, you would not get any output with that data and those control cards, so you'd best explain how you got some output, because something you've posted is not correct.

Aki88,

Ask questions before providing code in these types of cases. Although the JOINKEYS positions are likely wrong, you have no way to guess that 1,4 should be part of the joining key, other than to guess. Get the requirement clear before providing code, please.

Re: JOINKEYS to find non matched records

PostPosted: Fri Apr 01, 2016 10:03 am
by Papya013
I am sorry for the little confusion with the position of the fields mentioned in the code.

1234 ABCD N 9999
records in FILE1 with matching keys as
13,4,A,6,4,A,11,1,A,1,4,A
will not be present in the other file with which we will compare.

The scenario is matching keys as
(13,4,A,6,4,A,11,1,A)
there will be few records in FILE2.

So the requirement is to update the flag as 'J' on FILE1 record on not finding a matching with the join keys combination mentioned in LINE 2(which means that records unmatched only because of flag).

Kindly let me know if this is still unclear, I can try to explain in different ways.