Copy the part of header to detail records using SORT.

IBM's Sort Product, ICETOOL, ICEMAN and ICEGENER.
Previous topicNext topic

Topic Author
Bala Kumar
Registered Member
Posts: 10
Joined: Sun Oct 20, 2013 2:04 pm

Copy the part of header to detail records using SORT.

Post by Bala Kumar » Sat Feb 11, 2017 10:26 am

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: 499
Joined: Sun Aug 25, 2013 7:24 pm

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

Post by William Collins » Sat Feb 11, 2017 4:30 pm

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.




Topic Author
Bala Kumar
Registered Member
Posts: 10
Joined: Sun Oct 20, 2013 2:04 pm

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

Post by Bala Kumar » Mon Feb 13, 2017 3:13 pm

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: 2624
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Zodiac: Sagittarius

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

Post by Anuj Dhawan » Tue Feb 14, 2017 8:33 pm

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.


Topic Author
Bala Kumar
Registered Member
Posts: 10
Joined: Sun Oct 20, 2013 2:04 pm

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

Post by Bala Kumar » Wed Feb 15, 2017 1:43 pm

Thanks.




William Collins
Global Moderator
Global Moderator
Posts: 499
Joined: Sun Aug 25, 2013 7:24 pm

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

Post by William Collins » Wed Feb 15, 2017 3:49 pm

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.



Previous topicNext topic

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