2018 Sep 12 9:21 AM
Hi everybody,
I'm a newbie with dynamic programming and I need some help with an recent issue.
I'm trying to add a dynamic where clause to a select in this way,
DATA : tab(100) OCCURS 0 WITH HEADER LINE.
APPEND 'FIELD = FIELD1' TO tab. SELECT SINGLE *
FROM (p_tabla)
INTO <struc>
WHERE (tab).
But it only works with one condition, if I add more than one I get a sy-subrc = 4.
Is there another way of adding several conditions statements to a "where" clause dynamically?
Thanks a lot!!
2018 Sep 12 12:16 PM
I think you should use clike data for dynamic where condition.
Try this.
data: lv_where type text100.
Concatenate 'BUKRS = P_BUKRS' 'AND' 'BUDAT IN S_BUDAT' into lv_where separated by space.
SELECT SINGLE *
FROM (p_tabla)
INTO <estructura>
WHERE (lv_where).
2018 Sep 12 9:27 AM
1) APPEND 'FIELD TO FIELD2' TO tab. should be APPEND 'FIELD = FIELD2' TO tab.
2) if the same field is used then you should use an OR statement as an AND will prevent from finding any record
3) be sure to put values into quotation marks if the field is alphanumeric
note: it is not mandatory to do it in a table, it could be a string also
2018 Sep 12 9:34 AM
Thanks a lot for your answer, I've tried the following
APPEND 'BUKRS = P_BUKRS' TO tab.
append ' AND ' to tab.
append 'BUDAT IN S_BUDAT' to tab.
SELECT SINGLE *
FROM (p_tabla)
INTO <estructura>
WHERE (tab).
And still get the same error.... could it be for the type of the tab table?
Thank you so much
2018 Sep 12 10:12 AM
I think you should check are there data fit with your sql or not, since i dont see your dynamic have any mistake.
2018 Sep 12 12:16 PM
I think you should use clike data for dynamic where condition.
Try this.
data: lv_where type text100.
Concatenate 'BUKRS = P_BUKRS' 'AND' 'BUDAT IN S_BUDAT' into lv_where separated by space.
SELECT SINGLE *
FROM (p_tabla)
INTO <estructura>
WHERE (lv_where).
2018 Sep 12 12:25 PM
Thanks a lot, it was solved with your answer, but adding a space after the AND, like 'AND '.
2018 Sep 12 12:57 PM
DATA : tab(100) OCCURS 0 WITH HEADER LINE.
Tables with header lines have been obsolete for more than 15 years. Please do not use them.
2018 Sep 13 10:11 AM
maybe this Fm fits ur requirement
CRS_CREATE_WHERE_CONDITION