Example: Deleting a Row

Function delete_check is added to the custquery.4gl module to check whether a store has any orders in the database before allowing the user to delete the store from the customer table. If there are no existing orders, a dialog MENU is used to prompt the user for confirmation.

Function delete_check (custquery.4gl)
01 FUNCTION delete_check()
02   DEFINE del_ok SMALLINT,
03          ord_count SMALLINT
04
05   LET del_ok = FALSE
06
07   SELECT COUNT(*) INTO ord_count 
08     FROM orders 
09     WHERE orders.store_num = 
10           mr_custrec.store_num 
11
12   IF ord_count > 0 THEN
13     MESSAGE "Store has existing orders"
14   ELSE
15     MENU "Delete" ATTRIBUTES (STYLE="dialog", 
16                   COMMENT="Delete the row?")
17      COMMAND "Yes"
18        LET del_ok = TRUE
19      COMMAND "No"
20        MESSAGE "Delete canceled"
21      END MENU
22   END IF
23
24   RETURN del_ok 
25
26 END FUNCTION

The function delete_cust is added to the custquery.4gl module to delete the row from the customer table.

Function delete_cust (custquery.4gl)
01 FUNCTION delete_cust()
02
03   WHENEVER ERROR CONTINUE
04   DELETE FROM customer 
05     WHERE store_num = mr_custrec.store_num 
06   WHENEVER ERROR STOP
07   IF SQLCA.SQLCODE = 0 THEN
08     MESSAGE "Row deleted"
09     INITIALIZE mr_custrec.* TO NULL
10   ELSE
11     ERROR SQLERRMESSAGE 
12   END IF
13
14 END FUNCTION
Note: