Function order_insert

This function inserts a new record in the orders database table.

Function order_insert (orders.4gl):
01 FUNCTION order_insert()
02 
03   WHENEVER ERROR CONTINUE
04   INSERT INTO orders (
05      store_num,
06      order_num,
07      order_date,
08      fac_code,
09      ship_instr,
10      promo 
11    ) VALUES (
12      order_rec.store_num,
13      order_rec.order_num,
14      order_rec.order_date,
15      order_rec.fac_code,
16      order_rec.ship_instr,
17      order_rec.promo 
18    )
19    WHENEVER ERROR STOP
20   
21    IF (SQLCA.SQLCODE <> 0) THEN
22      CLEAR FORM
23      ERROR SQLERRMESSAGE
24      RETURN FALSE
25    END IF
27 
28    MESSAGE "Order added"
29    RETURN TRUE
30 
31 END FUNCTION
Note:
  • Lines 03 thru 19 implement the INSERT SQL statement to create a new row in the orders table.
  • Lines 21 thru 25 handle potential SQL errors, and display a message and return FALSE if the insert was not successful.
  • Lines 28 and 29 display a message and return TRUE in case of success.