Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic selection

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

15 REPLIES 15

Former Member
0 Kudos

hi,

CALL FUNCTION 'SE16N_START'

EXPORTING

I_DISPLAY = 'X' .

check thi FM, it will beusefull to fetch teh data from DB tables.

Regards,

Deepthi.

Former Member
0 Kudos

Hi

The bet way is to put the common conditions in all 11 in where clause and then filter data based on condition.

Aditya

JozsefSzikszai
Active Contributor
0 Kudos

any reason why can't you mention the "11 search pramaters" in the where conditions of the SELECT?

Former Member
0 Kudos

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

0 Kudos

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?

Former Member
0 Kudos

Hi,

These are paramters only.

and i am fecthing data from PA0002 and PA0105 and PA0001 tables.

regards,

Syed

0 Kudos

Ok, we are getting closer...

so what is the problem with coding like this:

SELECT ...

FROM PA0001

INTO ...

WHERE ... EQ parameter1

AND/ ... EQ parameter2

...

0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

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 .

0 Kudos

>

> 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)?

Former Member
0 Kudos

Hi,

Another idea ...

store the 11 parameters in a internal table and use for all entries to fetch the data from DB.

Regards,

Ram

0 Kudos

Yes, The idea of appending all select-options-low to ranges variable and using a single select is also good( as suggested by Ram).

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi all,

Thanks for your responses and ideas.. i have got the soln for my query.

Regards,

Syed