7.82.2 ROLLBACK Examples
Requesting the user to input details of an order. Write the order header and all associated lines to the database. Ask the user to confirm that the order should be kept. If the reply is not YES, remove the order from the database.
GROUP_BY NAME(#ORDERHEAD) FIELDS(#ORDNUM #CUSTNUM #DATEDUE)
DEF_LIST NAME(#ORDERLINE) FIELDS(#ORDLIN #PRODUCT #QUANTITY #PRICE)
DEFINE FIELD(#CONFIRM) TYPE(*CHAR) LENGTH(3) LABEL('Confirm order :')
SET_MODE TO(*ADD)
INZ_LIST NAMED(#ORDERLINE) NUM_ENTRYS(20)
REQUEST FIELDS(#ORDERHEAD) BROWSELIST(#ORDERLINE)
INSERT FIELDS(#ORDERHEAD) TO_FILE(ORDHDR)
SELECTLIST NAMED(#ORDERLINE) GET_ENTRYS(*NOTNULL)
INSERT FIELDS(#ORDERLINE) TO_FILE(ORDLIN)
ENDSELECT
REQUEST FIELDS((#CONFIRM)(#ORDNUM *NOCHG))
IF COND('#CONFIRM = YES')
COMMIT
MESSAGE MSGTXT('Order has been commited to the database')
ELSE
ROLLBACK
MESSAGE MSGTXT('Order has been removed from the database')
ENDIF
If the function were to fail when writing the 4th order line (say), then an automatic rollback would be issued. This would cause the order header and any order lines already created to be rolled back from the file.