Page 1 of 1

Copy the part of header to detail records using SORT.

Posted: Sat Feb 11, 2017 10:26 am
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.

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

Posted: Sat Feb 11, 2017 4:30 pm
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.

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

Posted: Mon Feb 13, 2017 3:13 pm
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.

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

Posted: Tue Feb 14, 2017 8:33 pm
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.

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

Posted: Wed Feb 15, 2017 1:43 pm
by Bala Kumar
Thanks.

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

Posted: Wed Feb 15, 2017 3:49 pm
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.