set_count() takes an integer expression as its argument and specifies the number of records that contain data in a program array.
Before you use an INPUT ARRAY WITHOUT DEFAULTS statement or a DISPLAY ARRAY statement, you must call set_count() with an integer argument to specify the total number of records in the program array. Most often, these records contain the values in the retrieved rows that a SELECT statement returned from a database and are associated with a database cursor.
The SET_COUNT( ) built-in function sets an initial value from which the ARR_COUNT( ) function determines the total number of members in an array. If you do not explicitly call SET_COUNT( ), a default value of zero is assigned.
MAIN
DEFINE arr ARRAY[10] OF RECORD
idx INTEGER,
data CHAR(5)
END RECORD
DEFINE i INTEGER
OPEN WINDOW w_test
AT 2, 2
WITH FORM "set_count_function"
ATTRIBUTE(BORDER)
FOR i = 1 TO 10
LET arr[i].idx = i
LET arr[i].data = "ln:", i USING "<&"
END FOR
LET i = 5
WHILE TRUE
CALL set_count(i)
DISPLAY ARRAY arr TO sc_rec.*
ON KEY (F1)
LET i = i - 1
EXIT DISPLAY
ON KEY (F2)
LET i = i + 1
EXIT DISPLAY
ON KEY (F9)
EXIT WHILE
END DISPLAY
IF i > 10 THEN
LET i = 10
END IF
IF i < 1 THEN
LET i = 1
END IF
END WHILE
END MAIN
[Field sizes for ‘f1’ are reduced on the page to show layout.]
DATABASE formonly
SCREEN
{
[f0 ][f1 ] Press\g \g(F1)\g \gfor\g \gless\g \grows
[f0 ][f1 ] Press\g \g(F2)\g \gfor\g \gmore\g \grows
[f0 ][f1 ]
[f0 ][f1 ]
[f0 ][f1 ]
[f0 ][f1 ]
[f0 ][f1 ]
[f0 ][f1 ]
[f0 ][f1 ]
[f0 ][f1 ] Press\g \g(F9)\g \gto\g \gexit
}
ATTRIBUTES
f0=formonly.idx;
f1=formonly.data;
INSTRUCTIONS
SCREEN RECORD sc_rec [10] (
formonly.idx,
formonly.data
)
DELIMITERS "[]"
In this program, the variable i is an array index that received its value in an earlier FOREACH loop. The index was initialized with a value of 1, so the expression (n_rows -1) represents the number of rows that were fetched from a database table in the FOREACH loop. The expression set_count(i- 1) tells DISPLAY ARRAY how many program records containing row values from the database are in the program array, so it can determine how to control the screen array.
FOREACH c_contact INTO cont_arr[i]
LET i = i + 1
END FOREACH
CALL SET_COUNT(i - 1)
DISPLAY ARRAY cont_arr
TO sc_cont.*
If no INPUT ARRAY statement has been executed, and you do not call set_count(), DISPLAY ARRAY or INPUT ARRAY WITHOUT DEFAULTS displays no records.