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

Dynamic internal table from upload file header

Former Member
0 Likes
1,045

Hi Experts,

Is it possible to create an internal table dynamically from the upload file header? My requirement is to create an internal table based on the header columns of my tab-delimited text which is dynamic. Please help how to do it.

<removed_by_moderator>

LM

Edited by: Julius Bussche on Sep 19, 2008 10:47 AM

2 REPLIES 2
Read only

Former Member
0 Likes
632

Hi Leo,

Below are few of the links which will assist for dynamic internal table.

Dynamice Internal table:

Its an extension to internal table concept, used when the number of fields is not known at the design time or until the compile time.

Example for the same..

PARAMETERS : p_table(10) TYPE C.

DATA: w_tabname TYPE w_tabname,

w_dref TYPE REF TO data,

w_grid TYPE REF TO cl_gui_alv_grid.

FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE.

w_tabname = p_table.

CREATE DATA w_dref TYPE TABLE OF (w_tabname).

ASSIGN w_dref->* TO <t_itab>.

Populating Dynamic internal table

SELECT *

FROM (w_tabname) UP TO 20 ROWS

INTO TABLE <t_itab>.

Scenario 2:

Create a dynamic internal table with the specified number of columns.

Creating Dynamic internal table

TYPE-POOLS: slis.

FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE, u201C Dynamic internal table name

<fs_dyntable>, u201C Field symbol to create work area

<fs_fldval> type any. u201C Field symbol to assign values

PARAMETERS: p_cols(5) TYPE c. u201C Input number of columns

DATA: t_newtable TYPE REF TO data,

t_newline TYPE REF TO data,

t_fldcat TYPE slis_t_fldcat_alv,

t_fldcat TYPE lvc_t_fcat,

wa_it_fldcat TYPE lvc_s_fcat,

wa_colno(2) TYPE n,

wa_flname(5) TYPE c.

  • Create fields .

DO p_cols TIMES.

CLEAR wa_it_fldcat.

move sy-index to wa_colno.

concatenate 'COL'

wa_colno

into wa_flname.

wa_it_fldcat-fieldname = wa_flname.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-intlen = 10.

APPEND wa_it_fldcat TO t_fldcat.

ENDDO.

  • Create dynamic internal table and assign to FS

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_fldcat

IMPORTING

ep_table = t_newtable.

ASSIGN t_newtable->* TO <t_dyntable>.

  • Create dynamic work area and assign to FS

CREATE DATA t_newline LIKE LINE OF <t_dyntable>.

ASSIGN t_newline->* TO <fs_dyntable>.

Populating Dynamic internal table

DATA: fieldname(20) TYPE c.

DATA: fieldvalue(10) TYPE c.

DATA: index(3) TYPE c.

DO p_cols TIMES.

index = sy-index.

MOVE sy-index TO wa_colno.

CONCATENATE 'COL'

wa_colno

INTO wa_flname.

  • Set up fieldvalue

CONCATENATE 'VALUE' index INTO

fieldvalue.

CONDENSE fieldvalue NO-GAPS.

ASSIGN COMPONENT wa_flname

OF STRUCTURE <fs_dyntable> TO <fs_fldval>.

<fs_fldval> = fieldvalue.

ENDDO.

  • Append to the dynamic internal table

APPEND <fs_dyntable> TO <t_dyntable>.

Displaying dynamic internal table using Grid.

DATA: wa_cat LIKE LINE OF fs_fldcat.

DO p_cols TIMES.

CLEAR wa_cat.

MOVE sy-index TO wa_colno.

CONCATENATE 'COL'

wa_colno

INTO wa_flname.

wa_cat-fieldname = wa_flname.

wa_cat-seltext_s = wa_flname.

wa_cat-outputlen = '10'.

APPEND wa_cat TO fs_fldcat.

ENDDO.

  • Call ABAP List Viewer (ALV)

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

it_fieldcat = fs_fldcat

TABLES

t_outtab = <t_dyntable>.

Mohinder

Read only

0 Likes
632

Hi Mohinder,

Thanks but what I need is how to make one from a header of the file uploaded. For example, I will make the first line of my file as header which are not fixed. Lets say MATNR, MAKTX, MTART... etc. These fields can be at any column in my file.

I will use GUI_UPLOAD to get these, but I'm stucked here. How to create dynamic internal table for this.

Thanks.

LM