arr_count() returns a positive whole number, typically representing the number of records entered in a program array during or after execution of the INPUT ARRAY statement.
You can use arr_count() to determine the number of program records that are currently stored in a program array. In typical 4GL applications, these records correspond to values from the active set of retrieved database rows from the most recent query. By first calling set_count(), you can set an upper limit on the value that arr_count() returns.
arr_count() returns a positive integer, corresponding to the index of the furthest record within the program array that the screen cursor accessed. Not all the rows counted by arr_count() necessarily contain data (for example, if the user presses the DOWN ARROW key more times than there are rows of data). If set_count() was explicitly called, arr_count() returns the greater of these two values: the argument of set_count() or the highest value attained by the array index.
This example uses the value returned by arr_count() to count the size of the screen record:
MAIN
DEFINE
x ARRAY[10] OF RECORD
a CHAR(10),
b CHAR(10)
END RECORD,
i INTEGER
FOR i = 1 TO 5
LET x[i].a = "Line: ", i USING "<&"
LET x[i].b = "Data: ", i USING "<&"
END FOR
OPEN WINDOW w_test
AT 2, 2
WITH FORM "arr_count_function"
CALL set_count(5)
INPUT ARRAY x WITHOUT DEFAULTS FROM sc_rec.*
ON KEY (F5)
LET i = arr_count()
ERROR "There are ", i USING "<&", " lines of data"
END INPUT
CALL fgl_winmessage("Exit","Press any key to close this demo application","info")
CLOSE WINDOW w_test
END MAIN
DATABASE formonly
SCREEN
{
[f1 ][f2 ]
[f1 ][f2 ]
[f1 ][f2 ]
[f1 ][f2 ]
[f1 ][f2 ]
[f1 ][f2 ]
[f1 ][f2 ]
[f1 ][f2 ]
[f1 ][f2 ]
[f1 ][f2 ]
Press (F5) to check the array count.
Press (Escape) to exit
}
ATTRIBUTES
f1=formonly.a;
f2=formonly.b;
INSTRUCTIONS
SCREEN RECORD sc_rec [10] (
formonly.a,
formonly.b
)
DELIMITERS "[]"
This example makes use of ARR_COUNT( ) and the related built-in functions ARR_ CURR( ) and SCR_LINE( ) to assign values to variables within the BEFORE ROW clause of a DISPLAY ARRAY statement.
By calling these functions in BEFORE ROW, the respective variables are evaluated each time the cursor moves to a new line and are available within other clauses of the DISPLAY ARRAY statement.
MAIN
DEFINE arr1 ARRAY[20] OF RECORD
f1 CHAR(10),
f2 CHAR(10),
f3 CHAR(10)
END RECORD
DEFINE i, j INTEGER
OPEN WINDOW w_test
AT 2, 2
WITH FORM "arr_curr_function"
FOR i = 1 TO 20
LET arr1[i].f1 = "Row ", i USING "<&"
LET arr1[i].f2 = "Column 2"
LET arr1[i].f3 = "Column 3"
END FOR
CALL set_count(20)
DISPLAY ARRAY arr1 TO sc_rec.*
BEFORE ROW
LET i = arr_curr()
LET j = scr_line()
DISPLAY i TO f_arr_curr
DISPLAY j TO f_scr_line
END DISPLAY
CLOSE WINDOW w_test
END MAIN
DATABASE formonly
SCREEN
{
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
[f1 ][f2 ][f3 ]
}
ATTRIBUTES
f1=formonly.a;
f2=formonly.f_arr_curr;
f3=formonly.f_scr_line;
INSTRUCTIONS
SCREEN RECORD sc_rec [20] (
formonly.a,
formonly.f_arr_curr,
formonly.f_scr_line
)
DELIMITERS "[]"