Focal Point
[SOLVED] Filtering in maitain

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

February 01, 2013, 03:10 AM
Shankar
[SOLVED] Filtering in maitain
Hi,
I have comma separated values in a variable.I want to use it in WHERE clause to filter records against a column in databse table as we do it using IN operator in Oracle. As we do not have IN in maintain, How can we achieve this requirement.
E.g. Suppose variable contains value 'A,AB,ABC' . Now I have to use these values in WHERE clause as
 
WHERE [coumn name] eq 'A' and [coumn name] eq 'AB' and [coumn name] eq 'ABC';

There can be any number of values in variable. Please suggest a way to achive this in maintain.

Thanks in advance.

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


WF 8.1.04,Windows 7,
DataBase: Oracle 11g,Output :Excel,PDF,HTML
February 01, 2013, 04:55 AM
FrankDutch
I am not a SQL specialist, but I wonder if this where clause would work.
The column name can not be A and B and AB at the same time.
I would suggest to change the AND into OR




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

February 01, 2013, 05:09 AM
GamP
1. get it to work in TABLE first, not Maintain.
2. when it works call tha table fex from the maintain giving it the parameter list and catching the result in a stack. Be sure the stack contains at least the exact fields table will return.
Done!


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
February 01, 2013, 05:24 AM
Shankar
Hi Frank,
Yes you are right. My mistake.
But can you please tell me the way to convert the comma separated string into WHERE clause string. That will really help.

Thanks.


WF 8.1.04,Windows 7,
DataBase: Oracle 11g,Output :Excel,PDF,HTML
February 03, 2013, 08:23 AM
Shankar
Hi GamP,
In my case it would require lot of code restructuring and that would be very costly affair for me as this is just a minor enhancement in an existing application.
Is there any way to handle it in maintain easily as i have to deliver it urgently and i can't take more time for this.Please help.

Thanks.


WF 8.1.04,Windows 7,
DataBase: Oracle 11g,Output :Excel,PDF,HTML
February 04, 2013, 08:47 AM
John_Edwards
GamP's suggestion is the right way to go and it's not terribly difficult to write.

1. Write a traditional FOCUS routine that performs your select.

TABLE FILE X
PRINT A
B
C
WHERE C IN (&1);
ON TABLE PCHOLD
END

That &1 is your list of values, your string 'A','AB','ABC'. It will be the variable you call the routing with. Let's call this routing select_records.fex.

2. Exchange your Maintain select for the call to the routine.

-* for all next x.a into StkRecords where x.c EQ 'a';
infer x.a into StkRecords;
EXEC select_records
from string_of_values
into StkRecords;

3. At this point you have StkRecords filled with your values. The amper variables in your Focexec are positional -- that is the first one sent is &1, the second &2 and so on. So string_of_values arrives in &1. Your INTO stack receives the results of the select.

It's just that simple, and using FOCUS routines for your selections opens up your Maintain code to all the power of a focexec. Joins, hold files, the works. Seriously, this is the fastest, easiest way to do this. You could put together a loop in Maintain and select the values one at a time, but that's much more work than what GamP put you onto in his first post.

J.



February 04, 2013, 09:29 AM
Maintain Wizard
Here is the Maintain solution. Perform a loop and use MNTGETTOK to get the value before the comma each time through the loop. Then use the value in a NEXT with WHERE statement to add the values from the database into the stack.

MAINTAIN FILE MOVIES
MODULE IMPORT(MNTUWS)
COMPUTE STRING/A0 = "ROOF,WIND,TOP";
COMPUTE I/I3=1;
REPEAT WHILE VAL NE ''
COMPUTE VAL/A0=MNTGETTOK(STRING,",",I);
REPOSITION MOVIECODE
FOR ALL NEXT MOVIECODE TITLE INTO STK(STK.FOCCOUNT+1)
WHERE TITLE CONTAINS TRIM(VAL)
COMPUTE I=I+1;
ENDREPEAT
END

Mark
February 05, 2013, 11:33 PM
Shankar
Thanks a lot Mark. It worked for me.

Warm Regards.


WF 8.1.04,Windows 7,
DataBase: Oracle 11g,Output :Excel,PDF,HTML