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:
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: