|
View previous topic :: View next topic
|
| Author |
Message |
l.nethaji
New User
Joined: 16 Mar 2008 Posts: 90 Location: tamil nadu
|
|
|
|
I have 2 files. First one has a header followed by a detail and trailer records.
Second file is has only detail records.
They both have the same layout for detail record LRECL 20100.
SAmple File 1
HH00100100100000
DD99939439494943
TT899000999999999
SAmple File 2
DD99999999999999
O/p file 3:-
HH00100100100000
DD99939439494943
DD99999999999999
TT899000999999999
In my job, I need to write the header records from File 1 followed with the detail records of file 1 and then with Detail records of file 2 at the end need to add the trailer records from File 1 .
Please help how we can implement it using WHEN=GROUP or suggest any options to sort this out. Although we send the trailer records having the wrong counts since we haven't included the new detail records count that not a issue for the receipient team. |
|
| Back to top |
|
 |
dick scherrer
Moderator Emeritus

Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Is there only one set of records to process? Or is it likely there will be multiple "sets" of records? |
|
| Back to top |
|
 |
l.nethaji
New User
Joined: 16 Mar 2008 Posts: 90 Location: tamil nadu
|
|
|
|
Hi dick,
We have only one set of records in the file1 (header detail and trailer) and file 2 (detail) |
|
| Back to top |
|
 |
l.nethaji
New User
Joined: 16 Mar 2008 Posts: 90 Location: tamil nadu
|
|
|
|
Dick ,
please share me if you have any idea how to go with this .
Regards,
L.Nethaji |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
If your trailer can be generated then it you can get away with a COPY operation like below
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN=Input file 1 with header/detail/trailer records
// DD DISP=SHR,DSN=Input file 2 with just detail records
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OMIT COND=(1,2,CH,EQ,C'TT')
OUTFIL REMOVECC,
TRAILER1=(C'TT',COUNT-1=(M11,LENGTH=6))
//* |
If you need the original trailer record as is then use the following control cards. I assumed that you need to update the detail record count in position 3 on the trailer record.
| Code: |
//SYSIN DD *
SORT FIELDS=(1,2,AQ,A),EQUALS
ALTSEQ CODE=(C8C3)
OUTFIL IFTRAIL=(HD=YES,TRLID=(1,2,CH,EQ,C'TT'),
TRLUPD=(03:COUNT=(M11,LENGTH=6)))
//* |
|
|
| Back to top |
|
 |
l.nethaji
New User
Joined: 16 Mar 2008 Posts: 90 Location: tamil nadu
|
|
|
|
Hi ,
Thanks a lot for your help
May be i will omit the trailer file and write it to another file and merge the header 1 detail detail 2 along with trailer 1 in another step
If your trailer can be generated then it you can get away with a COPY operation like below
Code:
If you need the original trailer record as is then use the following control cards. I assumed that you need to update the detail record count in position 3 on the trailer record.
But i am not able to understand the below code.
IS this for generating a new trailer ...
Code:
//SYSIN DD *
SORT FIELDS=(1,2,AQ,A),EQUALS
ALTSEQ CODE=(C8C3)
OUTFIL IFTRAIL=(HD=YES,TRLID=(1,2,CH,EQ,C'TT'),
TRLUPD=(03:COUNT=(M11,LENGTH=6)))
//*
In my scenario i need to add an existing trailer from file 1 in the o/p file after header from file 1 + detail from file 1+ detail from file 2 . |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
It is using your original trailer, and updating it to reflect the correct number of detail records.
If you still just want the original trailer, remove the OUTFIL entirely. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Another option, using JOINKEYS to "merge" the data. On the first file, all records get extended (I've used F, 80 , records for the example) with X'00' except for the trailer which gets X'FF'. All records on the second file get X'FE', Then JOINKEYS is used , with only unmatched records, and the output is stitched together.
If you want the trailer, you can include Kolusu's OUTFIL code alongside.
| Code: |
//INTLEVE EXEC PGM=SORT
//CHKOUT DD DUMMY
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS F1=INA,FIELDS=(81,1,A),SORTED,NOSEQCK
JOINKEYS F2=INB,FIELDS=(81,1,A),SORTED,NOSEQCK
JOIN UNPAIRED,F1,F2,ONLY
REFORMAT FIELDS=(F1:1,80,F2:1,80,?)
OUTFIL IFTHEN=(WHEN=(161,1,CH,EQ,C'1'),
BUILD=(1,80)),
IFTHEN=(WHEN=NONE,
BUILD=(81,80))
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(81:X'00')),
IFTHEN=(WHEN=(1,2,CH,EQ,C'TT'),
OVERLAY=(81:X'FF'))
//JNF2CNTL DD *
INREC OVERLAY=(81:X'FE')
//INA DD *
HH00100100100000
DD99939439494943
TT89900099999999
//INB DD *
DD00000000000000
DD99999999999999 |
|
|
| Back to top |
|
 |
Santoshkumar Sala
New User
.jpg)
Joined: 18 Jul 2010 Posts: 12 Location: Mumbai
|
|
|
|
Hi Netaji,
If you can modify the HEADER --> from HH to 00
DETAIL --> From DD to 01
TrAILER --> From TT to 99
You can simple merge both the files and SORT these 2 bytes in Ascending order ... so the final output will in below order.
00 -- Header
01 -- details -- File 01
01 -- details -- File 02
99 -- Trailer |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| Bill Woodger wrote: |
| Another option, using JOINKEYS to "merge" the data. On the first file, all records get extended (I've used F, 80 , records for the example) |
Cannot use Joinkeys to merge as 20100 + 20100 will fall outside the allowable LRECL range.
| l.nethaji wrote: |
| They both have the same layout for detail record LRECL 20100 |
.
| Santoshkumar Sala wrote: |
If you can modify the HEADER --> from HH to 00
DETAIL --> From DD to 01
TrAILER --> From TT to 99
You can simple merge both the files and SORT these 2 bytes in Ascending order ... so the final output will in below order. |
You don't really need to modify the contents to 00,01 and 99 as you can use ALTSEQ code to merge the records.
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN01 DD DISP=SHR,DSN=Input file 1 with header/detail/trailer records
//SORTIN02 DD DISP=SHR,DSN=Input file 2 with just detail records
//SORTOUT DD SYSOUT=*
//SYSIN DD *
MERGE FIELDS=(1,2,AQ,A),EQUALS
ALTSEQ CODE=(C8C3)
//* |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Thanks Kolusu.Couldn't work out why you were SORTing :-) I missed the LRECL...
However, if the trailer is not huge as well....
l.nethaji,
How big is your trailer? How often do you need to do this? How may records on each file? |
|
| Back to top |
|
 |
sureshpathi10
Active User

Joined: 03 May 2010 Posts: 158 Location: Kuala Lumpur
|
|
|
|
Thanks Kolusu, Each day a new lesson.
Perspective towards the issue make difference...  |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|