Was this helpful?
formdata Statement--Loop Through Fields
This statement loops through all fields in the form.
Syntax
formdata formname
begin
    program code;
end
Description
The formdata statement loops through the fields on a specified form, executing the code in the begin/end block for each field. Formname identifies the form and can be expressed as a character string, with or without quotes, or as a program string variable.
This statement is used primarily with the inquire_frs statement to allow inquiries to be easily made on all fields in a form. This is particularly useful if the program does not know until runtime what forms it uses. Formdata causes the same section of code to be executed for all the fields on the form; therefore, the notion of the current field allows inquire_frs to be effectively used.
The template for this usage is:
formdata formname
begin
    inquire_frs on current object;
    program code
end
The syntax of the inquire_frs statement is described in inquire_frs Statement--Retrieve FRS Runtime Information.
The full range of inquire_frs statements, as well as all other embedded SQL and host language statements, can appear within the formdata loop. The formdata loop starts the first pass on the first field in the form and sequences along to the next field, including display-only fields, with each additional pass through the loop.
You can use the formdata statement in conjunction with tabledata to loop through all columns in a table field. See the example below and the tabledata statement description for details.
You cannot issue a formdata statement for a form inside that form's display loop, nor can you initiate a display loop for a form inside a formdata loop of the same form.
To terminate the formdata's program loop, use the endloop statement.
Example--formdata statement:
Loop through a form, printing out all field and column names. The blank strings in the inquire_frs reference the current field and the current table field column, respectively.
exec frs formdata :formname;
exec frs begin;
    exec frs inquire_frs field ''
        (:fldname = name, :istable = table);
    if (istable = 1) then
        print fldname,' is a table field';
        print '---------------';
        exec frs tabledata;
        exec frs begin;
            exec frs inquire_frs column '' ''
                (:colname = name);
            print colname, ' is a column';
        exec frs end;
        print '---------------';
    else
        print fldname, ' is a regular field';
    end if;
exec frs end;
Last modified date: 04/03/2024