Example: custmain.4gl

This module contains the MAIN program block for the query program, and the MENU that drives the query actions.

Module custmain.4gl:
  1 IMPORT FGL custquery
  2 
  3 MAIN
  4 
  5   DEFER INTERRUPT
  6 
  7   CONNECT TO "custdemo"
  8 
  9   CLOSE WINDOW SCREEN
 10   OPEN WINDOW w1 WITH FORM "custform"
 11      ATTRIBUTES(TEXT="Customer")
 12 
 13   MENU "Customer"
 14     ON ACTION query ATTRIBUTES(COMMENT="Search for customers")
 15       CALL custquery.query_cust()
 16     ON ACTION next
 17       CALL custquery.fetch_rel_cust(1)
 18     ON ACTION previous
 19       CALL custquery.fetch_rel_cust(-1)
 20     ON ACTION quit
 21       EXIT MENU
 22   END MENU
 23 
 24   CLOSE WINDOW w1
 25 
 26   DISCONNECT CURRENT
 27 
 28 END MAIN
Note:
  • Line 1: Declare that the custquery module must be imported, by using the IMPORT FGL instruction. This is mandatory in order to use symbols such as functions, that are defined in the custquery module.
  • Note that the SCHEMA statement is not needed since this module does not define any program variables in terms of a database table.
  • Line 3: Beginning of the MAIN block.
  • Line 5 uses the DEFER INTERRUPT statement to prevent the user from terminating the program prematurely with a SIGINT for example.
  • Line 10 opens a window with the form file.
  • Lines 13 thru 22 contains the MENU for the query program. Four actions - query, next, previous, and quit - will be displayed as buttons on the form.
  • Line 15 calls the function query_cust in the cust_query module.
  • Line 17 calls the function fetch_rel_cust in the cust_query module. The literal value 1 is passed to the function, indicating that the cursor should move forward to the next row.
  • Line 19 calls the function fetch_rel_cust also, but passes the literal value -1, indicating that the cursor should move backwards to retrieve the previous row in the results set.

There are no further statements so the Query program terminates after leaving the MENU dialog.