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 define Range Tables dynamically

Former Member
0 Kudos

Hi,

How can I define ranges dynamic for further using in the Select Statement?

Cause my Code is like this; But It comes to Short-Dump

lt_typnr is Range Table.

IF typnr IS SUPPLIED.

CONCATENATE 'TYPNR IN' lt_typnr INTO

source_line separated by space.

APPEND source_line TO where_tab.

ENDIF.

SELECT * FROM ZTYP_TABLE

INTO CORRESPONDING FIELDS OF TABLE lt_header

WHERE (where_tab).

Greetings

Besi

1 ACCEPTED SOLUTION

Former Member
0 Kudos

In case Anand's solution does not work, if the range table is empty, it will have no impact on the selection. So you could code:

IF typnr IS SUPPLIED.
ELSE.
  REFRESH lt_typnr[].
ENDIF.

SELECT * FROM ZTYP_TABLE
  INTO CORRESPONDING FIELDS OF TABLE lt_header
  WHERE typnr IN lt_typnr.

6 REPLIES 6

andreas_mann3
Active Contributor
0 Kudos

Hi besi,

using sel_opt's is'nt possible in a dynamic wheretab

->

1) so you've to dissolve your sel_opt

2) or you've to use GENERATE SUBROUTINE POOL (F1)

regards Andreas

FredericGirod
Active Contributor
0 Kudos

That's not fit to your question, but have a look at the function module :

FREE_SELECTIONS_INIT

FREE_SELECTIONS_DIALOG

FREE_SELECTIONS_RANGE_2_WHERE

Regards

Frédéric.

Former Member
0 Kudos

Hi Besi,

Could you please see if this one works?

IF typnr IS SUPPLIED.

CONCATENATE 'TYPNR IN'

'LT_TYPNR'

INTO source_line separated by space.

APPEND source_line TO where_tab.

ENDIF.

The value LT_TYPNR has to be supplied as a <i>literal</i>.

Here in your case, you have given it as a variable. Hence the dump.

Please reward the points and close the thread if this solution is satisfactory.

Regards,

Anand Mandalika.

Former Member
0 Kudos

In case Anand's solution does not work, if the range table is empty, it will have no impact on the selection. So you could code:

IF typnr IS SUPPLIED.
ELSE.
  REFRESH lt_typnr[].
ENDIF.

SELECT * FROM ZTYP_TABLE
  INTO CORRESPONDING FIELDS OF TABLE lt_header
  WHERE typnr IN lt_typnr.

0 Kudos

Also,

in Release 4.6 it is not possible to build a where clause with variables.

So

field = 'A' would work

while

field = g_var would not.

I am not sure in which Release this feature has been introduced.

Christian

Former Member
0 Kudos

Hi Developers,

I was on Vacation. Sorry for lately Points.

Thank You for all

Bye

Besi