Application Development and Automation 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: 
Read only

dynamically select data with 20 input parameters

Former Member
0 Likes
521

Hi Experts,

Now i have created a subscreen with more than 20 fields on it. these fields are defined by parameters, not select options. user can input any fileds for these input parameters.

So now i should write codes to select data from database according the user input. Is there any easy way for me to write it? I heard about dynamically SQLs, but i don't know how to use it.

Thanks a lot!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
478

Hi Wei,

You Can try where clause for your select query like "where (cond_syntax)" . Here cond_syntax will be data variable of type string. You can use If .. to check values of your parameters and accordingly use concatenate statemnt to write dynamic condition for where cluase of your query.

Hope this will answer your question.

Thanks and Regards,

Vaibhav Pendse

3 REPLIES 3
Read only

Sandra_Rossi
Active Contributor
0 Likes
478

you forgot to mention why you needed dynamic SQL : I guess that when user lets a field blank, you must not perform selection on it.

The easiest is ( FIELD1 = P_FIELD1 OR FIELD1 = space ) AND ( FIELD2 = P_FIELD2 OR FIELD2 = space ) AND etc. Even if it seems repetitive, I advise you to keep the SQL static instead of dynamic, because in this latter case, I think the code will be a little bit less clear.

Of course, if you argue that there are other requirements, then maybe it's worth re-evaluating the solution.

If you need more information, just look at ABAP examples in your system (SE38, Environment, Examples, ABAP examples -> ... -> Dynamic conditions)

Read only

Former Member
0 Likes
478

hai fang,

declare an internal table with soem fixed legth say 70 chars

then what ever u want to select write in line and append to internal table

and then use select query as below

select (itab) from table ( table) where condtions.

itab contains all the fields which u wan tto select

m.a

Read only

Former Member
0 Likes
479

Hi Wei,

You Can try where clause for your select query like "where (cond_syntax)" . Here cond_syntax will be data variable of type string. You can use If .. to check values of your parameters and accordingly use concatenate statemnt to write dynamic condition for where cluase of your query.

Hope this will answer your question.

Thanks and Regards,

Vaibhav Pendse