The MAIN program block
The MAIN program block contains the menu for the
orders program.
MAIN program block
(orders.4gl):01 SCHEMA custdemo
02
03 DEFINE order_rec RECORD
04 store_num LIKE orders.store_num,
05 store_name LIKE customer.store_name,
06 order_num LIKE orders.order_num,
07 order_date LIKE orders.order_date,
08 fac_code LIKE orders.fac_code,
09 ship_instr LIKE orders.ship_instr,
10 promo LIKE orders.promo
11 END RECORD,
12 arr_items DYNAMIC ARRAY OF RECORD
13 stock_num LIKE items.stock_num,
14 description LIKE stock.description,
15 quantity LIKE items.quantity,
16 unit LIKE stock.unit,
17 price LIKE items.price,
18 line_total DECIMAL(9,2)
19 END RECORD
20
21 CONSTANT msg01 = "You must query first"
22 CONSTANT msg02 = "Enter search criteria"
23 CONSTANT msg03 = "Canceled by user"
24 CONSTANT msg04 = "No rows in table"
25 CONSTANT msg05 = "End of list"
26 CONSTANT msg06 = "Beginning of list"
27 CONSTANT msg07 = "Invalid stock number"
28 CONSTANT msg08 = "Row added"
29 CONSTANT msg09 = "Row updated"
30 CONSTANT msg10 = "Row deleted"
31 CONSTANT msg11 = "Enter order"
32 CONSTANT msg12 = "This customer does not exist"
33 CONSTANT msg13 = "Quantity must be greater than zero"
34
35 MAIN
36 DEFINE has_order, query_ok SMALLINT
37 DEFER INTERRUPT
38
39 CONNECT TO "custdemo"
40 CLOSE WINDOW SCREEN
41
42 OPEN WINDOW w1 WITH FORM "orderform"
43
44 MENU
45 BEFORE MENU
46 CALL setup_actions(DIALOG,FALSE,FALSE)
47 ON ACTION new
48 CLEAR FORM
49 LET query_ok = FALSE
50 CALL close_order()
51 LET has_order = order_new()
52 IF has_order THEN
53 CALL arr_items.clear()
54 CALL items_inpupd()
55 END IF
56 CALL setup_actions(DIALOG,has_order,query_ok)
57 ON ACTION find
58 CLEAR FORM
59 LET query_ok = order_query()
60 LET has_order = query_ok
61 CALL setup_actions(DIALOG,has_order,query_ok)
62 ON ACTION next
63 CALL order_fetch_rel(1)
64 ON ACTION previous
65 CALL order_fetch_rel(-1)
66 ON ACTION getitems
67 CALL items_inpupd()
68 ON ACTION quit
69 EXIT MENU
70 END MENU
71
72 CLOSE WINDOW w1
73
74 END MAINNote:
- Lines
03thru11define a record with fields for all the columns in theorderstable, as well asstore_namefrom thecustomertable. - Lines
12through19define a dynamic array with fields for all the columns in theitemstable, as well asquantityandunitfrom thestocktable, and a calculated fieldline_total. - Lines
21thru33define constants to hold the program messages. This centralizes the definition of the messages, which can be used in any function in the module. - Lines
44thru65define the main menu of the application. - Line
46is executed before the menu is displayed; it calls thesetup_actionsfunction to disable navigation and item management actions by default. TheDIALOGpredefined object is passed as the first parameter to the function. - Lines
47thru56perform theaddaction to create a new order. Theorder_newfunction is called, and if it returnsTRUE, theitems_inpupdfunction is called to allow the user to enter items for the new order. Menu actions are enabled/disabled depending on the result of the operation, using thesetup_actionsfunction. - Lines
57thru61perform thefindaction to search for orders in the database. Theorder_queryfunction is called and menu actions are enabled/disabled depending on the result of the operation, using thesetup_actionsfunction. - Lines
62thru65handle navigation in the order list after a search. Functionorder_fetch_relis used to fetch the previous or next record. - Line
67calls the functionitems_inpupdto allow the user to edit theitemsassociated with the displayedorder. - Line
72closes the window before leaving the program.