7.125.3 UPDATE Examples

Example 1: Ask the user to input an order number and customer number from the workstation and update the associated order header record:

REQUEST  FIELDS(#ORDNUM #CUSTNO)

UPDATE   FIELDS(#ORDNUM #CUSTNO) IN_FILE(ORDHDR) WITH_KEY(#ORDNUM)

Example 2: Ask the user to input an existing order number and a new order number at the workstation. Update the existing order header and all associated order lines to have the new order number:

DEFINE  FIELD(#OLDORDNUM) REFFLD(#ORDNUM) LABEL('Existing order')

DEFINE  FIELD(#NEWORDNUM) REFFLD(#ORDNUM) LABEL('New order')

REQUEST FIELDS(#OLDORDNUM #NEWORDNUM)

CHANGE  FIELD(#ORDNUM) TO(#NEWORDNUM)

UPDATE  FIELDS(#ORDNUM) IN_FILE(ORDHDR) WITH_KEY(#OLDORDNUM)

UPDATE  FIELDS(#ORDNUM) IN_FILE(ORDLIN) WITH_KEY(#OLDORDNUM)

Example 3: Change the price (#PRICE) of all records in a nominated product category (#CAT) to $100.00:

CHANGE  FIELD(#PRICE) TO(100.00)

UPDATE  FIELDS(#PRICE) IN_FILE(PROMSTV1) WITH_KEY(#CAT)

Example 4: Increase the price (#PRICE) of all records in a nominated product category (#CAT) by $100.00:

SELECT  FIELDS(#PRICE) FROM_FILE(PROMSTV1) WITH_KEY(#CAT)

CHANGE  FIELD(#PRICE) TO('#PRICE + 100.00')

UPDATE  FIELDS(#PRICE) IN_FILE(PROMSTV1)

ENDSELECT

Example 5: Reset all cost related fields in a nominated product category (#CAT):

GROUP_BY   NAME(#XG_COST) FIELDS(#COST1 #COST2 #COST3 #COST4)

CHANGE     FIELD(#XG_COST) TO(*DEFAULT)

UPDATE     FIELDS(#XG_COST) IN_FILE(PROMSTV1) WITH_KEY(#CAT)