Application Development and Automation 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: 
Read only

SELECT command with variables

Former Member
0 Likes
333

Hi,

I have a number of table-variables and field-variables coming from a dialog. I can easily concatenate those into constructs like [table]~[field].

Following, I have a SELECT statement that simply fetches all those fields from n different DB tables which are for that purpose connected, currently using JOINs.

What I need to find now is a way to use those construct-variables in the SELECT statement, as simple as that. The idea is that I will, going forward, concatenate those into a field_list and put that into the command since that way I will be independent of how many fields there might be.

Can anybody give me a hint on how to do that? I haven't yet found out.

Thanks a lot!

Best regards,

Sapperdapper

1 REPLY 1
Read only

Azeemquadri
Contributor
0 Likes
294

Hi - Below section of code could be helpful. Please check.

DATA: lv_sel_list TYPE TABLE OF edpline," Dynamic sel list
         lv_xref TYPE REF TO cx_dynamic_check,
         lv_message_txt TYPE string,
         lv_whereclause TYPE string.

   CONSTANTS : lc_x(5) VALUE  ' ''X'' '.

*For each entry in zbc_dbtrack select count and groupby fieldname
   LOOP AT i_dbtrack INTO w_dbtrack.

     APPEND 'count(*) as count' TO lv_sel_list.
     APPEND w_dbtrack-zgbfield  TO lv_sel_list.
     IF w_dbtrack-zgbfield IS NOT INITIAL.
       TRY.

*Dynamic Count and groupby field name
           SELECT (lv_sel_list)
           FROM (w_dbtrack-ztable)
           INTO TABLE i_fieldcount
           GROUP BY (w_dbtrack-zgbfield).

*Get count of flagged for deletion data
           IF w_dbtrack-zdelfield IS NOT INITIAL.

*Dynamic where clause
             CONCATENATE w_dbtrack-zdelfield '=' lc_x
             INTO lv_whereclause
             SEPARATED BY space.

             SELECT (lv_sel_list)
              FROM (w_dbtrack-ztable)
              INTO TABLE i_delfieldcount
              WHERE (lv_whereclause)
              GROUP BY (w_dbtrack-zgbfield).

           ENDIF.

*Catch dynamic sql errors
         CATCH cx_sy_dynamic_osql_error
      cx_sy_create_data_error INTO lv_xref.

           lv_message_txt = lv_xref->get_text( ).

           MESSAGE lv_message_txt TYPE 'E'.


       ENDTRY.