scroll Statement—Target Scrolls
To scroll to a specific record or to the top or bottom of the data set, use the scroll statement. These specialized scrolls are called target scrolls. A target scroll moves the cursor to a specified row in the data set.
This statement has the following syntax:
scroll formname tablename to record|end;
This statement moves the cursor to the row in the data set with the record number record. The key word end used in place of record causes the program to scroll to the last row in the data set. The following embedded SQL example contains three activate sections, each of which demonstrates a different use of the target scroll.
/* Assume previous declarations, plus ... */
exec sql begin declare section;
searchname character_string(20);
exec sql end declare section;
...
exec frs activate menuitem 'Bottom';
exec frs begin;
/* Scroll to end of data set */
exec frs scroll empform employee to end;
exec frs end;
exec frs activate menuitem 'Top';
exec frs begin;
/* Scroll to first record in data set */
exec frs scroll empform employee to 1;
exec frs end;
exec frs activate menuitem 'Find';
exec frs begin;
/* Prompt for name to search for */
exec frs prompt ('Name to search for: ',:searchname);
/* Loop through data set and stop
** when name is found.*/
exec frs unloadtable empform employee
(:ename = ename, :record = _record);
exec frs begin;
if (ename = searchname) then
/* Scroll to record with specified name. */
exec frs scroll empform employee to :record;
exec frs resume field employee;
end if;
exec frs end;
exec frs message 'Cannot find named employee.';
exec frs sleep 2;
exec frs end;
...
In the Find operation above, when the name is found, the activate section is terminated by the resume statement. If the name has not been found by the time that all rows are unloaded, control passes to the message statement following the end of the unloadtable loop.
Another variant of the scroll statement functions identically to the automatic FRS scrolls, scrolling the displayed data set up or down one line at a time. This variant is used primarily in scroll activation blocks, which are described in the next section. For a discussion of all the scroll statement variants, see the scroll statement description in
Forms Statements.