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 FUNCTION
Note:
- Line
01
Since you cannot use theDIALOG
keyword outside theDIALOG
statement, a dialog object is passed to this function in order to use the methods of theDIALOG
class. - Line
04
calls theorder_validate
function, passing the dialog object. If the fields in the dialog are not validated, the function returns without updating the database row. - Lines
06
thru14
execute the SQL statement to update a row in theorders
database table using values from theorder_rec
program record. - Lines
16
thru18
return an error and exits the function if theSQLCA.SQLCODE
indicates the database update was not successful. - Lines
21
resets thetouched
flags of the fields in theorders
screen record, after the database is successfully updated, to get back to the initial state of the dialog. - Line
22
displays a message to the user indicating the database update was successful. - Line
24
returnsTRUE
to the calling function if the database update was successful.