Skip to Content
0
Aug 14, 2023 at 12:25 PM

Dynamic where clause with for all entries?

115 Views

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