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

Move field from Header to Detail records in each group


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

New User


Joined: 09 Jun 2006
Posts: 14

PostPosted: Thu Sep 12, 2013 3:48 pm
Reply with quote

I have input file with records in below structure -
HDR <ACCT. NO.1>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TRL <count>
HDR <ACCT. NO.2>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TRL <count>
HDR <ACCT. NO.3>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TTT <TXN Details>
TRL <count>

I want above records to be transformed into

TTT <ACCT.No.1> <TXN Details>
TTT <ACCT.No.1> <TXN Details>
TTT <ACCT.No.1> <TXN Details>
TTT <ACCT.No.2> <TXN Details>
TTT <ACCT.No.2> <TXN Details>
TTT <ACCT.No.2> <TXN Details>
TTT <ACCT.No.2> <TXN Details>
..
..
TTT <ACCT.No.3> <TXN Details>
TTT <ACCT.No.3> <TXN Details>

Can anyone suggest me the way to go forward with sample code?
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: Thu Sep 12, 2013 5:01 pm
Reply with quote

Use OMIT to get rid of TRL

Use IFTHEN=(WHEN=GROUP to identify the HDR and PUSH the values from the HDR to each detail record.

Use OUTFIL OMIT to get rid of the by now redundant header, and BUILD to create your desired output.
Back to top
View user's profile Send private message
thisak

New User


Joined: 09 Jun 2006
Posts: 14

PostPosted: Fri Sep 13, 2013 9:29 am
Reply with quote

By your reply, I can understand that my case can achievable.
But I want to know what each of those keywords does?
If any sample code is there, then this would be great.

Thank you very much.
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Fri Sep 13, 2013 10:22 am
Reply with quote

This is what Bill has suggested. Bill..Please correct me if I'm wrong.

Try the below code. You can modify it as per your exact data length and offsets.

Code:
//STEP01   EXEC PGM=SORT                                           
//SORTIN   DD *                                                   
HDR <ACCT. NO.1>                                                   
TTT <TXN DETAILS>                                                 
TTT <TXN DETAILS>                                                 
TTT <TXN DETAILS>                                                 
TRL <COUNT>                                                       
HDR <ACCT. NO.2>                                                   
TTT <TXN DETAILS>                                                 
TTT <TXN DETAILS>                                                 
TTT <TXN DETAILS>                                                 
TTT <TXN DETAILS>                                                 
TRL <COUNT>                                                       
//SORTOUT  DD SYSOUT=*                                             
//SYSOUT   DD SYSOUT=*                                             
//SYSIN    DD *                                                   
 OPTION COPY                                                       
 INREC  IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'HDR'),PUSH=(81:5,12))
 OUTFIL INCLUDE=(1,3,CH,EQ,C'TTT'),BUILD=(1,4,5:81,12,17:4,14)     
/*                                                                 

Output:
Code:
TTT <ACCT. NO.1> <TXN DETAILS>
TTT <ACCT. NO.1> <TXN DETAILS>
TTT <ACCT. NO.1> <TXN DETAILS>
TTT <ACCT. NO.2> <TXN DETAILS>
TTT <ACCT. NO.2> <TXN DETAILS>
TTT <ACCT. NO.2> <TXN DETAILS>
TTT <ACCT. NO.2> <TXN DETAILS>
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: Fri Sep 13, 2013 11:40 am
Reply with quote

I would add the OMIT COND= for the "TRL" and the OUTFIL OMIT= for the "HDR".

If there is data you don't want, it is always good to OMIT COND= (or INCLUDE the data that you do want) so that fewer records are processed - plus, it is clearer what is being processed.

With OMIT= for the header on the OUTFIL, it is then easier to understand the whole process:

We don't want trailers, at all, they are nothing to us. First line of code.
We process informaiton from the headers onto thte data.
Now we don't want the headers.

thisak.

Note that you should read the 81:as "a temporary data position at the end of my record". If your records area variable, then it needs to be at the start of the record.
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Fri Sep 13, 2013 12:28 pm
Reply with quote

Thanks Bill.

Thisak,
First try to understand what this code is doing and then modify it as per your requirements.

Code:
//SYSIN    DD *                                                   
 OPTION COPY                                                       
 OMIT   COND=(1,3,CH,EQ,C'TRL')                                   
 INREC  IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'HDR'),PUSH=(81:5,12))
 OUTFIL OMIT=(1,3,CH,EQ,C'HDR'),BUILD=(1,4,5:81,12,17:4,14)       
/*                                                                 
Back to top
View user's profile Send private message
thisak

New User


Joined: 09 Jun 2006
Posts: 14

PostPosted: Tue Sep 17, 2013 2:05 pm
Reply with quote

Thank you very much - Bill & Mistah

Mistah, Thanks again for explaining that with code.
I'll try this and surely reply with the outcome.

Thanks,
Thisak
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 only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join multiple records using splice DFSORT/ICETOOL 5
No new posts EZT program to build a flat file with... All Other Mainframe Topics 9
Search our Forums:

Back to Top