2007 Dec 27 11:25 AM
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.
2007 Dec 27 11:32 AM
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
2007 Dec 27 11:32 AM
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
2007 Dec 27 11:36 AM
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
2007 Dec 27 11:43 AM
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.