How to get multiple string variables from a parameter? [SOLVED]
Need help!
How can I get multiple variables from a parameter where the "OR" string is the delimiter. eg stringA is "'ADMT_SRC' OR 'ADMT_SRC_D' OR 'ADMT_TYPE' OR 'ADMT_TYP_D' OR 'AGE' OR 'AGEGRP'" I would like to get each value separated by the "OR". I am familiar with looping, but need the string functions to identify the ORs and to parse through each item. Thanks!This message has been edited. Last edited by: Gerard Cabunoc,
March 03, 2010, 04:10 PM
Dan Satchell
Take a look at the GETTOK function.
WebFOCUS 7.7.05
March 03, 2010, 04:25 PM
Francis Mariani
What's interesting about this is that to use GETTOK you need to know how many OR's there are, and I haven't found a ready-made function for that.
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 03, 2010, 04:55 PM
Waz
If you don't know how many OR's there are, then use a loop until you get nothing.
Waz...
Prod:
WebFOCUS 7.6.10/8.1.04
Upgrade:
WebFOCUS 8.2.07
OS:
Linux
Outputs:
HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!
March 03, 2010, 04:58 PM
Darin Lee
No ready made function, but you could define your own function by calculating the length of a string, then strip out the OR and recalculate the length. The difference (divide by two because OR has two characters in it) would tell you how many there are in a given string.
Then you can
-SET &PARM_CNT=1; -REPEAT PARM_LOOP WHILE &PARM_CNT LE (number of occurrences of OR); -SET &PARM&PARM_CNT.EVAL=GETTOK(&parmstring,&parmstring.LENGTH,&PARM_CNT,'OR',length of value,'Alength of value'); -SET &PARM_CNT=&PARM_CNT + 1; -PARM_LOOP
Regards,
Darin
In FOCUS since 1991 WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex WF Client: 77 on Linux w/Tomcat
March 03, 2010, 05:28 PM
Dan Satchell
The STRREP function replaces the ' OR ' strings with a single quote ('). I tried a straight GETTOK solution (without STRREP), but GETTOK didn't like having a delimiter string longer than one character. It worked, but not as expected.
-SET &VALS = '''ADMT_SRC'''|' OR '|'''ADMT_SRC_D'''|' OR '|'''ADMT_TYPE'''|' OR '|'''ADMT_TYP_D'''|' OR '|'''AGE'''|' OR '|'''AGEGRP''';
-SET &VALSX = STRREP(&VALS.LENGTH,&VALS,6,''' OR ''',1,'''',&VALS.LENGTH,'A&VALS.LENGTH');
-*
-REPEAT ENDREPEAT1 FOR &I FROM 1 TO 100
-SET &VAL.&I = GETTOK(&VALSX,&VALSX.LENGTH,&I,'''',15,'A15');
-*TYPE &VAL.&I
-IF &VAL.&I EQ '' GOTO QUITREPEAT1 ;
-ENDREPEAT1
-QUITREPEAT1
WebFOCUS 7.7.05
March 04, 2010, 09:47 AM
Francis Mariani
Function to count the occurrence of one string in another:
-*------------------------------------------------------------------------------
-* Module Name : deffunc_cntchar.fex
-* Description : DEFINE Function to count the occurrence of a character in a string
-* (Can be used in Dialogue Manager or DEFINE or COMPUTE)
-* Developed by : Francis Mariani - Francis Mariani Inc.
-* Date Developed : March 3, 2010
-*
-* How to count the occurrence of a character in a string
-*
-* CNTCHAR(string1, string2)
-* where:
-* string1 (Alphanumeric, max 600)
-* Is an alphanumeric string, or field in which the character will be counted.
-* string2 (Alphanumeric, max 10)
-* Is an alphanumeric string, or field that will be counted.
-*
-* Example: Counting occurrences of a character in a string
-*
-* -SET &STR1 = 'AAA-AAAA AAAA-W OR WW RRRR FF OR FF-FFFFF';
-* -SET &STR2 = '-';
-* -SET &COUNT = CNTCHAR(&STR1,&STR2);
-*
-* Documentation: Creating Reports With WebFOCUS Language
-* Creating Temporary Fields
-* Creating Temporary Fields Unrelated to Master Files
-*
-*------------------------------------------------------------------------------
-* Maintenance History
-*------------------------------------------------------------------------------
-* Modified by :
-* Date Modified :
-* Reason :
-* Change ID :
-*------------------------------------------------------------------------------
DEFINE FUNCTION CNTCHAR(INSTRING1/A600, INSTRING2/A10)
-* Determine the non-blank length of the input string
-* (If the string to be counted is not blank, strip the blank
-* characters in the input string before determining the length)
INSTRLEN/D4 = IF INSTRING2 EQ ' ' THEN ARGLEN(600, INSTRING1, 'D4') ELSE ARGLEN(600, STRIP(600, INSTRING1, ' ', 'A600'), 'D4');
-* Convert the string to be counted in the input string to blank
INSTRING2LEN/I4 = IF INSTRING2 EQ ' ' THEN 1 ELSE ARGLEN(10, INSTRING2, 'I4');
OUTSTR1/A600 = STRREP(600, INSTRING1, INSTRING2LEN, INSTRING2, 1, ' ', 600, 'A600');
-* Strip the blanks out of the string (the blanks represent the string to be counted)
OUTSTR2/A600 = STRIP(600, OUTSTR1, ' ', OUTSTR2);
-* Determine the length of the string without the blanks
OUTSTRLEN/D4 = ARGLEN(600, OUTSTR2, 'D4');
-* Determine the number of blanks in the string by subtracting the length of the string
-* without the blanks from the length of the input string - this gives us the count of the string
CNTCHAR/D4 = (INSTRLEN - OUTSTRLEN) / INSTRING2LEN;
END
-RUN
Save this code in a file in an Application Folder, then -INCLUDE it whenever you need it.
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 04, 2010, 10:48 AM
Dan Satchell
Francis,
Very nice job. But if I use your sample string and enter ' OR ' for the search string (to differentiate it from 'OR' characters that might be embedded elsewhere in the string), it comes back with a count of 1 instead of 2?
WebFOCUS 7.7.05
March 04, 2010, 02:57 PM
Francis Mariani
Dan, yes, the ' OR ' doesn't work - I haven't tried hard enough to make that work - I'm sure I can, but I quickly adapted a DEFINE FUNCTION that searched for a character into one that searched for a string...
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 04, 2010, 06:16 PM
j.gross
To allow for significant trailing blanks, change the parameter list -- either add a length parameter for the second string, or require the second string to include leading and trailing delimiters (e.g., '/ OR /' for the problem presented in this topic)
- Jack Gross WF through 8.1.05
March 04, 2010, 08:35 PM
Francis Mariani
Thanks Jack, I decided on the length for the second string.
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 09, 2010, 02:43 PM
Gerard Cabunoc
Really awesome... Thanks for all the help guys! This solved my problem.
WebFOCUS 7.6 Windows 2000 Server, Windows XP Output: HTML, XLS, PDF, Delimited Flat File