Page 1 of 1
Create multiple records on the basis of counts in a field
Posted:
Mon Sep 06, 2010 1:01 pm
by Himanshu.Verma
Hi,
I have been looking a number of links to findout the solution for my specific requirement but did not find anyone.
I need to create multiple records of one input record based on the count in a perticular field in the input record.
if the count in the field is 2 then it should write 2 records and if the field has 5 then it sud write 5 records in the output file.
Does anybody have any solution using SORT. Any help will be highly apprreciated.
Regards,
Himanshu
Re: Create multiple records on the basis of counts in a field
Posted:
Mon Sep 06, 2010 10:02 pm
by dick scherrer
Hello and welcome to the forum,
In addition to the "rules" you need to post some sample input data and the output you want when that sample iknput is processed.
Also, mention the dsorg and lrecl of the files.
Re: Create multiple records on the basis of counts in a field
Posted:
Tue Sep 07, 2010 10:06 am
by Himanshu.Verma
Hello Dick,
Thanks, below mention are the two sample records in the file with
Record format . . . : FB
Record length . . . : 78
000001 Y <4 -Ø 020001001 -c -Ø 0000 -Ø<90448UNDE NOF
002E0000110004F00000000681FFFFFFFFF000681068100340FFFF0684FFFFFEDCC4DDC4
00C80000C0C01C400C0000800C0200010010C803C800C0050D0000800C90448454505660
------------------------------------------------------------------------------
000002 *Y <4 -Ø 020001001 -c -Ø 0000 -Ø<90448UNDE NOF
005E0000110004F00000000681FFFFFFFFF000681068100340FFFF0684FFFFFEDCC4DDC4
00C80000C0C01C400C0000800C0200010010C803C800C0050D0000800C90448454505660
------------------------------------------------------------------------------
The first three character contains a count in PD. Now I have the requirement as per the count i need to write that many records.
i.e. for the first record,the count is 2 so it should write 2 records in the output similarly for the next record the count is 5 so the output file shall contain 5 records.
E.g.
000001 Y <4 -Ø 020001001 -c -Ø 0000 -Ø<90448UNDE NOF
002E0000110004F00000000681FFFFFFFFF000681068100340FFFF0684FFFFFEDCC4DDC4
00C80000C0C01C400C0000800C0200010010C803C800C0050D0000800C90448454505660
------------------------------------------------------------------------------
000001 Y <4 -Ø 020001001 -c -Ø 0000 -Ø<90448UNDE NOF
002E0000110004F00000000681FFFFFFFFF000681068100340FFFF0684FFFFFEDCC4DDC4
00C80000C0C01C400C0000800C0200010010C803C800C0050D0000800C90448454505660
------------------------------------------------------------------------------
000002 *Y <4 -Ø 020001001 -c -Ø 0000 -Ø<90448UNDE NOF
005E0000110004F00000000681FFFFFFFFF000681068100340FFFF0684FFFFFEDCC4DDC4
00C80000C0C01C400C0000800C0200010010C803C800C0050D0000800C90448454505660
------------------------------------------------------------------------------
000002 *Y <4 -Ø 020001001 -c -Ø 0000 -Ø<90448UNDE NOF
005E0000110004F00000000681FFFFFFFFF000681068100340FFFF0684FFFFFEDCC4DDC4
00C80000C0C01C400C0000800C0200010010C803C800C0050D0000800C90448454505660
------------------------------------------------------------------------------
000002 *Y <4 -Ø 020001001 -c -Ø 0000 -Ø<90448UNDE NOF
005E0000110004F00000000681FFFFFFFFF000681068100340FFFF0684FFFFFEDCC4DDC4
00C80000C0C01C400C0000800C0200010010C803C800C0050D0000800C90448454505660
------------------------------------------------------------------------------
000002 *Y <4 -Ø 020001001 -c -Ø 0000 -Ø<90448UNDE NOF
005E0000110004F00000000681FFFFFFFFF000681068100340FFFF0684FFFFFEDCC4DDC4
00C80000C0C01C400C0000800C0200010010C803C800C0050D0000800C90448454505660
------------------------------------------------------------------------------
000002 *Y <4 -Ø 020001001 -c -Ø 0000 -Ø<90448UNDE NOF
005E0000110004F00000000681FFFFFFFFF000681068100340FFFF0684FFFFFEDCC4DDC4
00C80000C0C01C400C0000800C0200010010C803C800C0050D0000800C90448454505660
------------------------------------------------------------------------------
Regards,
Himanshu
Re: Create multiple records on the basis of counts in a field
Posted:
Tue Sep 07, 2010 11:08 pm
by Frank Yaeger
DFSORT does not have any built-in functions to repeat records based on a count in each record. I would suggest you write your own program, or E35 exit, to do this.
Re: Create multiple records on the basis of counts in a field
Posted:
Tue Oct 12, 2010 1:34 am
by kilaru
I am not denying what Frank Said, but, incase if you are not comfortable writng Exit Routines and the multiple occurrences are not greater than 9 for any key, then you can think of writing 10 OUTFIL Statements as below.
//SYMNAMES DD *
KEY-COUNT,1,3,PD
//*
OUTFIL R1, INCLUDE=(KEY-COUNT,EQ,+1)
OUTFIL R2, INCLUDE=(KEY-COUNT,EQ,+2)
,,
,,
OUTFIL R9, INCLUDE=(KEY-COUNT,EQ,+9)
* capture all others into a file.
OUTFIL SAVE,FNAMES=OTHERS
Thanks
Krishna Kilaru
Re: Create multiple records on the basis of counts in a field
Posted:
Tue Oct 12, 2010 1:52 am
by kilaru
Sorry, I missed to include REPEAT Parm earlier. Here are the OUTFIL statements with REPEAT par,
//SYMNAMES DD *
KEY-COUNT,1,3,PD
//*
//SORTCNTL DD *
OUTFIL R1, INCLUDE=(KEY-COUNT,EQ,+1),REPEAT=1
OUTFIL R2, INCLUDE=(KEY-COUNT,EQ,+2),REPAET=2
,,
,,
OUTFIL R9, INCLUDE=(KEY-COUNT,EQ,+9),REPEAT=9
* capture all others into a file.
OUTFIL SAVE,FNAMES=OTHERS
//*
Thanks
Krishna Kilaru
Re: Create multiple records on the basis of counts in a field
Posted:
Tue Oct 12, 2010 2:03 am
by Frank Yaeger
Kilaru,
If you had actually tried your suggested control statements, you would have found they have syntax errors.
Please don't post untested solutions here.
Re: Create multiple records on the basis of counts in a field
Posted:
Tue Oct 12, 2010 3:16 am
by kilaru
Sorry Frank. I was just curious to present my thought and didn't pay much attention on Syntax or Testing. Here after I will make sure to test before posting.
Here are the control cards from my Test run that used ICETOOL. I found from this test that REPEAT=n is valid when 'n' is any except 1.
000037 //SYMNAMES DD *
000038 KEY-COUNT,1,3,PD
000039 //*
000040 //OPTIONS DD SYSOUT=*
000041 //SYSOUT DD SYSOUT=*
000042 //SYSUDUMP DD SYSOUT=*
000043 //TOOLIN DD *
000044 SORT FROM(FILEIN) USING(CTL1)
000045 /*
000046 //CTL1CNTL DD *
000047 SORT FIELDS=(COPY)
000048 OUTFIL FNAMES=R1,
000049 INCLUDE=(KEY-COUNT,EQ,+1)
000050 OUTFIL FNAMES=R2,REPEAT=2,
000051 INCLUDE=(KEY-COUNT,EQ,+2)
000052 OUTFIL FNAMES=R3,REPEAT=3,
000053 INCLUDE=(KEY-COUNT,EQ,+3)
000054 OUTFIL SAVE,FNAMES=OTHERS
000055 /*
Here is what I got in my DFSMSG.
ICE055I 0 INSERT 0, DELETE 0
ICE054I 0 RECORDS - IN: 3, OUT: 3
ICE227I 0 R1 : DELETED = 2, REPORT = 0, DATA = 1
ICE228I 0 R1 : TOTAL IN = 3, TOTAL OUT = 1
ICE227I 0 R2 : DELETED = 2, REPORT = 0, DATA = 2
ICE228I 0 R2 : TOTAL IN = 3, TOTAL OUT = 2
ICE227I 0 R3 : DELETED = 2, REPORT = 0, DATA = 3
ICE228I 0 R3 : TOTAL IN = 3, TOTAL OUT = 3
ICE227I 0 OTHERS : DELETED = 3, REPORT = 0, DATA = 0
ICE228I 0 OTHERS : TOTAL IN = 3, TOTAL OUT = 0
ICE174I 0 NO DATA RECORDS FOR AN OUTFIL DATA SET - RC=0
ICE052I 0 END OF DFSORT
Re: Create multiple records on the basis of counts in a field
Posted:
Tue Oct 12, 2010 5:28 am
by steve-myers
kilaru - I think most of us that respond fairly often have been guilty of making this kind of goof. Me, I learned my lesson long ago. These days I try everything before I post!