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

everyone,

I am trying to upload a excel file into internal table, but i can not excpct the max no of columns in excel file ,so i need a dynamic internal table ,as by varying no of columns i could upload file into internal table, there should not be limit of no of colums to be uploaded ,if any one could suggest something i will be greatful.

thanks

san

5 REPLIES 5

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Check this link.May be it can help you.

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

Former Member
0 Kudos

hi, the way to create dynamic table, you can reference these link

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

But I think, if the structure of target internal table is unclear, you need a dynamic table.

If only the source file column is not clear, and the target internal table defination is fixed, you don't need it.

just read the file into a long char table like this:

TYPES: begin of typ_tmp,

data(1000) type c,

end of typ_tmp.

DATA: itab_tmp type standard table of typ_tmp.

After the file read into it, you can do a split or other action to parse it.

Former Member
0 Kudos

Hi sanjeev,

See this weblog:

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

This can help you.

Thanks & Regards,

Ravikiran.

0 Kudos

Hi,

try that:

1) gui_upload csv-file with delimiter ';' into

internal table (type string)

2) cr dynamic structure (rel. 4.6) or itab (4.7)

CREATE DATA dwa TYPE (name).

ASSIGN dwa->* TO <rec>.

3) split data :

SPLIT wa AT trenn INTO TABLE sptab.

4) loop sptab and fill your structure :

ASSIGN COMPONENT idx OF STRUCTURE <rec> TO <f>.

Andreas

Former Member
0 Kudos

hi,

here is a sample code to create a dynamic internal table.

hope it gives you some pointers....(plz don't mind the lack of indentation)

TABLES: mara, makt.

TYPE-POOLS: slis.

DATA: it_fcat

TYPE slis_t_fieldcat_alv,

is_fcat LIKE LINE OF it_fcat,

ls_layout TYPE slis_layout_alv.

DATA: it_fieldcat TYPE lvc_t_fcat,

is_fieldcat LIKE LINE OF

it_fieldcat.

DATA: new_table TYPE REF TO data,

new_line TYPE REF TO data,

ob_cont_alv TYPE REF TO cl_gui_custom_container,

ob_alv TYPE REF TO cl_gui_alv_grid,

vg_campos(255) TYPE c,

i_campos LIKE TABLE OF vg_campos,

vg_campo(30) TYPE c,

vg_tables(60) TYPE c.

*DATA: e_params LIKE zutsvga_alv_01.

FIELD-SYMBOLS: <l_table> TYPE table,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

PARAMETERS: p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

is_fcat-fieldname = 'COL01'.

is_fcat-ref_fieldname = 'MATNR'.

is_fcat-ref_tabname = 'MARA'.

APPEND is_fcat TO it_fcat.

is_fcat-fieldname = 'COL02'.

is_fcat-ref_fieldname = 'MAKTX'.

is_fcat-ref_tabname = 'MAKT'.

APPEND is_fcat TO it_fcat.

LOOP AT it_fcat INTO is_fcat.

is_fieldcat-fieldname = is_fcat-fieldname.

is_fieldcat-ref_field = is_fcat-ref_fieldname.

is_fieldcat-ref_table = is_fcat-ref_tabname.

APPEND is_fieldcat TO it_fieldcat.

CONCATENATE is_fieldcat-ref_table is_fieldcat-ref_field INTO

vg_campos SEPARATED BY '~'.

APPEND vg_campos TO i_campos.

ENDLOOP.

*... Create the dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

*... Create a new line

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

SELECT (i_campos) FROM mara INNER JOIN makt ON maramatnr = maktmatnr

UP TO P_MAX ROWS INTO TABLE <l_table>.

describe table <l_table>.

write 😕 sy-tfill.

LOOP AT <l_table> INTO <l_line>.

LOOP AT it_fcat INTO is_fcat.

ASSIGN COMPONENT is_fcat-fieldname OF STRUCTURE <l_line> TO <l_field>.

IF sy-tabix = 1.

WRITE: /2 <l_field>.

ELSE.

WRITE: <l_field>.

ENDIF.

ENDLOOP.

ENDLOOP.

regards,

PJ