‎2009 Jul 17 1:16 PM
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
‎2009 Jul 17 1:46 PM
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.
‎2009 Jul 17 1:47 PM
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> .
‎2009 Jul 19 11:25 AM
Also please make sure that gi_vend is not empty when you get to your select for all entries in gi_vend...