2023 Aug 14 1:25 PM
Hello Experts.
I am trying to create a simple dynamic where clause with the addition of for all entries, but I am new to the concept and kind of stuck.
LOOP AT c_tab ASSIGNING FIELD-SYMBOL(<fs>).
IF i_fieldname = 'MATNR'.
SELECT COUNT( * )
FROM (select_table)
FOR ALL ENTRIES IN @i_data
WHERE matnr = @i_data-data. "Make this matnr dynamic
IF sy-subrc EQ 0 AND sy-dbcnt >= 1.
<fs>-num_entries = sy-dbcnt.
ELSE.
DELETE c_tab INDEX tabix.
ENDIF.
ELSE.
SELECT COUNT( * )
FROM (select_table)
FOR ALL ENTRIES IN @i_data
WHERE artnr = @i_data-data. "Dynamic
IF sy-subrc EQ 0 AND sy-dbcnt >= 1.
<fs>-num_entries = sy-dbcnt.
ELSE.
DELETE c_tab INDEX tabix.
ENDIF.
ENDIF.
ENDLOOP.
Basically I want to expand the matnr/artnr functionality. I wish to be able to select for any field provided by the user and for that I need a dynamic where clause. Inside i_data I hold the values the user provides. I also need to enchant that structure, so the type there is dynamic too, but I'll work on that seperately.
How can I achieve this?
Thank you
2023 Aug 14 1:43 PM
I guess you can't use a table of type ANY TABLE as you need to know the field(s) in the WHERE statement.
You could use a stringtab to achieve it:
DATA:
t_stringtab TYPE stringtab.
PARAMETERS:
p_table TYPE tablenam.
SELECT COUNT( * )
FROM (p_table)
FOR ALL ENTRIES IN @t_stringtab
WHERE matnr = @t_stringtab-table_line.
Then you just need to fill t_stringtab dynamically before performing the SELECT.
2023 Aug 14 3:26 PM
Did you already try to create such a simple text (must be character-like data object or a standard table) to use in dynamic WHERE clause ?
2023 Aug 14 4:02 PM
Methodology to develop fast:
2023 Aug 14 4:02 PM