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

Merge 2 files with header detail and trailer


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Lekshmi Jayapal

New User


Joined: 09 Jul 2009
Posts: 4
Location: Cochin

PostPosted: Thu Jul 09, 2009 8:47 pm
Reply with quote

Hi,

Could you please help with the below Sort criteria.
Merge two files into a single file with header,detail and trailer and update the trailer totals.

File1 : Header1,Detail1 ,Trailer1
File2 : Header2,Detail2 ,Trailer2

Output :

File3 : Header1,Detail1,Detail2,Trailer3
(Trailer3 : sum of the hash total fields of trailer 1+trailer 2)

Options we tried had 4 sort steps
Sort step 1 : Split header, trailer and details into 3 files.
Sort step 2 : To calculate the sum of hash totals in the trailer file splitted above
Sort step3 : Eliminate duplicate header record (Header2)
Sort step 4 : Merge detail file from step 1 + Trailer file from step2 + Header file from step3.

Can any one suggest a much easier solution to the above sort.

Thanks
Lekshmi
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Jul 09, 2009 8:52 pm
Reply with quote

Please show an example of the records in each input file (relevant fields only) and what you expect for output. Give the RECFM and LRECL of each input file. Give the starting position, length and format of each relevant field.

Is there something in the header that identifies it (what)?

Is there something in the trailer that identifies it (what)?
Back to top
View user's profile Send private message
Lekshmi Jayapal

New User


Joined: 09 Jul 2009
Posts: 4
Location: Cochin

PostPosted: Thu Jul 09, 2009 9:11 pm
Reply with quote

Hi Frank,

Thanks for your immediate reply.

Both the files are of same format FB and same length 460

Layout of the files
----------------------

Header : 'HH' from position 1 to 2 indicates header
HH000000000000000000000000000000000AAAABBB

Details : 'DD' from position 1 to 2 indicates detail
DD 000000000000000 100000000000000000A 00000000AA A AAAA
DD 000000000000000 3000000000000000000000000000000000000
DD 000000001000000 100000000000000000A 00000000AA A AAAA
DD 000000001000000 3000000000000000000000000000000000000
DD 001110000000000 100000000000000000A 00000000AA A AAAA
DD 001110000000000 3000000000000000000000000000000000000

Trailer : 'TT' from position 1 to 2 indicates trailer
TT00000000AAAAAAAAAA000806947000088393

Hashtotal filed 1 in trailer : from 21 length of the field 9
Hashtotal filed 2 in trailer : from 30 length of the field 9
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Jul 09, 2009 9:27 pm
Reply with quote

The layout information is helpful, but I was also looking for an example of the records in each file and the expected output. It's not clear if you want the records of the second file appended after the records of the first file, or if you want the two files merged by a key or sorted by a key or what. I was hoping the example would make that clear.

Also, is the hashtotal for field1 the total of the amounts in positions 21-29 of the data records from both files or something else? Again, I was hoping the example would make that clear.
Back to top
View user's profile Send private message
Lekshmi Jayapal

New User


Joined: 09 Jul 2009
Posts: 4
Location: Cochin

PostPosted: Thu Jul 09, 2009 10:57 pm
Reply with quote

Hi Frank,

Please refer the example shown below.

Input1 : File 1

HH000000000000000000000000000000000AAAA
DD0012345678000000000000000000000000000
DD0078787550000000000000000000000000000
DD0187667750999999999999999999999999999
DD0156474680777777777777777777777777777
TT00000000AAAAAAAAAA000000002000000004

Input2 : File2

HH000000000000000000000000000000000BBBB
DD0012345678000000000000000000000000000
DD0078787550000000000000000000000000000
DD0187667750999999999999999999999999999
DD0156474680777777777777777777777777777
TT00000000AAAAAAAAAA000000002000000004

Output : File3

HH000000000000000000000000000000000AAAA
DD0012345678000000000000000000000000000
DD0078787550000000000000000000000000000
DD0012345678000000000000000000000000000
DD0078787550000000000000000000000000000
DD0187667750999999999999999999999999999
DD0156474680777777777777777777777777777
DD0187667750999999999999999999999999999
DD0156474680777777777777777777777777777
TT00000000AAAAAAAAAA000000002000000008

Hashtotal field1 in each of the file is the count of distinct records with respect to position 3 to 4 in the Detail record.

Hashtotal field2 in each of the file is the total count of detail records in the file.

In the output file there should be only one header and one trailer and all the detail records from both the input files as shown in the above eg:.Also the hash total in the trailer record of the output file would be the sum of the corresponding hash totals in the trailers in the input file.

Please get back in case of more clarifications.

Thanks
Lekshmi
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Jul 09, 2009 11:35 pm
Reply with quote

Getting closer.

Quote:
Also the hash total in the trailer record of the output file would
be the sum of the corresponding hash totals in the trailers in the
input file.


I don't think so. For hash total 1, your example shows 2 for file1 and 2 for file2 so the sum would be 4, but you show 2 in the output. I think what you really want for hash total 1 is the count of distinct records for the merged D records - that would be 2 (just 00 and 01 in 3-4). Is that correct?

Can the Trailer be rebuilt as:

TT00000000AAAAAAAAAAnnnnnnnnnmmmmmmmmm

where TT00000000AAAAAAAAAA can be hardcoded and the two hash totals filled in from the appropriate counts?

Or must information from the input Trailer be kept in the output trailer (e.g. AAAAAAAAAA can change)?
Back to top
View user's profile Send private message
Lekshmi Jayapal

New User


Joined: 09 Jul 2009
Posts: 4
Location: Cochin

PostPosted: Fri Jul 10, 2009 9:25 am
Reply with quote

Hi Frank ,

That was a mistake I used the same file as File 1 and File2.In file 1 and File2 details records will never be the same.Especially the value from posititon 3 -4 between the 2 files will never be the same.So we can consider the 'D00' and 'D01' in file 2 as D'03' and 'D04' so the hashtotal-1 in the trailer filed is 4 and Hashtotal-2 in the trailer field will remian as '8'.


TT00000000AAAAAAAAAA cannot be hard coded as we have to retain the
value coming in the File1 in the output file trailer.
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Fri Jul 10, 2009 7:52 pm
Reply with quote

Lekshmi Jayapal,

The following DFSORT JCL will give you the desired results


Code:

//STEP0100 EXEC PGM=SORT   
//SYSOUT   DD SYSOUT=*     
//SORTIN   DD DSN=Your 460 byte file1,DISP=SHR
//         DD DSN=Your 460 byte file2,DISP=SHR
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                     
  SORT FIELDS=COPY                                                 
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'HH'),PUSH=(461:ID=1)),
  IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'TT',AND,461,1,ZD,EQ,1),     
  PUSH=(462:21,18))                                                 
                                                                   
  OUTREC IFTHEN=(WHEN=(1,2,CH,EQ,C'TT'),                           
  OVERLAY=(21:21,9,ZD,ADD,462,9,ZD,ZD,LENGTH=9,                     
           30:30,9,ZD,ADD,471,9,ZD,ZD,LENGTH=9))                   
                                                                   
  OUTFIL BUILD=(1,460),                                             
  OMIT=((1,2,CH,EQ,C'HH',AND,461,1,ZD,EQ,2),OR,                     
        (1,2,CH,EQ,C'TT',AND,461,1,ZD,EQ,1))                       
/*
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
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
Search our Forums:

Back to Top