Module custmain.4gl

The MENU statement in the module custmain.4gl is modified to call functions for adding, updating, and deleting the rows in the customer table.

The MAIN block (custmain.4gl)
01 -- custmain.4gl 
02 
03 MAIN
04   DEFINE query_ok INTEGER
05  
06   DEFER INTERRUPT
07   CONNECT TO "custdemo"
08   SET LOCK MODE TO WAIT 6
09   CLOSE WINDOW SCREEN
10   OPEN WINDOW w1 WITH FORM "custform"
11
12   MENU
13    ON ACTION find 
14      LET query_ok = query_cust()
15    ON ACTION next        
16      IF query_ok THEN
17        CALL fetch_rel_cust(1)
18      ELSE
19        MESSAGE"You must query first."
20      END IF
21    ON ACTION previous
22      IF query_ok THEN
23        CALL fetch_rel_cust(-1)
24      ELSE
25        MESSAGE "You must query first."
26      END IF
27    COMMAND "Add" 
28      IF inpupd_cust("A") THEN
29        CALL insert_cust()
30      END IF
31    COMMAND "Delete"
32      IF delete_check() THEN
33        CALL delete_cust()
34      END IF
35    COMMAND "Modify"  
36      IF inpupd_cust("U") THEN
37        CALL update_cust()
38      END IF
39    ON ACTION quit 
40      EXIT MENU
41   END MENU
42 
43   CLOSE WINDOW w1
44 
45   DISCONNECT CURRENT
46
47 END MAIN
Note:
  • Line 08 sets the lock timeout period to 6 seconds.
  • Lines 12 thru 41 define the main menu of the program.
  • Lines 27 thru 30 The MENU option Add now calls an inpupd_cust function. Since this same function will also be used for updates, the value "A", indicating an Add of a new row, is passed. If inpupd_cust returns TRUE, the insert_cust function is called.
  • Lines 31 thru 34 The MENU option Delete now calls a delete_check function. If delete_check returns TRUE, the delete_cust function is called.
  • Lines 35 thru 38 are added to the MENU statement for the Modify option, calling the inpud_cust function. The value "U", for an Update of a new row, is passed as a parameter. If inpupd_cust returns TRUE, the update_cust function is called.