|
View previous topic :: View next topic
|
| Author |
Message |
Guirao
New User

Joined: 27 Nov 2007 Posts: 7 Location: Madrid
|
|
|
|
Hi,
I want to repeat all input records seven times into the output file through "one only" SORT.
Thanks. |
|
| Back to top |
|
 |
Escapa
Senior Member

Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Probably You need to use
OUTFIL REPEAT=7
But to get precise answer
you need to post sample input and desired output  |
|
| Back to top |
|
 |
Guirao
New User

Joined: 27 Nov 2007 Posts: 7 Location: Madrid
|
|
|
|
This is my SORT:
| Quote: |
//SORT0001 EXEC PGM=SORT
//SORTIN DD DSN=XE04183.INICIO,DISP=SHR
//SORTOUT DD DSN=XE04183.INICIO.SALIDA,
// DISP=(,CATLG,DELETE),
// SPACE=(CYL,(1,5),RLSE)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL REPEAT=7 |
and this is my input file:
| Quote: |
....REC 1
....REC 2 |
... and the result:
| Quote: |
....REC 1
....REC 1
....REC 1
....REC 1
....REC 1
....REC 1
....REC 1
....REC 2
....REC 2
....REC 2
....REC 2
....REC 2
....REC 2
....REC 2 |
But I want to repeat the block of the input file, so i wish is that following:
| Quote: |
....REC 1
....REC 2
....REC 1
....REC 2
....REC 1
....REC 2
....REC 1
....REC 2
....REC 1
....REC 2
....REC 1
....REC 2
....REC 1
....REC 2 |
Thanks[/quote] |
|
| Back to top |
|
 |
Escapa
Senior Member

Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Change your code as below
| Code: |
//SORT0001 EXEC PGM=SORT
//SORTIN DD DSN=XE04183.INICIO,DISP=SHR
// DD DSN=XE04183.INICIO,DISP=SHR
// DD DSN=XE04183.INICIO,DISP=SHR
// DD DSN=XE04183.INICIO,DISP=SHR
// DD DSN=XE04183.INICIO,DISP=SHR
// DD DSN=XE04183.INICIO,DISP=SHR
// DD DSN=XE04183.INICIO,DISP=SHR
//SORTOUT DD DSN=XE04183.INICIO.SALIDA,
// DISP=(,CATLG,DELETE),
// SPACE=(CYL,(1,5),RLSE)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
/*
|
|
|
| Back to top |
|
 |
Guirao
New User

Joined: 27 Nov 2007 Posts: 7 Location: Madrid
|
|
|
|
OK, the results where exactly what i want.
Thanks a lot.
Regards. |
|
| Back to top |
|
 |
Escapa
Senior Member

Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
| Quote: |
OK, the results where exactly what i want.
Thanks a lot. |
U R Welcome  |
|
| Back to top |
|
 |
cybertaurean
New User

Joined: 22 Dec 2008 Posts: 87 Location: US
|
|
|
|
@Escapa... Can anything be done through sort if the # of required repetitions (in the fashion mentioned above) is huge... say 10000 times.
I believe dataset concatenation wouldn't work in such a case. Any other option to get it done using SORT?
Regards,
C.T. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
'course you can.
Use the first method to replicate the individual records 10000. Sequence number each individual record starting from 1 until the next record that gets replicated. Sort on the sequence number, with EQUALS, strip off the sequence number. You should have now a file which is replicated in its' entirety 10,000 times.
Don't have the code for it (I think you were just curious :-) ). Don't know if it can be done in one step. Don't see why it can't be done. Can't imagine yet why anyone would want to.
Frank or Kolusu will probably say I don't need to over-complicate, and do it in two lines :-) They, and the product, are so good that nothing would surprise me. |
|
| Back to top |
|
 |
cybertaurean
New User

Joined: 22 Dec 2008 Posts: 87 Location: US
|
|
|
|
@bill: awesome! i was thinking on lines of what u felt kolusu or frank might talk about... i.e. without having to use a sequence number
thanks a lot!!!  |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| cybertaurean wrote: |
| @Escapa... Can anything be done through sort if the # of required repetitions (in the fashion mentioned above) is huge... say 10000 times. |
cybertaurean,
As bill mentioned here it CAN be done. And bill yes it is indeed easy ,however there is a catch.
Case 1
If Number of input records >= repetition factor then 1 pass of data with JOINKEYS
case 2
If Number of input records < repetition factor then you need 2 passes of data.
Case 1 solution
Joinkeys can be used to do Many to Many match. And we will use that feature to generate the data. The trick here is to use the same dataset for both JNF1 and JNF2 and then match on a key we add at the end of the record.
| Code: |
//STEP0100 EXEC PGM=SORT,REGION=0M
//SYSOUT DD SYSOUT=*
//INA DD *
REC01
REC02
REC03
REC04
REC05
REC06
REC07
REC08
REC08
REC10
//INB DD *
REC01
REC02
REC03
REC04
REC05
REC06
REC07
REC08
REC08
REC10
//SORTOUT DD SYSOUT=*
//SYSIN DD *
JOINKEYS F1=INA,FIELDS=(81,1,A),SORTED,NOSEQCK
JOINKEYS F2=INB,FIELDS=(01,1,A),SORTED,NOSEQCK
REFORMAT FIELDS=(F1:1,80,F2:2,8)
INCLUDE COND=(81,8,ZD,LE,7) <<== CODE REPEAT FACTOR HERE
SORT FIELDS=(81,8,CH,A),EQUALS
OUTREC BUILD=(1,80)
//*
//JNF1CNTL DD *
INREC OVERLAY=(81:X)
//*
//JNF2CNTL DD *
INREC BUILD=(X,SEQNUM,8,ZD)
//* |
Case 2 solution:
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
REC01
REC02
REC03
//SORTOUT DD DSN=&&IN,DISP=(,PASS),SPACE=(CYL,(10,10),RLSE)
//SYSIN DD *
SORT FIELDS=COPY
OUTREC OVERLAY=(81:SEQNUM,8,ZD)
OUTFIL REPEAT=7, <<== CODE REPEAT FACTOR HERE
IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(81,8)))
//*
//STEP0200 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=&&IN,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(81,8,CH,A),EQUALS
OUTREC BUILD=(1,80)
//* |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Very nice, Kolusu, very nice.
So, when requiring multiple duplications of a dataset:
- If it needs only be "logical", concatenate (up to max allowed) into desired program
- If it needs to be "physical" (on one dataset)
concatenate with sort, up to max allowed
- Else, Case 1 when records >= repetition factor
- Otherwise, Case 2
If it is a close call for Case 1, Case 2 will always work, but with two passes of the data. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|