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

define internal table depending on parameter

0 Likes
630

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!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
603

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..

5 REPLIES 5
Read only

Former Member
0 Likes
603

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

Read only

Former Member
0 Likes
603

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

Read only

Former Member
0 Likes
603

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

Read only

Former Member
0 Likes
604

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..

Read only

0 Likes
603

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!