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

Former Member
0 Kudos

Hi, I want to creat an Internal table which should take the rows of an existing unternal table as columns of the new table and viceversa. The existing Internal table is as follows:

TIME1 TIME2 TIME3 TIME4 TLT TOT TST

WC1 xxx xxx xxx xxx xxx xxx xxx

WC2 xxx xxx xxx xxx xxx xxx xxx

WC3 xxx xxx xxx xxx xxx xxx xxx

Please help me out.

5 REPLIES 5

Former Member
0 Kudos

Sagar,

Could you please explain in detail with the structure of the existing internal table?

This weblog can show you how to create a internal table at runtime.

/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically

You can also do

CREATE DATA table TYPE mara.

Regards,

Ravi

hymavathi_oruganti
Active Contributor
0 Kudos

for creating dynmic int table follow the following steps.

example:

data: begin of itab occurs 0,

sno type i,

sname(10),

marks type i,

end of itab.

Now my requirement is like below, marks should become headings of alv grid.

we donno how many marks will come. so , the requirement is dynamic.

sno| sname| 80 | 90 | 78 | 77...........

build a LVC fieldcat like below.

ls_fieldcat-fieldname = 'SNO'.

ls_fieldcat-col_text = 'SNO'.

append ls_fieldcat to lt_fieldcat.

ls_fieldcat-fieldname = 'SNAME'.

ls_fieldcat-col_text = 'SNAME'.

append ls_fieldcat to lt_fieldcat.

*******for marks*********

loop at itab

ls_fieldcat-fieldname = itab-marks.

ls_fieldcat-col_text = itab-marks.

append ls_fieldcat to lt_fieldcat.

endloop.

**************

2. NOW THE FIELDCAT IS UILT. WE HAVE TO BUILD AN INTERNAL TABLE FROM THE FIELDCAT.

DATA: DREF TYPE REF TO DATA,WA_REF TYPE REF TO DATA.

FIELD-SYMBOLS: <TEMP_TAB> TYPE TABLE, <TEMP_WA> TYPE ANY.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_LVCFIELDCAT

IMPORTING

EP_TABLE = DREF.

ASSIGN dref->* TO <TEMP_TAB>.

<temp_tab> is the dynamic internal table built from fieldcat.

3. NOW FILL THE DYNAMIC INTERNAL TABLE.

CREATE DATA WA_REF LIKE LINE OF <TEMP_TAB>.

ASSIGN WA_REF->* TO <TEMP_WA>.

LOOP AT ITAB.

MOVE-CORRESPONDING ITAB TO <TEMP_WA>.

APPEND <TEMP_WA> TO <TEMP_TAB>.

CLEAR IT_ITAB.

ENDLOOP.

ENDFORM. " FILL_DYN_TAB

0 Kudos

Hi Hyma, I appreciate you help in this. But my requirement is:

WC1 WC2 WC3

TIME1 XXX XXX XXX

TIME2 XXX XXX XXX

TIME3 XXX XXX XXX

TIME4 XXX XXX XXX

TLT XXX XXX XXX

TOT XXX XXX XXX

TST XXX XXX XXX

Please see my first mail to know about the original internal table. Thanks.

0 Kudos

Hi

You can try to do something like this:

DATA: BEGIN OF itab_in OCCURS 0,

field1,

field2,

field3,

fieldn,

END OF itab_in.

DATA: index(3) TYPE n.

DATA: t_lvc TYPE lvc_t_fcat,

w_lvc TYPE lvc_s_fcat.

FIELD-SYMBOLS: <new_itab> TYPE table,

<wa_itab> TYPE table.

DATA: new_tab TYPE REF TO data,

wa_tab TYPE REF TO data.

FIELD-SYMBOLS: <wa_out>, <wa_in>.

DATA: field_idx TYPE i.

START-OF-SELECTION.

  • Create the structure of new table

LOOP AT itab_in.

MOVE sy-tabix TO index.

CONCATENATE 'WC' index INTO w_lvc-fieldname.

.....................

APPEND w_lvc TO t_lvc.

ENDLOOP.

  • Create new table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_lvc

IMPORTING

ep_table = new_tab.

ASSIGN new_tab->* TO <new_itab>.

  • Create workarea

CREATE DATA wa_tab LIKE LINE OF <new_itab>.

ASSIGN wa_tab->* TO <wa_itab>.

  • Transfer data: n = Number of fields of ITAB_IN

DATA: n TYPE i.

do n times.

field_idx = field_idx + 1.

LOOP AT itab_in.

ASSIGN COMPONENT sy-tabix OF STRUCTURE <wa_itab> TO <wa_out>.

ASSIGN COMPONENT field_idx OF STRUCTURE itab_in TO <wa_in>.

ENDLOOP.

IF sy-subrc = 0.

APPEND <wa_itab> TO <new_itab>.

ENDIF.

ENDDO.

Max

Former Member
0 Kudos

Hi

You can use the LIKE statement and try the report i hope it will solve your problem.

Thanks

Mrutyunjaya Tripathy