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: 

Problem in Dynamic where clause

Former Member
0 Kudos
866

Hi,

I am having an issue with using dynamic where clause in a select statement.

The query that i want to emulate is:

SELECT * FROM (p_table)

INTO TABLE <dyn_table>

WHERE spras IN s_field1.

(s_field1 is a select-option)

I am trying to write a query like

SELECT * FROM (p_table)

INTO TABLE <dyn_table>

WHERE (ITAB).

ITAB is an internal table with the text 'spras IN s_field1' already present.

when i run the report, the query with the dynamic where clause gives a dump.

However, if i modify the contents of ITAB to have the text 'spras = 'EN'', the query executes successfully.

Can anyone please let me know how to write a dynamic where clause for select-options???

Cheers,

Raghav.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
308

Hi,

To specify a condition dynamically, use:

SELECT ... WHERE (<itab>) ...

where <itab> is an internal table with line type C and maximum length 72 characters. All of the conditions listed above except for selection tables, can be written into the lines of <itab>. However, you may only use literals, and not the names of data objects. The internal table can also be left empty.

If you only want to specify a part of the condition dynamically, use:

SELECT ... WHERE <cond> AND (<itab>) ...

You cannot link a static and a dynamic condition using OR.

You may only use dynamic conditions in the WHERE clause of the SELECT statement.

Regards,

Hari

3 REPLIES 3

Former Member
0 Kudos
309

Hi,

To specify a condition dynamically, use:

SELECT ... WHERE (<itab>) ...

where <itab> is an internal table with line type C and maximum length 72 characters. All of the conditions listed above except for selection tables, can be written into the lines of <itab>. However, you may only use literals, and not the names of data objects. The internal table can also be left empty.

If you only want to specify a part of the condition dynamically, use:

SELECT ... WHERE <cond> AND (<itab>) ...

You cannot link a static and a dynamic condition using OR.

You may only use dynamic conditions in the WHERE clause of the SELECT statement.

Regards,

Hari

Former Member
0 Kudos
308

Hi,

Check the following example:

DATA: COND(72) TYPE C,

ITAB LIKE TABLE OF COND.

PARAMETERS: CITY1(10) TYPE C, CITY2(10) TYPE C.

DATA WA TYPE SPFLI-CITYFROM.

CONCATENATE 'CITYFROM = ''' CITY1 '''' INTO COND.

APPEND COND TO ITAB.

CONCATENATE 'OR CITYFROM = ''' CITY2 '''' INTO COND.

APPEND COND TO ITAB.

CONCATENATE 'OR CITYFROM = ''' 'BERLIN' '''' INTO COND.

APPEND COND TO ITAB.

LOOP AT ITAB INTO COND.

WRITE COND.

ENDLOOP.

SKIP.

SELECT CITYFROM

INTO WA

FROM SPFLI

WHERE (ITAB).

WRITE / WA.

ENDSELECT.

Regards,

Bhaskar

Former Member
0 Kudos
308

The syntax of the select statement is false.

if u already have spras in Itab then you need to write inside the loop .

loop at itab into wa_itab.

SELECT *

FROM mara

INTO ktab

WHERE matnr = wa_itab -matnr.

endloop.

Reward if useful.