Function SET005A: Handle multi-Select List Box
FUNCTION OPTIONS(*DIRECT *WEBEVENT);
********** COMMENT(=======================================================);
********** COMMENT(Process ........: SET_005);
********** COMMENT(Function .......: SET005A);
********** COMMENT(Created on .....: 07/02/00);
********** COMMENT();
********** COMMENT(Full Description: The purpose of this sample function);
********** COMMENT(is to show how to process a multi selectable List Box.);
********** COMMENT(The List Box component used in this function is called);
********** COMMENT(S_005DEPT. It was generated by LANSA using the Web);
********** COMMENT(Administrator and it has been added Java Script to);
********** COMMENT(handle the multiselection. Refer to the component);
********** COMMENT(source code to examine the Java Script added to the);
********** COMMENT(visual component.);
********** COMMENT();
********** COMMENT(Disclaimer: The following material is supplied as an);
********** COMMENT(example only. No warranty is expressed or implied.);
********** COMMENT();
********** COMMENT(Group and field definitions);
********** COMMENT();
********** COMMENT(#MAXLENGTH should default to the length value of the);
********** COMMENT(field specified as the Field for Value when generating);
********** COMMENT(the List Box web component. In this example, it is the);
********** COMMENT(length of DEPTMENT. Its value is merged in the piece of);
********** COMMENT(Java Script that handles the multi-selection.);
DEFINE FIELD(#MAXLENGTH) TYPE(*DEC) LENGTH(002) DECIMALS(0) DEFAULT(4);
********** COMMENT(#MAXITEMS should default to the maximum number of items);
********** COMMENT(that can be selected from the List Box. When more items);
********** COMMENT(than the value of #MAXITEMS are selected, a JavaScript);
********** COMMENT(alert messag appears on the browser's screen.);
DEFINE FIELD(#MAXITEMS) TYPE(*DEC) LENGTH(002) DECIMALS(0) DEFAULT(64);
********** COMMENT();
********** COMMENT(#SHOWBROWS controls the ONCONDITION tag. The browselist);
********** COMMENT(is displayed only when it has records in it.);
DEFINE FIELD(#SHOWBROWS) TYPE(*DEC) LENGTH(001) DECIMALS(0);
********** COMMENT();
********** COMMENT(#SELVALUES contains the values selected in the List Box);
DEFINE FIELD(#SELVALUES) TYPE(*CHAR) LENGTH(256);
********** COMMENT(#SELLENGTH has the lengths of the values in #SELVALUES);
********** COMMENT(and it is populated in the subroutine SET_VALLEN.);
********** COMMENT(For example, if SELVALUES has 'ADM FLT TRVL', then);
********** COMMENT(#SELLENGTH will have '334'. Knowing the length of the);
********** COMMENT(the actual value will let us extract the exact value);
********** COMMENT(from #SELVALUES in the JavaScript code and will);
********** COMMENT(simplify it.);
DEFINE FIELD(#SELLENGTH) TYPE(*CHAR) LENGTH(064);
********** COMMENT(Pointer indicating the SUBSTRING start position. Used);
********** COMMENT(SET_VALLEN.);
DEFINE FIELD(#STR_SBSTR) TYPE(*DEC) LENGTH(007) DECIMALS(0);
********** COMMENT();
********** COMMENT(#W_DEPT is a work field to use as the key to access);
********** COMMENT(PSLMST1 because you can't use an array element as key.);
DEFINE FIELD(#W_DEPT) REFFLD(#DEPTMENT);
********** COMMENT(Scanning #DEP will give us the length of the value);
********** COMMENT(without trailing blanks. That length value is used to);
********** COMMENT(populate SELLENGTH. Used in SET_VALLEN subroutine.);
DEF_ARRAY NAME(#DEP) INDEXES(#PP) OVERLAYING(#W_DEPT) TYPE(*CHAR) TOT_ENTRY(0004) ENTRY_LEN(001);
********** COMMENT(Array index used in #DEP);
DEFINE FIELD(#PP) TYPE(*DEC) LENGTH(001) DECIMALS(0);
********** COMMENT();
********** COMMENT(#EMPLIST is a Employee browselist. It will have all the);
********** COMMENT(employees for the selected departments.);
DEF_LIST NAME(#EMPLIST) FIELDS((#DEPTMENT)(#FULLNAME)) COUNTER(#LISTCOUNT);
********** COMMENT();
********** COMMENT(#SEL makes an array of #SELVALUES. Each element has a);
********** COMMENT(length equal to #MAXLENGTH and contains a selected);
********** COMMENT(department.);
DEF_ARRAY NAME(#SEL) INDEXES(#II) OVERLAYING(#SELVALUES) TYPE(*CHAR) TOT_ENTRY(0064) ENTRY_LEN(004);
********** COMMENT();
********** COMMENT(Fields to pass to the REQUEST command.);
GROUP_BY NAME(#PANELDATA) FIELDS((#SELVALUES *HIDDEN)(#STDRENTRY *HIDDEN)(#S_005DEPT)(#SHOWBROWS *HIDDEN)(#MAXLENGTH *HIDDEN)(#MAXITEMS *HIDDEN)(#SELLENGTH *HIDDEN));
********** COMMENT();
********** COMMENT(Don't show the browselist.);
CHANGE FIELD(#SHOWBROWS) TO(0);
********** COMMENT(If first time the function has been invoked, display);
********** COMMENT(the List Box of Departments.);
IF COND('#stdrentry *ne Y');
CHANGE FIELD(#STDRENTRY) TO(Y);
GOTO LABEL(REQ);
ENDIF;
********** COMMENT();
CLR_LIST NAMED(#EMPLIST);
IF COND('#sel#array = *blanks');
MESSAGE MSGTXT('You have not selected any Employees.');
GOTO LABEL(REQ);
ENDIF;
********** COMMENT();
CHANGE FIELD(#STR_SBSTR) TO(1);
CHANGE FIELD(#SELLENGTH) TO(*BLANKS);
********** COMMENT(Loop to process each array element. The loop will end);
********** COMMENT(either when the first blank element has been found or);
********** COMMENT(when the last element has been processed. As each);
********** COMMENT(element represents a department code, it will be used);
********** COMMENT(as the key to access PSLMST1);
BEGIN_LOOP USING(#II) TO(#MAXITEMS);
********** COMMENT();
LEAVE IF('#sel#ii = *blanks');
CHANGE FIELD(#W_DEPT) TO(#SEL#II);
CHANGE FIELD(#STD_COUNT) TO(0);
********** COMMENT(Select all employess for a department);
SELECT FIELDS((#SURNAME)(#GIVENAME)(#DEPTMENT)) FROM_FILE(PSLMST1) WITH_KEY(#W_DEPT);
CHANGE FIELD(#STD_COUNT) TO('#std_count + 1');
IF COND('#std_count > 1');
CHANGE FIELD(#DEPTMENT) TO(*BLANKS);
ENDIF;
USE BUILTIN(BCONCAT) WITH_ARGS(#GIVENAME #SURNAME) TO_GET(#FULLNAME);
ADD_ENTRY TO_LIST(#EMPLIST);
ENDSELECT;
********** COMMENT(Set the length of the Department to populate #SELENGTH);
EXECUTE SUBROUTINE(SET_VALLEN);
END_LOOP;
********** COMMENT();
********** COMMENT(Employess found, make the browselist visible, otherwise);
********** COMMENT(send a message.);
IF COND('#listcount > 0');
CHANGE FIELD(#SHOWBROWS) TO(1);
ELSE;
MESSAGE MSGTXT('No Employess exist in selected department (s).');
ENDIF;
********** COMMENT();
REQ: REQUEST FIELDS(#PANELDATA) BROWSELIST(#EMPLIST) EXIT_KEY(*NO) MENU_KEY(*NO) PROMPT_KEY(*NO);
********** COMMENT();
********** COMMENT(*******************************************************);
SUBROUTINE NAME(SET_VALLEN);
********** COMMENT(*******************************************************);
********** COMMENT(Start scanning the array from the end character);
********** COMMENT(because the values may contain a blank within.);
BEGIN_LOOP USING(#PP) FROM(#MAXLENGTH) TO(1) STEP(-0000001);
LEAVE IF('#dep#pp *ne *blanks');
END_LOOP;
SUBSTRING FIELD(#PP 1) INTO_FIELD(#SELLENGTH #STR_SBSTR);
CHANGE FIELD(#STR_SBSTR) TO('#STR_SBSTR + 1');
ENDROUTINE;
FUNCTION OPTIONS(*DIRECT *WEBEVENT);
********** COMMENT(=======================================================);
********** COMMENT(Process ........: SET_005);
********** COMMENT(Function .......: SET005A);
********** COMMENT(Created on .....: 07/02/00);
********** COMMENT();
********** COMMENT(Full Description: The purpose of this sample function);
********** COMMENT(is to show how to process a multi selectable List Box.);
********** COMMENT(The List Box component used in this function is called);
********** COMMENT(S_005DEPT. It was generated by LANSA using the Web);
********** COMMENT(Administrator and it has been added Java Script to);
********** COMMENT(handle the multiselection. Refer to the component);
********** COMMENT(source code to examine the Java Script added to the);
********** COMMENT(visual component.);
********** COMMENT();
********** COMMENT(Disclaimer: The following material is supplied as an);
********** COMMENT(example only. No warranty is expressed or implied.);
********** COMMENT();
********** COMMENT(Group and field definitions);
********** COMMENT();
********** COMMENT(#MAXLENGTH should default to the length value of the);
********** COMMENT(field specified as the Field for Value when generating);
********** COMMENT(the List Box web component. In this example, it is the);
********** COMMENT(length of DEPTMENT. Its value is merged in the piece of);
********** COMMENT(Java Script that handles the multi-selection.);
DEFINE FIELD(#MAXLENGTH) TYPE(*DEC) LENGTH(002) DECIMALS(0) DEFAULT(4);
********** COMMENT(#MAXITEMS should default to the maximum number of items);
********** COMMENT(that can be selected from the List Box. When more items);
********** COMMENT(than the value of #MAXITEMS are selected, a JavaScript);
********** COMMENT(alert messag appears on the browser's screen.);
DEFINE FIELD(#MAXITEMS) TYPE(*DEC) LENGTH(002) DECIMALS(0) DEFAULT(64);
********** COMMENT();
********** COMMENT(#SHOWBROWS controls the ONCONDITION tag. The browselist);
********** COMMENT(is displayed only when it has records in it.);
DEFINE FIELD(#SHOWBROWS) TYPE(*DEC) LENGTH(001) DECIMALS(0);
********** COMMENT();
********** COMMENT(#SELVALUES contains the values selected in the List Box);
DEFINE FIELD(#SELVALUES) TYPE(*CHAR) LENGTH(256);
********** COMMENT(#SELLENGTH has the lengths of the values in #SELVALUES);
********** COMMENT(and it is populated in the subroutine SET_VALLEN.);
********** COMMENT(For example, if SELVALUES has 'ADM FLT TRVL', then);
********** COMMENT(#SELLENGTH will have '334'. Knowing the length of the);
********** COMMENT(the actual value will let us extract the exact value);
********** COMMENT(from #SELVALUES in the JavaScript code and will);
********** COMMENT(simplify it.);
DEFINE FIELD(#SELLENGTH) TYPE(*CHAR) LENGTH(064);
********** COMMENT(Pointer indicating the SUBSTRING start position. Used);
********** COMMENT(SET_VALLEN.);
DEFINE FIELD(#STR_SBSTR) TYPE(*DEC) LENGTH(007) DECIMALS(0);
********** COMMENT();
********** COMMENT(#W_DEPT is a work field to use as the key to access);
********** COMMENT(PSLMST1 because you can't use an array element as key.);
DEFINE FIELD(#W_DEPT) REFFLD(#DEPTMENT);
********** COMMENT(Scanning #DEP will give us the length of the value);
********** COMMENT(without trailing blanks. That length value is used to);
********** COMMENT(populate SELLENGTH. Used in SET_VALLEN subroutine.);
DEF_ARRAY NAME(#DEP) INDEXES(#PP) OVERLAYING(#W_DEPT) TYPE(*CHAR) TOT_ENTRY(0004) ENTRY_LEN(001);
********** COMMENT(Array index used in #DEP);
DEFINE FIELD(#PP) TYPE(*DEC) LENGTH(001) DECIMALS(0);
********** COMMENT();
********** COMMENT(#EMPLIST is a Employee browselist. It will have all the);
********** COMMENT(employees for the selected departments.);
DEF_LIST NAME(#EMPLIST) FIELDS((#DEPTMENT)(#FULLNAME)) COUNTER(#LISTCOUNT);
********** COMMENT();
********** COMMENT(#SEL makes an array of #SELVALUES. Each element has a);
********** COMMENT(length equal to #MAXLENGTH and contains a selected);
********** COMMENT(department.);
DEF_ARRAY NAME(#SEL) INDEXES(#II) OVERLAYING(#SELVALUES) TYPE(*CHAR) TOT_ENTRY(0064) ENTRY_LEN(004);
********** COMMENT();
********** COMMENT(Fields to pass to the REQUEST command.);
GROUP_BY NAME(#PANELDATA) FIELDS((#SELVALUES *HIDDEN)(#STDRENTRY *HIDDEN)(#S_005DEPT)(#SHOWBROWS *HIDDEN)(#MAXLENGTH *HIDDEN)(#MAXITEMS *HIDDEN)(#SELLENGTH *HIDDEN));
********** COMMENT();
********** COMMENT(Don't show the browselist.);
CHANGE FIELD(#SHOWBROWS) TO(0);
********** COMMENT(If first time the function has been invoked, display);
********** COMMENT(the List Box of Departments.);
IF COND('#stdrentry *ne Y');
CHANGE FIELD(#STDRENTRY) TO(Y);
GOTO LABEL(REQ);
ENDIF;
********** COMMENT();
CLR_LIST NAMED(#EMPLIST);
IF COND('#sel#array = *blanks');
MESSAGE MSGTXT('You have not selected any Employees.');
GOTO LABEL(REQ);
ENDIF;
********** COMMENT();
CHANGE FIELD(#STR_SBSTR) TO(1);
CHANGE FIELD(#SELLENGTH) TO(*BLANKS);
********** COMMENT(Loop to process each array element. The loop will end);
********** COMMENT(either when the first blank element has been found or);
********** COMMENT(when the last element has been processed. As each);
********** COMMENT(element represents a department code, it will be used);
********** COMMENT(as the key to access PSLMST1);
BEGIN_LOOP USING(#II) TO(#MAXITEMS);
********** COMMENT();
LEAVE IF('#sel#ii = *blanks');
CHANGE FIELD(#W_DEPT) TO(#SEL#II);
CHANGE FIELD(#STD_COUNT) TO(0);
********** COMMENT(Select all employess for a department);
SELECT FIELDS((#SURNAME)(#GIVENAME)(#DEPTMENT)) FROM_FILE(PSLMST1) WITH_KEY(#W_DEPT);
CHANGE FIELD(#STD_COUNT) TO('#std_count + 1');
IF COND('#std_count > 1');
CHANGE FIELD(#DEPTMENT) TO(*BLANKS);
ENDIF;
USE BUILTIN(BCONCAT) WITH_ARGS(#GIVENAME #SURNAME) TO_GET(#FULLNAME);
ADD_ENTRY TO_LIST(#EMPLIST);
ENDSELECT;
********** COMMENT(Set the length of the Department to populate #SELENGTH);
EXECUTE SUBROUTINE(SET_VALLEN);
END_LOOP;
********** COMMENT();
********** COMMENT(Employess found, make the browselist visible, otherwise);
********** COMMENT(send a message.);
IF COND('#listcount > 0');
CHANGE FIELD(#SHOWBROWS) TO(1);
ELSE;
MESSAGE MSGTXT('No Employess exist in selected department (s).');
ENDIF;
********** COMMENT();
REQ: REQUEST FIELDS(#PANELDATA) BROWSELIST(#EMPLIST) EXIT_KEY(*NO) MENU_KEY(*NO) PROMPT_KEY(*NO);
********** COMMENT();
********** COMMENT(*******************************************************);
SUBROUTINE NAME(SET_VALLEN);
********** COMMENT(*******************************************************);
********** COMMENT(Start scanning the array from the end character);
********** COMMENT(because the values may contain a blank within.);
BEGIN_LOOP USING(#PP) FROM(#MAXLENGTH) TO(1) STEP(-0000001);
LEAVE IF('#dep#pp *ne *blanks');
END_LOOP;
SUBSTRING FIELD(#PP 1) INTO_FIELD(#SELLENGTH #STR_SBSTR);
CHANGE FIELD(#STR_SBSTR) TO('#STR_SBSTR + 1');
ENDROUTINE;