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

Dynamic selection query

former_member434229
Active Participant
0 Likes
1,224

Hi,

I need to write a dynamic select query based on the user's selection.

On Selection screen select options provided of fields like Company code, Plant and Sales Organazation.

Now, I have find out how many tables having field company code(If User enters data in this field) from DD03L table. And, based on the data retrieved, how many entries does exists in those tables matching user criteria.

Same thing for Plant and Sales Organization.

Thanks in Advance.

Nitin

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
939

Hi Nitin,

you can try this way

select (w_field1) 
          (w_field2)
          from (w_table) "<== like this
          into corresponding fields of table itab
          where "Your conditions

Regards,

Manoj Kumar P

7 REPLIES 7
Read only

Former Member
0 Likes
939

Hi,

Use Field Symbols.

Regrads,

rahul

Read only

Former Member
0 Likes
939

Hi,

You can write select query using variable as follows:

select (w_field1) 
          (w_field2)
          from DD03
          into corresponding fields of table itab
          where "Your conditions

Regards,

Manoj Kumar P

Read only

0 Likes
939

Instead of DD03L table name, I have to provide table names dynamically.

Read only

Former Member
0 Likes
940

Hi Nitin,

you can try this way

select (w_field1) 
          (w_field2)
          from (w_table) "<== like this
          into corresponding fields of table itab
          where "Your conditions

Regards,

Manoj Kumar P

Read only

0 Likes
939

Hi Manoj,

Thanks for the reply but I already checked this out. The error message I get is 'w_table is not defined in ABAP Dictionary as a table, projection view or database view'.

Regards,

Nitin

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
939

Hello Nitin,

I was trying to write a code for your requirement ) I was got this short dump. Basically you need to capture this SQL exception.


DATA:
  it_dd03l TYPE STANDARD TABLE OF dd03l,
  wa_dd03l TYPE dd03l,
  v_tabname TYPE string,
  v_tabname1 TYPE tabname.

SELECT * FROM dd03l INTO TABLE it_dd03l
WHERE fieldname = 'BUKRS'.

IF sy-subrc = 0.
  LOOP AT it_dd03l INTO wa_dd03l.
    v_tabname = wa_dd03l-tabname.

    TRY.
        SELECT COUNT(*)
        FROM (v_tabname)
        WHERE bukrs = p_bukrs.
        IF sy-subrc = 0.
          v_tabname1 = v_tabname.
          WRITE: / v_tabname1, 35 sy-dbcnt.
        ENDIF.
      CATCH cx_sy_dynamic_osql_semantics.
    ENDTRY.

  ENDLOOP.

ENDIF.

Trust me, it will take hell lot of time to execute this report :-((

BR,

Suhas

Edited by: Suhas Saha on Dec 17, 2008 12:08 PM

Read only

0 Likes
939

Thanks Suhas,

It solved my problem.

I am also aware of the execution time this report is going to take.... but requirement is like this only.

Regards,

Nitin