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 the DIALOG keyword outside the DIALOG statement, a dialog object is passed to this function in order to use the methods of the DIALOG class.
  • Line 04 calls the order_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 thru 14 execute the SQL statement to update a row in the orders database table using values from the order_rec program record.
  • Lines 16 thru18 return an error and exits the function if the SQLCA.SQLCODE indicates the database update was not successful.
  • Lines 21 resets the touched flags of the fields in the orders 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 returns TRUE to the calling function if the database update was successful.