Page 1 of 2
Multiple Selection Dropdown
Posted: Wed May 01, 2013 9:47 am
by emhill
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!
Re: Multiple Selection Dropdown
Posted: Wed May 01, 2013 3:11 pm
by Scott Klement
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....
- 5-1-2013 2-05-51 PM.png (2.14 KiB) Viewed 1261 times
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
Or, if you prefer instead of an array, you could do it like this:
Code: Select all
x = 0;
option1 = gettok(result: ',': x);
option2 = gettok(result: ',': x);
option3 = gettok(result: ',': x);
Does that help?
Re: Multiple Selection Dropdown
Posted: Wed May 01, 2013 5:46 pm
by Scott Klement
I shoudl clarify that 'result' is the same of the field that's bound to the select box "value" property.
Re: Multiple Selection Dropdown
Posted: Wed May 01, 2013 6:08 pm
by emhill
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
Re: Multiple Selection Dropdown
Posted: Wed May 01, 2013 6:16 pm
by Scott Klement
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.
Re: Multiple Selection Dropdown
Posted: Wed May 01, 2013 7:51 pm
by emhill
Yep...that was it. I looked at that I don't know how many times but that never registered.
Works great!
Thanks again, Scott!!!!!
Re: Multiple Selection Dropdown
Posted: Fri May 03, 2013 10:54 am
by emhill
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?
Re: Multiple Selection Dropdown
Posted: Fri May 03, 2013 12:40 pm
by Scott Klement
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.
Re: Multiple Selection Dropdown
Posted: Fri May 03, 2013 5:03 pm
by emhill
Thanks Scott...that was just my typo....
Working great.
Re: Multiple Selection Dropdown
Posted: Fri Oct 09, 2015 4:59 pm
by cproctor
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!