Copy the part of header to detail records using SORT.

IBM's Sort Product, ICETOOL, ICEMAN and ICEGENER.
Post Reply
Bala Kumar
Registered Member
Posts: 16
Joined: Sun Oct 20, 2013 2:04 pm

Copy the part of header to detail records using SORT.

Post by Bala Kumar »

Hi everyone,

I need help for the foloing problem. Please have a look at the inpt file and the expected output:

Input file:

Code: Select all

0000000007889HEADER100000 
0100000002017DETEST100000 
0100000002017DETEST200000 
9900000007889TRAILER10000 
0000000001540HEADER200000 
0100000002017DYTEST100000 
0100000002017DYTEST200000 
9900000007889TRAILER20000 
Output File:

Code: Select all

0000000007889HEADER100000 078890001 
0100000002017DETEST100000 078890002 
0100000002017DETEST200000 078890003 
9900000007889TRAILER10000 078890004 
0000000001540HEADER200000 015400001 
0100000002017DYTEST100000 015400002 
0100000002017DYTEST200000 015400003 
9900000007889TRAILER20000 015400004 
In the records above, header will have “00” and trailer will always have “99” in start. What I need is to copy the number that is only in header to all records unit we reach the correspondng trailer.

Can you please help me on this.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Copy the part of header to detail records using SORT.

Post by William Collins »

You use IFTHEN=(WHEN=GROUP with BEGIN to identify the header and PUSH to copy the value from the header. The other data looks like a sequence number, WHEN=INIT with OVERLAY to create that.
Bala Kumar
Registered Member
Posts: 16
Joined: Sun Oct 20, 2013 2:04 pm

Re: Copy the part of header to detail records using SORT.

Post by Bala Kumar »

Thanks. When we use WHEN=INIT, does it mean to go to the initial record in the file or in the "GROUP"? Please advise me on this.
User avatar
Anuj Dhawan
Founder
Posts: 2799
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: Copy the part of header to detail records using SORT.

Post by Anuj Dhawan »

WHEN=GROUP clause(s) is (are) used to propagate fields, identifiers and sequence numbers within groups of records. And you define the records that belong to a group using an appropriate combination of BEGIN=(logexp), END=(logexp), KEYBEGIN=(field) and RECORDS=n parameters. WHEN=INIT clauses and WHEN=GROUP clauses are processed before any of the other IFTHEN clauses.

Hope that helps.
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Bala Kumar
Registered Member
Posts: 16
Joined: Sun Oct 20, 2013 2:04 pm

Re: Copy the part of header to detail records using SORT.

Post by Bala Kumar »

Thanks.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Copy the part of header to detail records using SORT.

Post by William Collins »

WHEN=INIT operates on each current record unconditionally.

WHEN=GROUP and WHEN=INIT can be intermixed, and there can be more than one of each.

The first record of a group is the record which defines the group, which meets the conditions for recognising the start of a group.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DFSort, ICETOOL, ICEMAN, ICEGENER.”