IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Appending 2 files to one


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
l.nethaji

New User


Joined: 16 Mar 2008
Posts: 90
Location: tamil nadu

PostPosted: Mon Feb 10, 2014 9:28 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Feb 10, 2014 10:50 pm
Reply with quote

Hello,

Is there only one set of records to process? Or is it likely there will be multiple "sets" of records?
Back to top
View user's profile Send private message
l.nethaji

New User


Joined: 16 Mar 2008
Posts: 90
Location: tamil nadu

PostPosted: Tue Feb 11, 2014 9:31 am
Reply with quote

Hi dick,

We have only one set of records in the file1 (header detail and trailer) and file 2 (detail)
Back to top
View user's profile Send private message
l.nethaji

New User


Joined: 16 Mar 2008
Posts: 90
Location: tamil nadu

PostPosted: Tue Feb 11, 2014 10:46 pm
Reply with quote

Dick ,

please share me if you have any idea how to go with this .

Regards,
L.Nethaji
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue Feb 11, 2014 11:12 pm
Reply with quote

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
View user's profile Send private message
l.nethaji

New User


Joined: 16 Mar 2008
Posts: 90
Location: tamil nadu

PostPosted: Wed Feb 12, 2014 12:12 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Feb 12, 2014 12:26 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Feb 12, 2014 2:35 am
Reply with quote

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
View user's profile Send private message
Santoshkumar Sala

New User


Joined: 18 Jul 2010
Posts: 12
Location: Mumbai

PostPosted: Wed Feb 12, 2014 3:02 am
Reply with quote

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
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Feb 12, 2014 4:49 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Feb 12, 2014 5:13 am
Reply with quote

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
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Wed Feb 12, 2014 7:59 am
Reply with quote

Thanks Kolusu, Each day a new lesson.
Perspective towards the issue make difference... icon_biggrin.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts How to append a PS file into multiple... JCL & VSAM 3
Search our Forums:

Back to Top