‎2009 Aug 30 8:35 AM
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!
‎2009 Aug 31 11:30 AM
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
‎2009 Aug 30 10:56 AM
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)
‎2009 Aug 31 4:14 AM
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
‎2009 Aug 31 11:30 AM
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