Saturday, March 1, 2014

OUTREC BUILD and OUTREC OVERLAY in SORT

We sometimes tend to get confused between the BUILD and OVERLAY of OUTREC statement.
Lets see  how each works and figure out when to use BUILD and OUTREC in SORT.
Scenario 1.
Input file is same as we used before
---+----1----+----2----+----3----+
************************  
HARLEY   123456MEXICO   
DAVID    658999CANADA    
*********************** 
We want to add date to the records from 35th position using BUILD.Sort syntax to do it with use of OUTREC BUILD would be:
SORT FIELDS=COPY                         
OUTREC BUILD=(1:1,32,35:&DATE)    
Output:
----+----1----+----2----+----3----+-          
*********************************
HARLEY   123456MEXICO   03/02/14
DAVID    658999CANADA   03/02/14 
********************************  
However,we can get the same output by use of OVERLAY in OUTREC as well like below:
SORT FIELDS=COPY                   
OUTREC OVERLAY=(35:&DATE)
Thus we can see, while using BUILD, we had to build the output records specifying the starting position,and records needed in output by using the syntax '1:1,32' and then specify '35:&date' which puts the date into 35th position.

However, OVERLAY reduced the coding effort.We specified only where the change needs to be done, keeping the entire record structure same.This becomes very handy when handling large and complex sort conditions since it eliminates the need to build the output record by record.

No comments:

Post a Comment