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----+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:
************************
HARLEY 123456MEXICO
DAVID 658999CANADA
***********************
SORT FIELDS=COPYOutput:
OUTREC BUILD=(1:1,32,35:&DATE)
----+----1----+----2----+----3----+-However,we can get the same output by use of OVERLAY in OUTREC as well like below:
*********************************
HARLEY 123456MEXICO 03/02/14
DAVID 658999CANADA 03/02/14
********************************
SORT FIELDS=COPYThus 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.
OUTREC OVERLAY=(35:&DATE)
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