5.3.5 Browsing and Selecting
Create a function to display all customers whose names generically match the name specified. Allow customers to be chosen from the list for a detailed display.
Files Involved
Physical file CUSMST (customer master file) and logical file CUSMSTV1 which is a view of CUSMST viewed by customer name.
Version 1
GROUP_BY NAME(#CUSTOMER) FIELDS(#CUSTNO #NAME #ADDL1
#ADDL2 #ADDL3)
DEF_LIST NAME(#BROWCUST) FIELDS((#CHOOSE *SELECT)
#CUSTNO #NAME) COUNTER(#NUMCUSTS)
BEGIN_LOOP
<< Get the customer name >>
REQUEST FIELD(#NAME)
<< Build up list of customers with same generic name >>
CLR_LIST NAMED(#BROWCUST)
SELECT FIELDS(#BROWCUST) FROM_FILE(CUSMSTV1)
WITH_KEY(#NAME) GENERIC(*YES)
ADD_ENTRY TO_LIST(#BROWCUST)
ENDSELECT
<< If none found issue message >>
IF COND('#NUMCUSTS = 0')
MESSAGE MSGTXT('No customers found with this name')
ELSE
<< else display list for selection >>
DISPLAY BROWSELIST(#BROWCUST)
<< process selected customers and display in detail >>
SELECTLIST NAMED(#BROWCUST) GET_ENTRYS(*SELECT)
FETCH FIELDS(#CUSTOMER) FROM_FILE(CUSMST)
WITH_KEY(#CUSTNO)
DISPLAY FIELDS(#CUSTOMER)
ENDSELECT
ENDIF
END_LOOP
Points to Note:
- The GENERIC(*YES) option automatically causes generic searching to be performed against the customer name.
Version 2
GROUP_BY NAME(#CUSTOMER) FIELDS(#CUSTNO #NAME #ADDL1
#ADDL2 #ADDL3)
DEF_LIST NAME(#BROWCUST) FIELDS((#CHOOSE *SELECT)
#CUSTNO #NAME) COUNTER(#NUMCUSTS)
DEFINE FIELD(#GENNAME) REFFLD(#NAME)
BEGIN_LOOP
<< Display the list - empty on first cycle >>
DISPLAY FIELD((#GENNAME *INPUT))
BROWSELIST(#BROWCUST)
<< Process any selected entries - none in first cycle >>
CHANGE FIELD(#TOTSELECT) TO(0)
SELECTLIST NAMED(#BROWCUST) GET_ENTRYS(*SELECT)
CHANGE FIELD(#TOTSELECT) TO('#TOTSELECT + 1')
FETCH FIELDS(#CUSTOMER) FROM_FILE(CUSTMST)
WITH_KEY(#CUSTNO)
DISPLAY FIELDS(#CUSTOMER)
ENDSELECT
<< If none selected build a new list >>
IF COND('#TOTSELECT = 0')
CLR_LIST NAMED(#BROWCUST)
SELECT FIELDS(#BROWCUST) FROM_FILE(CUSMSTV1)
WITH_KEY(#GENNAME) GENERIC(*YES)
ADD_ENTRY TO_LIST(#BROWCUST)
ENDSELECT
IF COND('#NUMCUSTS = 0')
MESSAGE MSGTXT('No customers found with this name')
ENDIF
ENDIF
END_LOOP
Points to Note:
- When the BEGIN_LOOP / END_LOOP loop is entered for the first time the list will be empty so it will not display at the first DISPLAY command. Likewise the SELECTLIST loop will not process any entries .... so a search will be made for the customers.
- Subsequent iterations of the loop will only re-build the customer list if no customer is chosen from the list for detailed display.
- The main difference between this version and the first is that this function only uses one screen format to ask for the customer name and to display the list. The first version uses 2 separate screen formats.
- Note the attribute *INPUT associated with field #GENNAME. This states that field #GENNAME should always be input capable, no matter what screen processing mode is in use.