7.9.3 CHANGE Examples
Example 1: Increment field #COUNT.
CHANGE FIELD(#COUNT) TO('#COUNT + 1')
Example 2: Add field #QUANTITY to field #COUNT.
CHANGE FIELD(#COUNT) TO('#COUNT + #QUANTITY')
Example 3: Change all fields in group #ORDERLINE to their null values. A "null" value is blanks for an alphanumeric field and zero for a numeric field.
GROUP_BY NAME(#ORDERLINE) FIELDS(#ORDLIN #PRODUCT #QUANTITY #PRICE)
CHANGE FIELD(#ORDERLINE) TO(*NULL)
which is identical to:
CHANGE FIELD(#ORDLIN) TO(*NULL)
CHANGE FIELD(#PRODUCT) TO(*NULL)
CHANGE FIELD(#QUANTITY) TO(*NULL)
CHANGE FIELD(#PRICE) TO(*NULL)
which is identical to:
CHANGE FIELD(#ORDLIN) TO(*ZERO)
CHANGE FIELD(#PRODUCT) TO(*BLANKS)
CHANGE FIELD(#QUANTITY) TO(*ZERO)
CHANGE FIELD(#PRICE) TO(*ZERO)
which is identical to:
CHANGE FIELD(#ORDLIN) TO(0)
CHANGE FIELD(#PRODUCT) TO(''' ''')
CHANGE FIELD(#QUANTITY) TO(0)
CHANGE FIELD(#PRICE) TO(0)
Example 4: Change all fields in group #ORDERLINE to their data dictionary defined default values.
GROUP_BY NAME(#ORDERLINE) FIELDS(#ORDLIN #PRODUCT #QUANTITY #PRICE)
CHANGE FIELD(#ORDERLINE) TO(*DEFAULT)
which is identical to:
CHANGE FIELD(#ORDLIN) TO(*DEFAULT)
CHANGE FIELD(#PRODUCT) TO(*DEFAULT)
CHANGE FIELD(#QUANTITY) TO(*DEFAULT)
CHANGE FIELD(#PRICE) TO(*DEFAULT)
Example 5: Change fields #A, #B and #C so that they all contain the product of #QUANTITY and #PRICE.
CHANGE FIELD(#A #B #C) TO('#QUANTITY * #PRICE')
which is identical to:
CHANGE FIELD(#A) TO('#QUANTITY * #PRICE')
CHANGE FIELD(#B) TO('#QUANTITY * #PRICE')
CHANGE FIELD(#C) TO('#QUANTITY * #PRICE')
Example 6: Change fields #A, #B and #C so that they all contain the value 1.
CHANGE FIELD(#A #B #C) TO(1)
which is identical to:
CHANGE FIELD(#A) TO(1)
CHANGE FIELD(#B) TO(1)
CHANGE FIELD(#C) TO(1)
Example 7: Change fields #A and #B so that they contain the product of '#A + 1'.
CHANGE FIELD(#A #B) TO('#A + 1')
which is identical to:
CHANGE FIELD(#A) TO('#A + 1')
CHANGE FIELD(#B) TO('#A + 1')
Note that this shows that the resulting values of #A and #B are not the same. The value of #B in this case is 1 more than #A.
This is not necessarily wrong, but it may not be the expected resulted. If you wanted both #A and #B to have the same value (#A + 1), then one of the following methods should be used.
CHANGE FIELD(#B #A) TO('#A + 1')
which is identical to:
CHANGE FIELD(#B) TO('#A + 1')
CHANGE FIELD(#A) TO('#A + 1')
or
CHANGE FIELD(#A) TO('#A + 1')
CHANGE FIELD(#B) TO(#A)