i'm looking to take a string that looks like this:
'AAABBBCCCDDD' OR 'EEEFFFGGGHHH' OR 'IIIJJJ***LLL'
Where the 12 characters in the quotes is static (always 12) but the number of segments of 12 characters varies. I'm trying to build a dynamic where statement that will use the first 3 characters of each segement then the next 3 then the next 3 etc.
So i'm looking to create 4 variables from the above input(*do not add the OR when a single segment is entered): VARIABLE1 = 'AAA' OR 'EEE' OR 'III'; VARIABLE2 = 'BBB' OR 'FFF' OR 'JJJ'; VARIABLE3 = 'CCC' OR 'GGG' OR '***'; VARIABLE4 = 'DDD' OR 'HHH' OR 'LLL';
Use the created variables in a where statement: WHERE FIELD1 EQ &VARIABLE1; WHERE FIELD2 EQ &VARIABLE2; WHERE FIELD3 EQ &VARIABLE3; WHERE FIELD4 EQ &VARIABLE4;
Thanks ahead!!This message has been edited. Last edited by: Joe Beydoun,
version 8202M Reporting Server on Windows Server using DB2 Connect to access data from iseries.
October 06, 2011, 06:23 PM
njsden
You can use GETTOK to tokenize your string based on ' OR '.
By looping through each token, you can then get rid of the enclosing quotes (TRIM can help you there) and then use EDIT to get the first 3 characters.
Just use each resulting variable in a WHILE statement on each iteraction of the loop .. as FIELD1, FIELD2, etc. is also a "variable" field name just use a different set of &variable to make that up (as you're already looping it will be very simple to use something like:
-SET &I = 0;
TABLE FILE CAR
PRINT ....
BY ....
-REPEAT :DOSTUFF ...
-SET &I = &I + 1;
-SET &TOKEN.&I = EDIT/TRIM/GETTOK(....)
...
WHILE FIELD&I EQ &TOKEN.&I ...
...
-:DOSTUFF
ON TABLE ...
END
There is great documentation about each of those functions both with the product and at this forum so you'll likely find useful ideas.
Oh, I did not pay attention to your "groups of 3" in the initial post.
That means you'll need a slightly more elaborated version of the logic implementing a "group" variable that would increase for every 3 tokens. Your WHERE statement won't use each token directly but perhaps a "token group" variable ... sounds horrible to describe but the code should be relatively simple.
This may have solved another issue for me. As for this one, one more step of creating the Where statements using those variables.
WHERE FIELD1 EQ '&ITEM_1_1' OR '&ITEM_1_2' OR '&ITEM_1_3'; WHERE FIELD2 EQ '&ITEM_2_1' OR '&ITEM_2_2' OR '&ITEM_2_3'; WHERE FIELD3 EQ '&ITEM_3_1' OR '&ITEM_3_2' OR '&ITEM_3_3'; WHERE FIELD4 EQ '&ITEM_4_1' OR '&ITEM_4_2' OR '&ITEM_4_3';
version 8202M Reporting Server on Windows Server using DB2 Connect to access data from iseries.
October 09, 2011, 05:35 PM
Waz
quote:
one more step of creating the Where statements using those variables
The WHERE Clauses will be the easy bit.
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!
October 10, 2011, 04:07 PM
jfr99
Here's another version of the example Waz started. This creates the where statements based on the input string.