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: 

How to create a range table dynamically to be used in Dynamic select query?

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

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.

4 REPLIES 4

former_member196331
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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.

Sandra_Rossi
Active Contributor
0 Kudos

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.

0 Kudos

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.