09-29-2008 7:30 AM
Hi experts,
I have a condition where i need to fetch the data from the DB tables based on user entries but
here there are 11 search parameters.
and i cant write IF condition for all the combinations of that 11 parameters because it will come upto 121 IF conditions..
so please can anyone help me out through this.
Even if you have a slightest idea you can share it.
Regrds,
Syed
09-29-2008 9:15 AM
Hi
This dynamic select query can be writteb based on tables .
Suppose if you want to retrieve data from two tables ztable1 and ztable2.
You have to declare two separate string for those two tables and you have to mention the conditions in that
string and you have to write in where cindition that string.
suppose you are retriving data from ztable1 and in that suppose 5 fields are there leasy f1,f2,f3,f4,f5.then
data str type string.
if str is not initial.
str = 'f1 eq f1'.
endif.
if f2 is not initial.
if str is not initial.
concatenate str 'and' into str separated by space.
endif.
concatenate str 'f2 eq f2' into str separated by space.
endif.
like this you have to write for f3,f4,f5.
after
select * from ztable1 where (str).
regards
venkat
09-29-2008 7:33 AM
hi,
CALL FUNCTION 'SE16N_START'
EXPORTING
I_DISPLAY = 'X' .
check thi FM, it will beusefull to fetch teh data from DB tables.
Regards,
Deepthi.
09-29-2008 7:34 AM
Hi
The bet way is to put the common conditions in all 11 in where clause and then filter data based on condition.
Aditya
09-29-2008 7:34 AM
any reason why can't you mention the "11 search pramaters" in the where conditions of the SELECT?
09-29-2008 8:26 AM
Hi,
i have to fectch data from more than one DB table and so i cant apply all eleven parametrs in a single select query and from those 11 paramters its not sure that the user will have to enter all 11 parameters .. user can enter any number of parameters so i need to check out if the parameters has any value or not . then i need to write the query for the parametrs which the user has entered.
Regards,
Syed
09-29-2008 8:39 AM
if you want real help: can you provide more details? i. e. what are the search parameters the user enters? (parameters, select-options, or something else?). from what tables do you want to select the data?
09-29-2008 8:44 AM
Hi,
These are paramters only.
and i am fecthing data from PA0002 and PA0105 and PA0001 tables.
regards,
Syed
09-29-2008 8:51 AM
Ok, we are getting closer...
so what is the problem with coding like this:
SELECT ...
FROM PA0001
INTO ...
WHERE ... EQ parameter1
AND/ ... EQ parameter2
...
09-29-2008 9:06 AM
Better thing is declare all of them as select-options with out extension and intervals.
The advantage is even if no value the select query will not stop.
For dynamic selection you can try like below:
1.Declare a Ranges varianle.
2.Write if conditions and use "concatenate statement"
ex:
if <condition>
concatenate ' ( ProdEffDate le ''' komk-prsdt ''' )'
into exdate-sel.
append exdate.
endif.
where as exdate is a ranges variable.
3. Append everything to the same ranges variable based on the if condition.
4. Now at last you can have a single select statement which will be even good for performance.
09-29-2008 9:08 AM
But i cant write like that in where clause until i get to know which paramters has the user entered.
for that i need to write combinations for the parametrs which the user has enterd and then only i can write those parametrs uin where clause.
regards,
Syed
09-29-2008 9:14 AM
use the FM
"dynpro_read" to get the values from the selection screen.
But there should be some logic based on which you can always use if conditions .
09-29-2008 9:14 AM
>
> But i cant write like that in where clause until i get to know which paramters has the user entered.
> for that i need to write combinations for the parametrs which the user has enterd and then only i can write those parametrs uin where clause.
>
>
> regards,
> Syed
does it mean, if the user enters for example for Company Code: 1000, than only personal numbers inside Company Code 1000 has to be selected? BUT if the user does not enter anything for the Company Code, than the field will be irrelevant in the selection (that means any Company Code can be selected)?
09-29-2008 9:09 AM
Hi,
Another idea ...
store the 11 parameters in a internal table and use for all entries to fetch the data from DB.
Regards,
Ram
09-29-2008 9:19 AM
Yes, The idea of appending all select-options-low to ranges variable and using a single select is also good( as suggested by Ram).
09-29-2008 9:15 AM
Hi
This dynamic select query can be writteb based on tables .
Suppose if you want to retrieve data from two tables ztable1 and ztable2.
You have to declare two separate string for those two tables and you have to mention the conditions in that
string and you have to write in where cindition that string.
suppose you are retriving data from ztable1 and in that suppose 5 fields are there leasy f1,f2,f3,f4,f5.then
data str type string.
if str is not initial.
str = 'f1 eq f1'.
endif.
if f2 is not initial.
if str is not initial.
concatenate str 'and' into str separated by space.
endif.
concatenate str 'f2 eq f2' into str separated by space.
endif.
like this you have to write for f3,f4,f5.
after
select * from ztable1 where (str).
regards
venkat
10-01-2008 8:26 AM
Hi all,
Thanks for your responses and ideas.. i have got the soln for my query.
Regards,
Syed