‎2007 Mar 13 1:22 PM
Hello,
does anybody know how internal tables can be defined when tablename is passed as parameter ?
I have p_table and want to define an internal table depending on its value (e.g. KNA1, MARA, LFA1 ) dynamically, so for example if p_table= MARA
DATA:
l_tab_table TYPE STANDARD TABLE OF MARA.
l_str_table TYPE MARA.
Has anybody done this before ?
Thank you!
‎2007 Mar 13 1:37 PM
HI Leider..
please have a look at
This will give you a clear Idea..
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
If it helps reward with points...
Regards
Rk..
‎2007 Mar 13 1:25 PM
Hi Clemens,
Follow this example:
PARAMETERS: dbtab(10) TYPE c,
rows TYPE i DEFAULT 100.
DATA dref TYPE REF TO data.
FIELD-SYMBOLS: TYPE ANY TABLE,
<wa> TYPE ANY,
TYPE ANY.
TRY.
CREATE DATA dref TYPE STANDARD TABLE OF (dbtab)
WITH NON-UNIQUE DEFAULT KEY.
ASSIGN dref->* TO .
SELECT *
FROM (dbtab) UP TO rows ROWS
INTO TABLE .
LOOP AT ASSIGNING <wa>.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <wa> TO .
IF sy-subrc = 0.
WRITE / .
ELSE.
EXIT.
ENDIF.
ENDDO.
ULINE.
ENDLOOP.
CATCH cx_sy_create_data_error.
WRITE 'Wrong Database!'.
ENDTRY.
Regards,
Ravi
‎2007 Mar 13 1:28 PM
Hi
U have to use field-symbols:
PARAMETERS: P_TABLE(30).
DATA: DYN_TAB TYPE REF TO DATA.
FIELD-SYMBOLS: <TAB> TYPE TABLE.
CREATE DATA DYN_TAB TYPE TABLE OF (P_TABLE).
ASSIGN DYN_TAB->* TO <TAB>.
I believe the option CREATE DATA ... TYPE TABLE is available from release 4.7.
If you use a lower release you have to use the method
CREATE_DYNAMIC_TABLE of class CL_ALV_TABLE_CREATE:
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = P_TABLE
CHANGING
CT_FIELDCAT = GT_FIELDCAT.
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = gt_fieldcat
importing ep_table = DYN_TAB.
ASSIGN DYN_TAB->* TO <TAB>.Max
‎2007 Mar 13 1:35 PM
Hi,
As of my knowledge , the first statements that are going to get executed are "DATA" statements only.
So regarding your requirement the system has to execute the PARAMETER statement first and then the DATA statement which is not going to happen generally.
Regards,
Balakrishna.N
‎2007 Mar 13 1:37 PM
HI Leider..
please have a look at
This will give you a clear Idea..
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
If it helps reward with points...
Regards
Rk..
‎2007 Mar 13 3:06 PM
Follow up:
Is there any sample or approach of how i can display the table columns ( that would be selectable ) after i selected the table via the parameter ? that way i would be able to just view certain columns of the specified table.
Thanks in advance!