Tutorial Chapter 13: Master/Detail using Multiple Dialogs |
The custlist.4gl module defines a 'zoom' module, to let the user select a customer from a list. The module could be reused for any application that requires the user to select a customer from a list.
This module uses the custlist.per form and is implemented with a DIALOG instruction defining a CONSTRUCT sub-dialog and a DISPLAY ARRAY sub-dialog. The display_custlist() function in this module returns the customer id and the name.
In the application illustrated in this chapter, the main module orders.4gl will call the display_custlist() function to retrieve a customer selected by the user.
01 ON ACTION zoom1 02 CALL display_custlist() RETURNING id, name 03 IF (id > 0) THEN 04 ...
Here is the complete source code.
Module custlist.4gl:
001 SCHEMA custdemo 002 003 TYPE cust_t RECORD 004 store_num LIKE customer.store_num, 005 store_name LIKE customer.store_name, 006 city LIKE customer.city 007 END RECORD 008 009 DEFINE cust_arr DYNAMIC ARRAY OF cust_t 010 011 FUNCTION custlist_fill(where_clause) 012 DEFINE where_clause STRING 013 DEFINE idx SMALLINT 014 DEFINE cust_rec cust_t 015 016 DECLARE custlist_curs CURSOR FROM 017 "SELECT store_num, store_name, city "|| 018 " FROM customer"|| 019 " WHERE "||where_clause|| 020 " ORDER BY store_num" 021 022 LET idx = 0 023 CALL cust_arr.clear() 024 FOREACH custlist_curs INTO cust_rec.* 025 LET idx = idx + 1 026 LET cust_arr[idx].* = cust_rec.* 027 END FOREACH 028 029 END FUNCTION 030 031 FUNCTION display_custlist() 033 DEFINE ret_num LIKE customer.store_num 034 DEFINE ret_name LIKE customer.store_name 035 DEFINE where_clause STRING 036 DEFINE idx SMALLINT 037 038 OPEN WINDOW wcust WITH FORM "custlist" 039 040 LET ret_num = 0 041 LET ret_name = NULL 042 043 DIALOG ATTRIBUTES(UNBUFFERED) 044 045 CONSTRUCT BY NAME where_clause ON customer.store_name 046 END CONSTRUCT 047 048 DISPLAY ARRAY cust_arr TO sa_cust.* 049 END DISPLAY 050 051 BEFORE DIALOG 052 CALL custlist_fill("1 = 1") 053 054 ON ACTION fetch 055 CALL custlist_fill(where_clause) 056 057 ON ACTION accept 058 LET idx = DIALOG.getCurrentRow("sa_cust") 059 IF idx > 0 THEN 060 LET ret_num = cust_arr[idx].store_num 061 LET ret_name = cust_arr[idx].store_name 062 EXIT DIALOG 063 END IF 064 065 ON ACTION cancel 066 EXIT DIALOG 067 068 END DIALOG 069 070 CLOSE WINDOW wcust 071 072 RETURN ret_num, ret_name 073 074 END FUNCTION