Page 1 of 1

jcl to merge file based on keys

PostPosted: Thu Apr 07, 2011 12:28 pm
by Kasikannan
Hi,

My input is

AAAA111 12
BBBB222 13
CCCC333 14
and
DDDD444 15
EEEE555 16
FFFF666 17

My output should be
AAAA111 12
BBBB222 13
CCCC333 14
DDDD444 .. 15
EEEE555 .. 16
FFFF666 .. 17

I used sort card as below
//SYSIN DD *
JOINKEYS FILES=F1,FIELDS=(01,07,A)
JOINKEYS FILES=F2,FIELDS=(01,07,A)
JOIN UNPAIRED
REFORMAT FIELDS=(F1:1,10,F2:1,12),FILL=X'FF'
SORT FIELDS=COPY
OUTREC IFTHEN=(WHEN=(01,10,BI,EQ,X'FF'),BUILD=(8,7))

/*

and I got the output as
AAAA111 12
BBBB222 13
CCCC333 14
.............. DDDD444 15
...............EEEE555 16
...............FFFF666 17

How can i get the expected result? Please help

Re: jcl to merge file based on keys

PostPosted: Thu Apr 07, 2011 1:38 pm
by enrico-sorichetti
from topic title and the sample posted a plain sort should be enough!
if it is not so ... reword everything and post more meaningful examples

Re: jcl to merge file based on keys

PostPosted: Thu Apr 07, 2011 2:01 pm
by Kasikannan
Hi,

Hope this may give a clear view

input file1:
aaaa xxx
bbbb yyy
cccc zzz

input file2:
aaaa 111
dddd 222
eeee 333

required output file:
aaaa xxx 111
bbbb yyy space
cccc zzz space
dddd space 222
eeee space 333

Re: jcl to merge file based on keys

PostPosted: Thu Apr 07, 2011 8:46 pm
by Frank Yaeger
You can use a DFSORT job like the following to do what I think you're asking for:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//IN1 DD *
aaaa xxx
bbbb yyy
cccc zzz
//IN2 DD *
aaaa 111
dddd 222
eeee 333
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  JOINKEYS F1=IN1,FIELDS=(1,4,A)
  JOINKEYS F2=IN2,FIELDS=(1,4,A)
  JOIN UNPAIRED
  REFORMAT FIELDS=(F1:1,9,F2:6,3)
  OPTION COPY
/*

Re: jcl to merge file based on keys

PostPosted: Tue Jul 23, 2013 5:43 pm
by raulravi
Dear Frank,

I have tried your sort code:
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//IN1 DD *
aaaa xxx
bbbb yyy
cccc zzz
//IN2 DD *
aaaa 111
dddd 222
eeee 333
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  JOINKEYS F1=IN1,FIELDS=(1,4,A)
  JOINKEYS F2=IN2,FIELDS=(1,4,A)
  JOIN UNPAIRED
  REFORMAT FIELDS=(F1:1,9,F2:6,3)
  OPTION COPY
/*


The output is :
************
AAAA XXX 111
BBBB YYY   
CCCC ZZZ   
         222
         333
************


But the expected out put is :
************
AAAA XXX 111
BBBB YYY   
CCCC ZZZ   
DDDD        222
EEEE         333
************


Can you please advice?

Raul

Re: jcl to merge file based on keys

PostPosted: Tue Jul 23, 2013 5:45 pm
by raulravi
Expected output is:
************
AAAA XXX 111
BBBB YYY   
CCCC ZZZ   
DDDD     222
EEEE     333
***********

Re: jcl to merge file based on keys

PostPosted: Tue Jul 23, 2013 6:58 pm
by NicC
First, you should not tailgate old topics - start a new topic with a reference to the topic you are refering to.
Second, you should not address a post to a specific person. It is fine if you do not want an answer from anyone else but you will have to be prepared to wait for ever as Frank retired some time ago and no longer contributes.
Third, what have you done to try and understand why you are getting the result you show?
Fourth, what have you tried in order to get the answer that YOU want?

Re: jcl to merge file based on keys

PostPosted: Tue Jul 23, 2013 9:33 pm
by dick scherrer
Hello and welcome to the forum,

For us to help, it will be best if you post the informational messages that were gnerated by the run. Include the message ids.

Re: jcl to merge file based on keys

PostPosted: Tue Jul 23, 2013 10:25 pm
by skolusu
raulravi,

Use the following control cards.

//SYSIN   DD *                                         
  JOINKEYS F1=IN1,FIELDS=(1,4,A)                       
  JOINKEYS F2=IN2,FIELDS=(1,4,A)                       
  JOIN UNPAIRED                                       
  REFORMAT FIELDS=(F1:1,9,F2:1,4,6,3,?)               
  INREC IFOUTLEN=12,                                   
  IFTHEN=(WHEN=(17,1,CH,EQ,C'B'),BUILD=(1,9,14,3)),   
  IFTHEN=(WHEN=(17,1,CH,EQ,C'2'),BUILD=(10,4,5X,14,3))
  OPTION COPY                                         
//*