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

Prepare a generic Select Query

Former Member
0 Likes
2,076

Hi ,

I need to work out a general select query which is used in multiple places. The select query uses FOR ALL ENTRIES on different internal tables but the WHERE condition remain the same. Can anyone help me in this I am writing this in a Function pool using the subroutines.

How to get the generic query,

for example I have two internal Tables

ITAB1 and ITAB2

Which are used in two different includes of the fumction pool. As the where condition is generic can I make it as a single select query using the fieldsymbols?



  SELECT bname
         name_first
        name_last
         name_text
    FROM v_usr_name
    INTO TABLE ct_user_name
    FOR ALL ENTRIES IN <fs>
     WHERE bname = <fs>-created_by OR
                  bname = <fs>-changed_by.

.

But the select query throws an error.

Regards

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,365

You can have a look at .

5 REPLIES 5
Read only

surajarafath
Contributor
0 Likes
1,365
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,366

You can have a look at .

Read only

Former Member
0 Likes
1,365

Hi,

The query is leading to a dump saying that the fields are not available in the table. But the Table is having the specified fields in the run time.

Please check the code and let me know the feasible solution.



    PERFORM fetch_user_name_data USING    gt_res_coll
                                 CHANGING lt_user_name.



FORM fetch_user_name_data  USING    ut_userid    TYPE ANY TABLE
                           CHANGING ct_user_name TYPE ty_t_user_name.


  DATA: lt_where_cond(100) OCCURS 0 WITH HEADER LINE.

  DATA:lt_coll TYPE TABLE OF ty_result_col.


  APPEND 'BNAME = UT_USERID-CREATED_BY' TO lt_where_cond.
  APPEND 'BNAME = UT_USERID-CHANGED_BY' TO lt_where_cond.

  SELECT bname
         name_first
         name_last
         name_text
    FROM v_usr_name
    INTO TABLE ct_user_name
    FOR ALL ENTRIES IN ut_userid
    WHERE (lt_where_cond).

Regards

Read only

Former Member
0 Likes
1,365

Hi,

Sory but I for got the AND Command

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,365

Hello,

APPEND 'BNAME = UT_USERID-CREATED_BY' TO lt_where_cond.
  APPEND 'BNAME = UT_USERID-CHANGED_BY' TO lt_where_cond.

This is not correct

Read the SAP documentation on how to use [dynamic WHERE clauses|http://help.sap.com/abapdocu_702/en/abenwhere_logexp_dynamic.htm].

BR,

Suhas