Skip to Content
author's profile photo Former Member
Former Member

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

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Jul 18, 2016 at 01: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 18, 2016 at 01: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 18, 2016 at 12: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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.