‎2008 Dec 17 9:44 AM
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
‎2008 Dec 17 10:37 AM
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 conditionsRegards,
Manoj Kumar P
‎2008 Dec 17 9:54 AM
‎2008 Dec 17 10:00 AM
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 conditionsRegards,
Manoj Kumar P
‎2008 Dec 17 10:13 AM
Instead of DD03L table name, I have to provide table names dynamically.
‎2008 Dec 17 10:37 AM
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 conditionsRegards,
Manoj Kumar P
‎2008 Dec 17 11:03 AM
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
‎2008 Dec 17 11:07 AM
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
‎2008 Dec 17 11:18 AM
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