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

Problem with SELECT using variable internal table

former_member198268
Participant
0 Likes
571

Hi,

I have a question regarding the usage of a variable table name and variable internal table in the SELECT statement.

Following is the code I have used:

DATA: l_tabname TYPE tabname,

l_dref TYPE REF TO data.

FIELD-SYMBOLS:<li_itab> TYPE ANY TABLE.

l_tabname = gwa_dyn-table.

CREATE DATA l_dref TYPE TABLE OF (l_tabname).

ASSIGN l_dref TO <li_itab>.

SELECT (gwa_dyn-field)

FROM (gwa_dyn-table)

INTO CORRESPONDING FIELDS OF TABLE <li_itab>

FOR ALL ENTRIES IN gi_vend

WHERE matnr EQ gi_mara-matnr.

IF sy-subrc EQ 0.

*Now to map the right internal table I use the CASE statement

CASE l_tabname.

WHEN 'MARA'.

gi_mara[] = <li_itab>.

WHEN 'MAKT'.

gi_makt[] = <li_itab>.

WHEN..

ENDCASE.

Now, my question is ;Is there a way if I can get rid of the CASE statement inorder that the internal table name in the SELECT statement can be fetched dynamically?'.

Please advice.

Regards,

Sophia Xavier

3 REPLIES 3
Read only

Former Member
0 Likes
535

Firstly, you can get the components of the dynamic table you are specifying using RTTI.

You can make use of the class CL_ABAP_TABLEDESCR and method DESCRIBE_BY_NAME

This will give you a list of COMPONENTS (Fields in your dynamic table)

Try to make use of Class CL_ALV_TABLE_CREATE and method CREATE_DYNAMIC_TABLE

finally, select data into this dynamic table

Hope this helps.

Read only

Pawan_Kesari
Active Contributor
0 Likes
535
DATA: l_tabname TYPE tabname .

DATA : gi_mara TYPE TABLE OF mara ,
       gi_makt TYPE TABLE OF makt .

l_tabname = 'MARA' .

DATA         : l_dref TYPE REF TO data.
FIELD-SYMBOLS: <li_itab> TYPE ANY TABLE.
CREATE DATA l_dref TYPE TABLE OF (l_tabname).
ASSIGN l_dref->* TO <li_itab>  .


*Define another field symbol and asign it to right internal table 
*here naming of internal table is important
FIELD-SYMBOLS : <fs_tab> TYPE ANY TABLE .
CONCATENATE 'GI_' l_tabname INTO l_tabname .
ASSIGN (l_tabname) TO <fs_tab>.

<fs_tab> = <li_itab> .
Read only

0 Likes
535

Also please make sure that gi_vend is not empty when you get to your select for all entries in gi_vend...