Focal Point
[SOLVED] Substring parameter into multiple parameters

This topic can be found at:
http://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/7447050886

October 18, 2017, 04:53 AM
MrM
[SOLVED] Substring parameter into multiple parameters
Hi,

Does anyone no how to split one parameter into multiple parameters.

Excample :

Input : &WEEKNUMBERS = 01 OR 06 OR 10 OR 11
Output: &WEEKNUMBER01 = 01
&WEEKNUMBER02 = 06
&WEEKNUMBER03 = 10
&WEEKNUMBER04 = 11

Thanks Mark

This message has been edited. Last edited by: FP Mod Chuck,
October 18, 2017, 07:16 AM
Mikel
Hi

You can use the GETTOK function.

Example
-* 2017-10-18 - Split var based +1 char delimiter.

-DEFAULTH &STR = '01 OR 06 OR 10 OR 11' ;
-DEFAULTH &DEL = ' OR ' ;

-TYPE String...: '&STR'
-TYPE Delimiter: '&DEL'

-* Use 1 char delimiter, comma for example.
-SET &LEN = &STR.LENGTH ;
-SET &STR = STRREP (&LEN, &STR, &DEL.LENGTH, &DEL, 1, ',', &LEN, 'A&LEN.EVAL') ;
-SET &STR = TRUNCATE(&STR);
-SET &LEN = &STR.LENGTH ;

-* Tokens extraction loop.
-SET &I = 0 ;
-SET &SUB = 'X' ;
-REPEAT :LOOPEND WHILE &SUB NE ' ' ;
-SET &I = &I + 1 ;
-SET &SUB = GETTOK(&STR, &LEN, &I, ',', &LEN, 'A&LEN');
-SET &SUB = TRUNCATE(&SUB) ;
-SET &SUB.&I = &SUB ;
-TYPE Substr &I : &SUB.&I
-:LOOPEND


Output
String...: '01 OR 06 OR 10 OR 11'
Del......: ' OR '
Substr 1 : 01
Substr 2 : 06
Substr 3 : 10
Substr 4 : 11
Substr 5 :


Regards. Mikel.


WebFOCUS 8.1.05, 8.2.01
October 18, 2017, 07:47 AM
MrM
Hi Mikel,

Thanks exactly what I needed.

Kind Regards

Mark
October 18, 2017, 09:16 AM
MartinY
Using WF8 you can also use TOKEN function. It's a little more simplest then GETTOK but do the same.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
November 13, 2017, 06:02 PM
Doug
I like the new TOKEN function better than GETTOK Smiler
November 15, 2017, 03:06 AM
Chaudhary
Doug,

I was working with Token function in WF 8105
and I replaced GETTOK function with TOKEN in Mikel's code it shows error
quote:
(FOC36355) INVALID TYPE OF ARGUMENT #3 FOR USER FUNCTION TOKEN


 
 -DEFAULTH &STR = '01 OR 06 OR 10 OR 11' ;
-DEFAULTH &DEL = ' OR ' ;

-TYPE String...: '&STR'
-TYPE Delimiter: '&DEL'

-* Use 1 char delimiter, comma for example.
-SET &LEN = &STR.LENGTH ;
-SET &STR = STRREP (&LEN, &STR, &DEL.LENGTH, &DEL, 1, ',', &LEN, 'A&LEN.EVAL') ;
-SET &STR = TRUNCATE(&STR);
-SET &LEN = &STR.LENGTH ;

-* Tokens extraction loop.
-SET &I = 0 ;
-SET &SUB = 'X' ;
-REPEAT :LOOPEND WHILE &SUB NE ' ' ;
-SET &I = &I + 1 ;
-*-SET &SUB = GETTOK(&STR, &LEN, &I, ',', &LEN, 'A&LEN');
-SET &SUB = TOKEN(&STR, ',' ,&I );
-SET &SUB = TRUNCATE(&SUB) ;
-SET &SUB.&I = &SUB ;
-TYPE Substr &I : &SUB.&I
-:LOOPEND


It seems that we can not pass Parameter value in number place.

This message has been edited. Last edited by: Chaudhary,


WF Production :- WF:8.0.0.4, 8.1.05 App-studio/Developer Studio(8.1.x) ,
8.2.0.1M , 8.2.0.2 (App-Studio8.2.x),
InfoAssist/+, InfoDiscovery
Output format:-AHTML, PDF, Excel, HTML
Platform:-Windows 7, 8,10
November 15, 2017, 08:00 AM
BabakNYC
I just tried your code in 8.2.01M and it worked. Which version did you test in?


WebFOCUS 8206, Unix, Windows
November 15, 2017, 08:16 AM
MartinY
Perform this small change as for WF8105 to work :

-SET &SUB = TOKEN(&STR, ',' ,&I.EVAL);



WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
November 16, 2017, 03:50 AM
Chaudhary
quote:
I just tried your code in 8.2.01M and it worked. Which version did you test in?

BabakNYC I was trying it in WF8105M


WF Production :- WF:8.0.0.4, 8.1.05 App-studio/Developer Studio(8.1.x) ,
8.2.0.1M , 8.2.0.2 (App-Studio8.2.x),
InfoAssist/+, InfoDiscovery
Output format:-AHTML, PDF, Excel, HTML
Platform:-Windows 7, 8,10
November 16, 2017, 03:53 AM
Chaudhary
quote:
Perform this small change as for WF8105 to work :

-SET &SUB = TOKEN(&STR, ',' ,&I.EVAL);



Thanks Martin in WF8105 it works with "EVAL"


WF Production :- WF:8.0.0.4, 8.1.05 App-studio/Developer Studio(8.1.x) ,
8.2.0.1M , 8.2.0.2 (App-Studio8.2.x),
InfoAssist/+, InfoDiscovery
Output format:-AHTML, PDF, Excel, HTML
Platform:-Windows 7, 8,10