07-18-2016 12:49 PM
Hello Experts,
I am facing an issue in creating the range table which can be used in a dynamic select query.
E.g. As below
loop at itab into wa.
lv_fieldname = wa-fieldname.
Now, have to create range table for this field which can be known in run time.
append this range table to final <condition> table till the loop ends.
endloop.
Now write a select query :
Select * from <dbtable> into <itab_data> where <(condition)>.
Could someone please guide me on how to proceed with this..or any better ways please...
Thanks in advance.
Vinay.
07-18-2016 2:52 PM
You could use RTTC (same answer as Armin (CL_ABAP_TYPEDESCR) ; search RTTC in the forum/abap doc), but I think it will be simpler in your case to use the function module FREE_SELECTIONS_RANGE_2_WHERE as it's also supported by SAP.
07-18-2016 1:45 PM
Suppose it_lifnr is the table fetching data from the Query.
Now. s_lifnr is the Range. Then loop from the Internal table then append the Range,
Then it will create the Range.
LOOP AT it_lifnr.
s_lifnr-low = it_lifnr-lifnr.
s_lifnr-sign = 'I'.
s_lifnr-option = 'EQ'.
APPEND s_lifnr.
CLEAR : s_lifnr, it_lifnr.
ENDLOOP.
07-18-2016 2:38 PM
You can use e.g. the type SELOPT, but it's limited to a fixed number of chars for LOW and HIGH. Maybe, it's possible to create a range type with STRING as type for LOW and HIGH; I've never tried.
If you really want to create the range type dynamically, you should get familiar with CL_ABAP_TYPEDESCR and corresponding classes.
07-18-2016 2:52 PM
You could use RTTC (same answer as Armin (CL_ABAP_TYPEDESCR) ; search RTTC in the forum/abap doc), but I think it will be simpler in your case to use the function module FREE_SELECTIONS_RANGE_2_WHERE as it's also supported by SAP.
07-20-2016 6:27 AM
Thanks Rossi.
Not much familiar with RTTC, so moved on to FREE_SELECTIONS_RANGE_2_WHERE and it fits perfect for our requirement.
Thanks a lot again.
Regards,
Vinay.