Tutorial Chapter 7: Array Display |
The DISPLAY ARRAY statement lets the user view the contents of an array of records, scrolling through the display.
The example defines a program array of records, each record having members that correspond to the fields of the screen records defined in the form specification file. The DISPLAY ARRAY statement displays all the records in the program array into the rows of the screen array. Typically the program array has many more rows of data than will fit on the screen.
When using a static array, the number of rows to be displayed is defined by the COUNT attribute. If you do not use the COUNT attribute, the runtime system cannot determine how much data to display, and so the screen array remains empty.
When using a dynamic array, the number of rows to be displayed is defined by the number of elements in the dynamic array; the COUNT attribute is ignored.
Example:
01 DISPLAY ARRAY cust_arr TO sa_cust.*
This statement will display the program array cust_arr to the form fields defined in the sa_cust screen array of the form.
By default, the DISPLAY ARRAY statement does not terminate until the user accepts or cancels the dialog; the Accept and Cancel actions are predefined and display on the form. Your program can accept the dialog instead, using the ACCEPT DISPLAY instruction.
When the user accepts or cancels a dialog, the ARR_CURR built-in function returns the index (subscript number) of the row in the program array that was selected (current).
The cust_lib.4gl module contains the library function display_custarr, that can be reused by other programs that reference the customer table.
01 SCHEMA custdemo 02 03 FUNCTION display_custarr() 04 05 DEFINE cust_arr DYNAMIC ARRAY OF RECORD 06 store_num LIKE customer.store_num, 07 store_name LIKE customer.store_name, 08 city LIKE customer.city, 09 state LIKE customer.state, 10 zip_code LIKE customer.zip_code, 11 contact_name LIKE customer.contact_name, 12 phone LIKE customer.phone 13 END RECORD, 14 cust_rec RECORD 15 store_num LIKE customer.store_num, 16 store_name LIKE customer.store_name, 17 city LIKE customer.city, 18 state LIKE customer.state, 19 zip_code LIKE customer.zip_code, 20 contact_name LIKE customer.contact_name, 21 phone LIKE customer.phone 22 END RECORD, 23 ret_num LIKE customer.store_num, 24 ret_name LIKE customer.store_name, 25 curr_pa SMALLINT 26 27 OPEN WINDOW wcust WITH FORM "manycust" 28 29 DECLARE custlist_curs CURSOR FOR 30 SELECT store_num, 31 store_name, 32 city, 33 state, 34 zip_code, 35 contact_name, 36 phone 37 FROM customer 38 ORDER BY store_num 39 40 41 CALL cust_arr.clear() 42 FOREACH custlist_curs INTO cust_rec.* 43 CALL cust_arr.appendElement() 44 LET cust_arr[cust_arr.getLength()].* = cust_rec.* 45 END FOREACH 46 47 LET ret_num = 0 48 LET ret_name = NULL 49 50 IF (cust_arr.getLength() > 0) THEN 51 DISPLAY ARRAY cust_arr TO sa_cust.* 52 IF NOT INT_FLAG THEN 53 LET curr_pa = arr_curr() 54 LET ret_num = cust_arr[curr_pa].store_num 55 LET ret_name = cust_arr[curr_pa].store_name 56 END IF 57 END IF 58 59 CLOSE WINDOW wcust 60 RETURN ret_num, ret_name 61 62 END FUNCTION