This program performs generic searches for employees by surname. The user specifies all or part of an employee's surname and a resulting list of employees with names matching the request is displayed.
******** Define work variables and browse list to be used
DEFINE FIELD(#L1COUNT) TYPE(*DEC) LENGTH(7) DECIMALS(0)
DEF_LIST NAME(#L1) FIELDS((#SURNAME) (#GIVENAME) (#EMPNO)
******** Loop until terminated by EXIT or CANCEL
******** Get surname to search for
******** Build list of generically identical names
SELECT FIELDS(#L1) FROM_FILE(PSLMSTV1)
******** If names found, display list to user
IF COND('#L1COUNT *GT 0')
******** else issue error indicating none found
MESSAGE MSGTXT('No employees have a surname
******** Loop back and request next name to search for
This program will work just fine, but what if the user inputs a search name of "D", and 800 employees working for the company have a surname that starts with "D"?
The result will be a list containing 800 names. But more importantly, it will take a long time to build up the list and use a lot of computer resource while doing it.
To solve this problem, a technique called "page at a time" browsing is often used. What this basically means is that the program extracts one "page" of names matching the request, and then displays them to the user. If the user presses the roll up key then the next page is fetched and displayed, etc, etc.