Every one of us familiar with the CPYF command. We use MBROPT as *REPLACE to replace the records of the To file with the From file records. We use MBROPT as *ADD to add the records of the From File to the To File.
There is one less used option called *UPDADD. This option updates the duplicate records in the To file and adds the news records from the From file to the To file.
Example, consider a file ORDDTL of sales order details. Each line represents an item on the order and is uniquely keyed on order number and line number.
Order Line Item
Number Number Number Quantity
====== ====== ====== ========
1 1 I01 5
1 2 I08 3
2 1 I01 6
2 2 I09 6
3 1 I01 3
3 2 I07 3
3 3 I09 6
3 4 I02 6
4 1 I02 5
4 2 I08 5
4 3 I22 6
6 1 I01 8
Assume a second file ORDDTLCHGS of the same format with additional order lines and/or changes to existing order lines.
Order Line Item
Number Number Number Quantity
====== ====== ====== ========
5 1 I18 4
6 1 I01 12
7 1 I05 6
Notice that two lines, for orders 5 and 7, do not exist in the ORDDTL file. The record for order 6, line 1, contains a new quantity for that order line.
To apply the updates to ORDDTL, use the *UPDADD option, like this:
CPYF FROMFILE(ORDDTLCHGS) TOFILE(ORDDTL) MBROPT(*UPDADD)
Here's the resulting dataset.
Order Line Item
Number Number Number Quantity
====== ====== ====== ========
1 1 I01 5
1 2 I08 3
2 1 I01 6
2 2 I09 6
3 1 I01 3
3 2 I07 3
3 3 I09 6
3 4 I02 6
4 1 I02 5
4 2 I08 5
4 3 I22 6
6 1 I01 12
5 1 I18 4
7 1 I05 6
Notice that the quantity has changed for order 6, line 1, and the lines for orders 5 and 1 have been added.
Monday, September 10, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment