Multiple Selection Dropdown
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Multiple Selection Dropdown
I am using the multiple selection capability from a select/dropdown box for the first time and was wondering what is the suggested way to parse out the returned values in RPG? I have a few ideas but they seem to be a bit ***. I would like to make this as generic as possible so it can be copied and used for any multiple selection select/dropdown box.
Any suggestions from a code-blocked brain?? :-)
Thanks in advance!
Any suggestions from a code-blocked brain?? :-)
Thanks in advance!
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Multiple Selection Dropdown
The result of multiple selections will be a comma-separated list.
I have a subprocedure named 'gettok' that I like to use for this sort of thing. It works nicely as long as there are no commas in the data itself. If there are commas, you'll need to write a better routine :-)
For example, let's say I have a select box with 5 options named test1, test2, test3, test4, test5.... This has "multiple = true", so user can select, for example the first, third and fifth options, so the result returned to my RPG would be: test1,test3,test5.
I can use gettok() to spit these out, like this:
Or, if you prefer instead of an array, you could do it like this:
Does that help?
I have a subprocedure named 'gettok' that I like to use for this sort of thing. It works nicely as long as there are no commas in the data itself. If there are commas, you'll need to write a better routine :-)
For example, let's say I have a select box with 5 options named test1, test2, test3, test4, test5.... This has "multiple = true", so user can select, for example the first, third and fifth options, so the result returned to my RPG would be: test1,test3,test5.
I can use gettok() to spit these out, like this:
Code: Select all
D x s 10i 0
D opt s 5a dim(5)
/free
exfmt rec;
x = 0;
opt(*) = gettok(result: ',': x);
for x = 1 to %elem(opt);
if opt(x) <> *blanks;
dsply opt(x);
endif;
endfor;
*inlr = *on;
/end-free
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* gettok(): Get next token from string
*
* string = (input) string to search
* delims = (input) delimiters
* pos = (i/o) next position to search. At the start
* of a string, set this to zero. Pass
* it on subsequent calls to remember where
* you left off.
*
* Returns the token found.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P gettok B
D gettok PI 1024A varying
D string 65535A varying const options(*varsize)
D delims 50A varying const
D pos 10I 0
D res s 1024A varying
D start s 10I 0
D c s 1A
/free
start = pos + 1;
%len(res) = 0;
for pos = start to %len(string);
c = %subst(string:pos:1);
if %check(delims:c) = 1;
res = res + c;
else;
leave;
endif;
endfor;
return res;
/end-free
P E
Code: Select all
x = 0;
option1 = gettok(result: ',': x);
option2 = gettok(result: ',': x);
option3 = gettok(result: ',': x);
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Multiple Selection Dropdown
I shoudl clarify that 'result' is the same of the field that's bound to the select box "value" property.
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Multiple Selection Dropdown
That was my next question. I used the bound field ui_str (defined 20a) and it is giving me an error on compile: RNF7535 The type and attributes of the parameter do not match those of the prototype. What should the field length be for the ui_str?
opt(*) = gettok(ui_str: ',' : x);
P gettok B
D gettok PI 1024a varying
D string 65535a varying const options(*varsize)
D delims 50a varying const
D pos 10i 0
D res s 1024a varying
D start s 10i 0
D c s 1a
/free
start = pos + 1;
%len(res) = *zero;
for pos = start to %len(string);
c = %subst(string:pos:1);
if %check(delims:c) = 1;
res = res + c;
else;
leave;
endif;
endfor;
return res;
/end-free
P E
opt(*) = gettok(ui_str: ',' : x);
P gettok B
D gettok PI 1024a varying
D string 65535a varying const options(*varsize)
D delims 50a varying const
D pos 10i 0
D res s 1024a varying
D start s 10i 0
D c s 1a
/free
start = pos + 1;
%len(res) = *zero;
for pos = start to %len(string);
c = %subst(string:pos:1);
if %check(delims:c) = 1;
res = res + c;
else;
leave;
endif;
endfor;
return res;
/end-free
P E
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Multiple Selection Dropdown
20A should work fine with that prototype. how do you have X defined? That one MUST be 10i 0. But any alpha field should work fine for the first field.
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Multiple Selection Dropdown
Yep...that was it. I looked at that I don't know how many times but that never registered.
Works great!
Thanks again, Scott!!!!!
Works great!
Thanks again, Scott!!!!!
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Multiple Selection Dropdown
Scott,
A little bit of a problem for this guy who is green when it comes to sub-procedures and prototypes.
We of course have two RPG objects created when dealing with PUI. One for the green screen and one for the PUI version. We still have clients that are on version 5.4.0 and we have to CRTBNDRPG with the TGTRLS of V5R4M0 for the green screen versions. Most of our programs are not in RPG free so I created a copybook of the sub-procedure you provided (GETTOK). It works great in V7R1M0 by just using this:
EVAL ARR(*) = GETTOK(STRING:',':XX)
But when I try to compile that with the target release of V5R4M0 I get the RNF7535 error "The type and attributes of the parameter do not match those of the prototype."
I can use the /IF DEFINED(UI) statement to wrap everything but that could get a bit ***. I probably need to define the prototype in the D specs of the RPG but there is where I have my problem. I'm not sure how to define all the fields and how to define the prototype for return data. I THINK it would look something like this which is basically copy of the sub-procedure parameters:
D GETTOK PR 1024A Varying
D STRING 65535A Varying const options(*varsize)
D DELIMS 50A Varying cnost
D POS 10I 0
Am I close??? :-)
Thanks so much for your help. You are teaching this old dog new tricks!!!!!
***** Edit *****
I tried the above and it seems to work just fine when compiling to V5R4M0 but do you see any gotchas in how I did it?
A little bit of a problem for this guy who is green when it comes to sub-procedures and prototypes.
We of course have two RPG objects created when dealing with PUI. One for the green screen and one for the PUI version. We still have clients that are on version 5.4.0 and we have to CRTBNDRPG with the TGTRLS of V5R4M0 for the green screen versions. Most of our programs are not in RPG free so I created a copybook of the sub-procedure you provided (GETTOK). It works great in V7R1M0 by just using this:
EVAL ARR(*) = GETTOK(STRING:',':XX)
But when I try to compile that with the target release of V5R4M0 I get the RNF7535 error "The type and attributes of the parameter do not match those of the prototype."
I can use the /IF DEFINED(UI) statement to wrap everything but that could get a bit ***. I probably need to define the prototype in the D specs of the RPG but there is where I have my problem. I'm not sure how to define all the fields and how to define the prototype for return data. I THINK it would look something like this which is basically copy of the sub-procedure parameters:
D GETTOK PR 1024A Varying
D STRING 65535A Varying const options(*varsize)
D DELIMS 50A Varying cnost
D POS 10I 0
Am I close??? :-)
Thanks so much for your help. You are teaching this old dog new tricks!!!!!
***** Edit *****
I tried the above and it seems to work just fine when compiling to V5R4M0 but do you see any gotchas in how I did it?
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Multiple Selection Dropdown
The prototype should be identical to the PI, except of course, that the letters "PI" are replaced with "PR".
Yours looks okay to me, except that you have a typo in the "const" keyword (you have "cnost") on the 3rd line.
Yours looks okay to me, except that you have a typo in the "const" keyword (you have "cnost") on the 3rd line.
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Multiple Selection Dropdown
Thanks Scott...that was just my typo....
Working great.
Working great.
-
- New User
- Posts: 11
- Joined: Thu Jun 12, 2014 1:59 pm
- First Name: Chris
- Last Name: Proctor
- Company Name: Columbia Sportswear Co.
- Phone: 5039851509
- State / Province: Oregon
- Country: United States
- Contact:
Re: Multiple Selection Dropdown
Hello! Can someone tell me if PUI still works this way, passing back multiple dropdown selections in the "choice values" bound field in the "selection choices" section of the properties? I have a field defined but if I debug it immediately after returning from the EXFMT, the field is empty. I am expecting to see a comma-delimited list of the selected items, correct? Thanks!
Chris Proctor
Columbia Sportswear Company
Columbia Sportswear Company
Who is online
Users browsing this forum: No registered users and 2 guests