Application Development 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: 

Dynamic table in select statement

former_member556412
Active Participant
0 Kudos

Hi All,

I have a requirement where i have a select option in which the input is table name , i need to use this input in my select statement and fetch entries in the table where bname is eq to ' ' or uname eq ' '.

the challenge that i am facing is not all the tables have both the fields (uname and Bname).

Request your help on how to code the above requirements.

Thanks,

Bhanu.

7 REPLIES 7

Former Member
0 Kudos

You can use the dynamic where condition for your requirement.

Former Member
0 Kudos

not sure which version you have, if RTTS is available, you can use class CL_ABAP_TABLEDESCR to get all the fields of table then check if the field you need is there or not,

Former Member
0 Kudos

This message was moderated.

sujeet2918
Active Contributor
0 Kudos

Hello

better you use field-symbol.

first assign your table name to <FS> the use it in your select statement.

Like below.

<<linkfarm removed by moderator>>

Regards,

Sujeet Mishra

Edited by: kishan P on Jun 9, 2011 2:56 PM

Former Member
0 Kudos

Hi Bhanu,

Please use this sample code i made for your reference to solve your problem.



TABLES: dd02t.
SELECT-OPTIONS s_tabnme FOR dd02t-tabname NO INTERVALS OBLIGATORY.

SELECT field1 field3 field3
  INTO TABLE gt_master_data
  FROM s_tabnme-low
  WHERE tablefield = condition.

hope this could help. Cheers.

Michaeldahm

kiran_k8
Active Contributor
0 Kudos

Bhanu,

I don't know what exactly is your requirement but I don't see any reason why a business user enters a table name as input in the selection screen.



MANDT NAME                           TYPE NUMB SIGN OPTI   LOW    HIGH

223   ZPROGNAME                       P    0001     I        EQ    XXX      ZTABLENAME

You can maintain an entry like the above in TVARVC table and get the table name using a select query on TVARVC and then use the table as below


SELECT SINGLE * FROM (l_tabname)
           into g_wa_tab2
           WHERE quosrc   EQ g_wa_tab1-quosrc  AND
                 quotyp   EQ g_wa_tab1-quotyp  AND
                 quotno   EQ g_wa_tab1-quotno  AND
                 quotdate EQ g_wa_tab1-quotdate.

Funda is using TAVRVC to maintain the table names and determine the table based on a condition and the using the table in the select query.

Thanks,

K.Kiran.

raviahuja
Contributor
0 Kudos

Hi Bhanu,

Sorry for not providing you code but you can try the logic given below:

1. Pick all table fields of table given in select options from table DD03L.

2. Now check what fields you need to pick or which fields exist in selection condition (where) from the list you got from point 1.

3. Accordingly either write you query or create a dynamic where condition in an internal table using these fields.

4. Use field symbol to create your structure at run time.

4. Now write query something like this:

SELECT SINGLE * FROM s_tab-low into <fs> where condition[] "here condition is your internal table with dynamic conditions.

Hope this solves your query.

Ravi

Edited by: Ravi Ahuja on Jun 11, 2011 12:38 PM