Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Here's a DFSORT/ICETOOL job that will do what you asked for. I assumed your input files have RECFM=FB and LRECL=80 but the job can be changed appropriately for other attributes.
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD *
F1 RECORD 01
F1 RECORD 02
F1 RECORD 03
F1 RECORD 04
F1 RECORD 05
F1 RECORD 06
F1 RECORD 07
F1 RECORD 08
F1 RECORD 09
F1 RECORD 10
F1 RECORD 11
F1 RECORD 12
F1 RECORD 13
/*
//IN2 DD *
F2 RECORD 01
F2 RECORD 02
F2 RECORD 03
F2 RECORD 04
/*
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//TOOLIN DD *
COPY FROM(IN1) TO(T1) USING(CTL1)
COPY FROM(IN2) TO(T2) USING(CTL2)
/*
//CTL1CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD,START=10,INCR=10)
/*
//CTL2CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD,START=31,INCR=30)
/*
//S2 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN01 DD DSN=&&T1,DISP=(OLD,PASS)
//SORTIN02 DD DSN=&&T2,DISP=(OLD,PASS)
//SORTOUT DD DSN=... output file (FB/80)
//SYSIN DD *
MERGE FIELDS=(81,8,ZD,A)
OUTREC BUILD=(1,80)
/*
SORTOUT would have:
Code:
F1 RECORD 01
F1 RECORD 02
F1 RECORD 03
F2 RECORD 01
F1 RECORD 04
F1 RECORD 05
F1 RECORD 06
F2 RECORD 02
F1 RECORD 07
F1 RECORD 08
F1 RECORD 09
F2 RECORD 03
F1 RECORD 10
F1 RECORD 11
F1 RECORD 12
F2 RECORD 04
F1 RECORD 13
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
hsk wrote:
But how this works and how can i modify it
(e.g. instade of 1 line from file 2 i want to insert 5 lines from file 2!!!)
Your previous example has only 4 records in file 2, is there more? Do you mean to have 5 from file 2 inserted after each line from file 1 or after every third line from file 1?
Quote:
especially
//CTL1CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD,START=10,INCR=10)
Okey ............
Now i got little idea how it is working!
Insert a seq. number after from position 81...
Increment file 1 by 10 .......... 10,20,30 .........
Increment file 2 by 30 .......... 31,61,91 ..........
Then merge 2 files and take only 80 bytes ..........
Wooooh! Smart way !!!!!
This works gr88888888 .............
But again, how to change it if i want to insert 2 records from file 2 after 3 records from file 1
Output shud look like
Code:
F1 RECORD 01
F1 RECORD 02
F1 RECORD 03
F2 RECORD 01
F2 RECORD 02
F1 RECORD 04
F1 RECORD 05
F1 RECORD 06
F2 RECORD 03
F2 RECORD 04
F1 RECORD 07
............. so on
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
hsk wrote:
But again, how to change it if i want to insert 2 records from file 2 after 3 records from file 1
Can you think of a sequencing method to get you what you want?
Have you looked at the manual and some of the smart sort tricks?
DFSORT/ICETOOL Reference Material
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
hsk,
Did you figure it out or do you need more help? If you did figure it out, please post your solution to help others in the future who might look at this topic.
Yup ...........
I could make it work ...........
Not sure if this THE BEST solution, rather this not the best solution .....
Following are the details @ my problem and the solution,
Problem:
I have 2 files File1 and File2
Code:
File1 File2
F1 RECORD 01 F2 RECORD 01
F1 RECORD 02 F2 RECORD 02
F1 RECORD 03 F2 RECORD 03
F1 RECORD 04 F2 RECORD 04
F1 RECORD 05 F2 RECORD 05
F1 RECORD 06 F2 RECORD 06
F1 RECORD 07 F2 RECORD 07
F1 RECORD 08 F2 RECORD 08
F1 RECORD 09 F2 RECORD 09
F1 RECORD 10 F2 RECORD 10
F1 RECORD 11 F2 RECORD 11
F1 RECORD 12 F2 RECORD 12
F1 RECORD 13 F2 RECORD 13
So on ........
Now i want to insert certain records from file2 in to file1 with specific order. Suppose e.g. i want to insert 5 records from file2 after 3 records from file1.
So output should look like
Code:
output file
F1 RECORD 01
F1 RECORD 02
F1 RECORD 03
F2 RECORD 01
F2 RECORD 02
F2 RECORD 03
F2 RECORD 04
F2 RECORD 05
F1 RECORD 04
F1 RECORD 05
F1 RECORD 06
F2 RECORD 06
F2 RECORD 07
F2 RECORD 08
F2 RECORD 09
F2 RECORD 10
F1 RECORD 07
F1 RECORD 08
F1 RECORD 09
so on ........
Solution:
Split File2 in to 5 files such as
Code:
F1 F2 F3 F4 F5
F2 RECORD 01 F2 RECORD 02 F2 RECORD 03 F2 RECORD 04 F2 RECORD 05
F2 RECORD 06 F2 RECORD 07 F2 RECORD 08 F2 RECORD 09 F2 RECORD 10
F2 RECORD 11 F2 RECORD 12 F2 RECORD 13 F2 RECORD 14 F2 RECORD 15
F2 RECORD 16 F2 RECORD 17 F2 RECORD 18 F2 RECORD 19 F2 RECORD 20
F2 RECORD 21 F2 RECORD 22 F2 RECORD 23 F2 RECORD 24 F2 RECORD 25
F2 RECORD 26 F2 RECORD 27 F2 RECORD 28 F2 RECORD 29 F2 RECORD 30
so on
Now i add SEQNUM in all files as follows
Increment file 1 by 10 .......... 10,20,30 .........
Increment file F1 by 30 .......... 31,61,91 ..........
Increment file F2 by 30 .......... 32,62,92 ..........
Increment file F3 by 30 .......... 33,63,93 ..........
Increment file F4 by 30 .......... 34,64,94 ..........
Increment file F5 by 30 .......... 35,65,95 ..........
Then merge all 6 files sorted on seqnum ......... it's done!!!!
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
This DFSORT/ICETOOL job is a beter alternative.
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD DSN=... input file1 (FB/80)
//IN2 DD DSN=... input file2 (FB/80)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(MOD,PASS)
//OUT DD DSN=... output file (FB/80)
//TOOLIN DD *
COPY FROM(IN1) TO(T1) USING(CTL1)
COPY FROM(IN2) TO(T1) USING(CTL2)
SORT FROM(T1) TO(OUT) USING(CTL3)
/*
//CTL1CNTL DD *
* Get seqnum as 0, 1, 2, 3, ...
* Divide by +3 to get 0, 0, 0, 1, ...
INREC OVERLAY=(81:SEQNUM,8,ZD,START=0,
81:81,8,ZD,DIV,+3,TO=ZD,LENGTH=8)
/*
//CTL2CNTL DD *
* Get seqnum as 0, 1, 2, 3, 4, 5, ...
* Divide by +5 to get 0, 0, 0, 0, 0, 1, ...
INREC OVERLAY=(81:SEQNUM,8,ZD,START=0,
81:81,8,ZD,DIV,+5,TO=ZD,LENGTH=8)
/*
//CTL3CNTL DD *
* Sort on divided number with EQUALS.
* The 3 0s from file1 will be followed by the
* 5 0s from file2. Then the 3 1s from file1 will
* be followed by the 5 1s from file2 and so on.
OPTION EQUALS
SORT FIELDS=(81,8,ZD,A)
OUTREC BUILD=(1,80)
/*
If you don't mind using two steps, you can do a MERGE instead of a SORT which would be more efficient:
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD DSN=... input file1 (FB/80)
//IN2 DD DSN=... input file2 (FB/80)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(MOD,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(MOD,PASS)
//TOOLIN DD *
COPY FROM(IN1) TO(T1) USING(CTL1)
COPY FROM(IN2) TO(T2) USING(CTL2)
/*
//CTL1CNTL DD *
* Get seqnum as 0, 1, 2, 3, ...
* Divide by +3 to get 0, 0, 0, 1, ...
INREC OVERLAY=(81:SEQNUM,8,ZD,START=0,
81:81,8,ZD,DIV,+3,TO=ZD,LENGTH=8)
/*
//CTL2CNTL DD *
* Get seqnum as 0, 1, 2, 3, 4, 5, ...
* Divide by +5 to get 0, 0, 0, 0, 0, 1, ...
INREC OVERLAY=(81:SEQNUM,8,ZD,START=0,
81:81,8,ZD,DIV,+5,TO=ZD,LENGTH=8)
/*
//S2 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN01 DD DSN=&&T1,DISP=(OLD,PASS)
//SORTIN02 DD DSN=&&T2,DISP=(OLD,PASS)
//SORTOUT DD DSN=... output file (FB/80)
//SYSIN DD *
* Merge on divided number with EQUALS.
* The 3 0s from file1 will be followed by the
* 5 0s from file2. Then the 3 1s from file1 will
* be followed by the 5 1s from file2 and so on.
OPTION EQUALS
MERGE FIELDS=(81,8,ZD,A)
OUTREC BUILD=(1,80)
/*
Gr888888, i guess this is most generic jcl and can be used for any sort of combination (x records from file1 and y records from file 2......)
I had thought of this seq. i.e. repeating the number 'n' number of times....but was not able to put it in the mathematical terms !!