Page 1 of 2

combine multiple rows into one row using sort

PostPosted: Wed Jan 06, 2010 6:28 pm
by sharmiladevi
Hi All,

I have a requirement to combine multiple rows in input file into one record in output file.

Input file (FB,LRECL=80):

AAAAA
BBBBB
CCCCC
DD
EEEEE
FFFFF
GGGGG
HH

Requirement : combine 4 ROWS into 1 ROW in the output file

Output file(FB,LRECL=337):

AAAAABBBBBCCCCCDD
EEEEEFFFFFGGGGGHH

Thanks
Sharmila T

Re: combine multiple rows into one row using sort

PostPosted: Wed Jan 06, 2010 10:32 pm
by Frank Yaeger
Your requirement is not clear. Do you want to remove the trailing blanks from each record before you combine them, or combine all 80 bytes from each record (with trailing blanks), or what? Why would the output have LRECL=337 instead of LRECL=320 (4 * 80)?

Would the output records really be:

   80          80         80     80
|AAAAA......|BBBBB....|CCCCC...|DD...|

Re: combine multiple rows into one row using sort

PostPosted: Thu Jan 07, 2010 1:01 am
by sharmiladevi
Hi Frank,
Yes. I want to combine all 80 bytes from each record. Assume the output length would have LRECL=320. The output records in your example is correct.

Thanks,
Sharmila T

Re: combine multiple rows into one row using sort

PostPosted: Thu Jan 07, 2010 2:21 am
by Frank Yaeger
Here's a DFSORT/ICETOOL job that will do what you asked for:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=...  input file (FB/80)
//OUT DD DSN=...  output file (FB/320)
//TOOLIN   DD    *
SPLICE FROM(IN) TO(OUT) ON(321,8,ZD) KEEPNODUPS WITHANY -
  WITH(81,80) WITH(161,80) WITH(241,80) USING(CTL1)
/*
//CTL1CNTL DD *
  OPTION COPY
  INREC IFOUTLEN=328,
    IFTHEN=(WHEN=GROUP,RECORDS=4,PUSH=(321:ID=8,329:SEQ=1)),
    IFTHEN=(WHEN=(329,1,ZD,EQ,2),BUILD=(81:1,80,321:321,8)),
    IFTHEN=(WHEN=(329,1,ZD,EQ,3),BUILD=(161:1,80,321:321,8)),
    IFTHEN=(WHEN=(329,1,ZD,EQ,4),BUILD=(241:1,80,321:321,8))
  OUTFIL FNAMES=OUT,BUILD=(1,320)
/*

Re: combine multiple rows into one row using sort

PostPosted: Fri Jan 08, 2010 8:52 pm
by sharmiladevi
Thanks a lot.. will try this code and let you know the results

Thanks
Sharmila T

Re: combine multiple rows into one row using sort

PostPosted: Wed Jan 13, 2010 6:16 pm
by upendra_water
Wow. Just one word Frank. Amazing. :o
I just tested this and it works perfectly.

Re: combine multiple rows into one row using sort

PostPosted: Tue Sep 28, 2010 3:24 pm
by Vicky007
hi all,

The requirement is basically similar; but i need to combine based on a specific criteria. PFB the I/P n required O/P.
Input file (FB,LRECL=80):

@AAAAA
BBBBB
CCCCC
DD
@CCC
AAAAA
@FFFF
@DDDDDD
PPPPP
VVVVV
GGGGG
HHHHHH

Required O/P
@AAAAABBBBBCCCCCDD
@CCCAAAAA
@FFFF
@DDDDDDPPPPPVVVVVGGGGGHHHHHH

I Should combine the records until I find '@' in the first byte of the record.
I want to remove the trailing blanks from each record before I combine them.

Please provide ur suggestion.

Thanks in advance!
Vicky SK

Re: combine multiple rows into one row using sort

PostPosted: Wed Sep 29, 2010 2:22 am
by Frank Yaeger
In the private message you sent me, you added this to the requirement:

3) There is no limit for the max. number of records between 2 '@'.


Really - if there were 5000 * 80 byte records, how would you combine them into one 40000 byte record given that exceeds the maximum allowed LRECL?

For the technique I used previously and the extension of that technique to do the grouping by @, there are definitely practical limits to the number of records that can be joined and the resulting joined record length.

Re: combine multiple rows into one row using sort

PostPosted: Wed Sep 29, 2010 8:17 am
by Vicky007
Hi Frank,

My mistake; when I said 'There is no limit' I tried to mean the number of records b/w 2 '@' may vary. It can be from 1 to 50. We may know it only during run time. Can you suggest something for this?

Thanks in advance!
Vicky SK

Re: combine multiple rows into one row using sort

PostPosted: Wed Sep 29, 2010 8:24 pm
by Vicky007
Hi Frank,
I used the code you suggested to Sharmiladevi and wrote the below code. It worked good and I got the desired output. However, when I tried for records more than 50 to be joined(ie, number of records b/w 2 '@'), I'm getting error. Because am using more than 50 'WITH' keyword in SPLICE operator.

Do you have any other suggestion to address this issue? Below is the piece of code that I used assuming I need to combine 50 records into one.

//TOOLIN DD *
SPLICE FROM(IN) TO(OUT) ON(30001,8,ZD) KEEPNODUPS WITHANY -
WITH(81,80) WITH(161,80) WITH(241,80) WITH(321,80) WITH(401,80) -
"
"
"
WITH(4001,80) USING(CTL1)
/*
//CTL1CNTL DD *
OPTION COPY
INREC IFOUTLEN=30008,
IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'@'),
PUSH=(30001:ID=8,30009:SEQ=5)),
IFTHEN=(WHEN=(30009,5,ZD,EQ,2),BUILD=(81:1,80,30001:30001,8)),
IFTHEN=(WHEN=(30009,5,ZD,EQ,3),BUILD=(161:1,80,30001:30001,8)),
"
"
"
IFTHEN=(WHEN=(30009,5,ZD,EQ,51),BUILD=(4001:1,80,30001:30001,8))
OUTFIL FNAMES=OUT,BUILD=(1,30000)
/*

Please provide ur suggestion.

Thanks in advance!
Vicky SK