Function order_update
This function validates that the values in the order_rec program
record are correct, and then executes an SQL statement to update the row in the
orders database table.
Function
order_update
(orders.4gl):01 FUNCTION order_update(d)
02 DEFINE d ui.Dialog
03
04 IF NOT order_validate(d) THEN RETURN FALSE END IF
05
06 WHENEVER ERROR CONTINUE
07 UPDATE orders SET
08 store_num = order_rec.store_num,
09 order_date = order_rec.order_date,
10 fac_code = order_rec.fac_code,
11 ship_instr = order_rec.ship_instr,
12 promo = order_rec.promo
13 WHERE orders.order_num = order_rec.order_num
14 WHENEVER ERROR STOP
15
16 IF SQLCA.SQLCODE <> 0 THEN
17 CALL __mbox_ok(title1,SQLERRMESSAGE,"stop")
18 RETURN FALSE
19 END IF
20
21 CALL d.setFieldTouched("orders.*", FALSE)
22 MESSAGE SFMT(msg17, order_rec.order_num)
23
24 RETURN TRUE
25
26 END FUNCTIONNote:
- Line
01Since you cannot use theDIALOGkeyword outside theDIALOGstatement, a dialog object is passed to this function in order to use the methods of theDIALOGclass. - Line
04calls theorder_validatefunction, passing the dialog object. If the fields in the dialog are not validated, the function returns without updating the database row. - Lines
06thru14execute the SQL statement to update a row in theordersdatabase table using values from theorder_recprogram record. - Lines
16thru18return an error and exits the function if theSQLCA.SQLCODEindicates the database update was not successful. - Lines
21resets thetouchedflags of the fields in theordersscreen record, after the database is successfully updated, to get back to the initial state of the dialog. - Line
22displays a message to the user indicating the database update was successful. - Line
24returnsTRUEto the calling function if the database update was successful.