Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Assigning parameter values based on an array?

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Assigning parameter values based on an array?
 Login/Join
 
Platinum Member
posted
Hi,

I want to pass an array of values as a single parameter to my program. Something simple like “3,7,12,56,42”.

I want to loop through the array and for every element assign each one to a new parameter, named &P1, &P2 etc up to a max of 10.

Is there a command that I can use that will deconstruct the array if I tell it what the separator is?

Here is some pseudo code giving an idea of what I am thinking:

-SET &ARRAY = “3,7,12,56,42”;

-SET &COUNTER = 1;
-REPEAT ARRAY_LOOP 10 TIMES

-SET &P.&COUNTER = IF &ARRAY.&COUNTER NE ‘’ THEN &ARRAY.&COUNTER ELSE ‘’;

-SET &COUNTER = &COUNTER + 1;
-ARRAY_LOOP

-TYPE &P1 (=3)
-TYPE &P2 (=7)
-TYPE &P3 (=12)
...etc


Thanks

Mark

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


WebFocus 765. iSeries v5r4
 
Posts: 175 | Location: England | Registered: April 11, 2006Report This Post
<JG>
posted
GETTOK
 
Report This Post
Platinum Member
posted Hide Post
Thanks!

Had a fiddle, any ideas why I am only seeing the first character of my elements?

-DEFAULT &P1 = ' ';
-DEFAULT &P2 = '';
-DEFAULT &P3 = '';
-DEFAULT &P4 = '';
-DEFAULT &P5 = '';

-SET &ARRAY = 'AA,BB,CC,DD,EE';
-SET &COUNTER = 1;

-REPEAT ARRAY_LOOP 5 TIMES

-SET &P.&COUNTER = GETTOK(&ARRAY, 20, &COUNTER, ',', 2, &P.&COUNTER);
-TYPE &P.&COUNTER

-SET &COUNTER = &COUNTER + 1; 
-ARRAY_LOOP


WebFocus 765. iSeries v5r4
 
Posts: 175 | Location: England | Registered: April 11, 2006Report This Post
<JG>
posted
quote:
-SET &P.&COUNTER = GETTOK(&ARRAY, 20, &COUNTER, ',', 2, &P.&COUNTER);


That should not work at all.

Try

-SET &P.&COUNTER = GETTOK('&ARRAY', 20, &COUNTER, ',', 2, 'A2');
 
Report This Post
Virtuoso
posted Hide Post
@mark66:

quote:
-DEFAULT &P1 = ' ';
-DEFAULT &P2 = '';
-DEFAULT &P3 = '';
-DEFAULT &P4 = '';
-DEFAULT &P5 = '';


In -SET, when you supply an amper variable as the final arg of a function, the length of its current value is used, and the output value will be adjusted, Procrusteanly (padded or truncated), to fit. Since you initialized the 5 receiving variables to '' or ' ', their length was set to 1, so GETTOK acted as if you explicitly coded a format of A1 as the final arg, and truncated its result accordingly.

(The minimum length of an amper var's value is 1, so '' has the same effect as ' ')

Bump the length of their default values and it works:
-DEFAULT &P1='  ', &P2='  ', &P3='  ', &P4='  ', &P5='  '

-SET &ARRAY = 'A,BB,CCC, D,EE';

-REPEAT ARRAY_LOOP FOR &P FROM 1 TO 5;

-SET &P.&P = GETTOK(&ARRAY, 20, &P, ',', 2, &P.&P);
-TYPE &P|: (&P.&P)
-ARRAY_LOOP
Output:
 1: (A )
 2: (BB)
 3: (CC)
 4: ( D)
 5: (EE)


@JG: Nope, if you quote the name of an amper var like that (in the RHS of a -SET), the name will be interpretted literally, & and all, and you wind up with
 1: (&A)
 2: (  )
 3: (  )
 4: (  )
 5: (  )
!
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
<JG>
posted
Absolutely correct, Sloppy coding.

It should have been '&ARRAY.EVAL'

The quotes are required if you have the possibility of a space in the string
 
Report This Post
Platinum Member
posted Hide Post
That's great, thank you both.

Mark


WebFocus 765. iSeries v5r4
 
Posts: 175 | Location: England | Registered: April 11, 2006Report This Post
Virtuoso
posted Hide Post
Another approach:

-SET &ARRAY = 'A,BB,CCC, D,EE,F F F';
-*
FILEDEF TEMPFILE DISK TEMPFILE.TXT
-RUN
-WRITE TEMPFILE &ARRAY
-RUN
-READ TEMPFILE,&P1,&P2,&P3,&P4,&P5,&P6
-TYPE &P1
-TYPE &P2
-TYPE &P3
-TYPE &P4
-TYPE &P5
-TYPE &P6


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Assigning parameter values based on an array?

Copyright © 1996-2020 Information Builders