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

How to generate a dynamic structure?

Former Member
0 Likes
1,039

Hi,

I would like to ask how can I gerenate a <b>dynamic structure</b>.

The case I need this because I have a flat plain text file stored on the server;

I have to read it through SAP to the internal table for further process.

However, the program have only need to know where to chunk the data

(with a standard separator e.g. #)

but need not to understand the meaning of data.

Each chucked data will be stored in a new field of the structure which have serveral lines

(depends on the number of lines in the data file).

All the data will be in <b>string</b> format. For Example:

<u>DATA FILE:</u>

Testing1#Testing2#Testing3

Row1Col1#Row1Col2#Row1Col3

Row2Col1#Row2Col2#Row2Col3

The resultant <u>structure</u> should contain this format of data :

Testing1 | Testing2 | Testing3

Row1Col1 | Row1Col2 | Row1Col3

Row2Col1 | Row2Col2 | Row2Col3

which means the structure should have only 3 fields with dynamic field length.

From some suggestion I got, <b>field symbol</b> and <b>data reference</b> may be use in this case. However, how can I apply here?

Thanks and regards,

Mandy

<u></u>

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
997

This may be helpful to you...

data: t_fieldcat TYPE lvc_t_fcat,

wa_fieldcat TYPE lvc_s_fcat,

new_table TYPE REF TO data,

new_line TYPE REF TO data.

field-symbols: <t_tab> TYPE STANDARD TABLE,

<wa_str> type any.

wa_fieldcat-fieldname = 'FLD1'.

wa_fieldcat-tabname = 'TAB'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-inttype = 'C'.

wa_fieldcat-intlen = w_len1. " determine during run time

APPEND wa_fieldcat TO t_fieldcat.

wa_fieldcat-fieldname = 'FLD2.

wa_fieldcat-tabname = 'TAB'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-inttype = 'C'.

wa_fieldcat-intlen = w_len2. " determine during run time

APPEND wa_fieldcat TO t_fieldcat.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_fieldcat

IMPORTING

ep_table = new_table.

ASSIGN new_table->* TO <t_tab>.

CREATE DATA new_line LIKE LINE OF <t_tab>.

ASSIGN new_line->* TO <wa_str>.

Reward points if it was useful...

Regards

Prax

Hi,

I would like to ask how can I gerenate a <b>dynamic structure</b>.

The case I need this because I have a flat plain text file stored on the server;

I have to read it through SAP to the internal table for further process.

However, the program have only need to know where to chunk the data

(with a standard separator e.g. #)

but need not to understand the meaning of data.

Each chucked data will be stored in a new field of the structure which have serveral lines

(depends on the number of lines in the data file).

All the data will be in <b>string</b> format. For Example:

<u>DATA FILE:</u>

Testing1#Testing2#Testing3

Row1Col1#Row1Col2#Row1Col3

Row2Col1#Row2Col2#Row2Col3

The resultant <u>structure</u> should contain this format of data :

Testing1 | Testing2 | Testing3

Row1Col1 | Row1Col2 | Row1Col3

Row2Col1 | Row2Col2 | Row2Col3

which means the structure should have only 3 fields with dynamic field length.

From some suggestion I got, <b>field symbol</b> and <b>data reference</b> may be use in this case. However, how can I apply here?

Thanks and regards,

Mandy

<u></u>

6 REPLIES 6
Read only

Former Member
0 Likes
997

Hi Mandy,

Refer to below weblog

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

Reward points if useful.

Regards,

Atish

Read only

Former Member
0 Likes
997

Please visit the below link.

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

Ravi

Read only

former_member194669
Active Contributor
0 Likes
997

Hi,

May this will help you.

data : begin of itab occurs 0,

field1(50) type c,

field2(50) type c,

field3(50) type c.

data : end of itab.

after reading the file and moving to this i_inputfile

loop at i_inputfile.

split i_inputfile at CL_ABAP_CHAR_UTILITIES=>CR_LF into table itab.

append itab.

endloop.

aRs

Read only

0 Likes
997

but I need not yet know how many fields will be....

how can I get the correct structure(itab)?

Read only

0 Likes
997

Hi Mandy,

Do you know the number of fields <b>(n)</b> to be included in the internal table ?

If yes then you can use above method...

or you can use an internal table with its <b>n</b> fields of type string.

But I think you should have known the number of fields in the internal table or the type of structure. then only you can proceed further...

You can do one thing...

read each data record from file to a string and then count the number of # (n) in the string, number of fields = n + 1. Your problem may get solved.

Read only

Former Member
0 Likes
998

This may be helpful to you...

data: t_fieldcat TYPE lvc_t_fcat,

wa_fieldcat TYPE lvc_s_fcat,

new_table TYPE REF TO data,

new_line TYPE REF TO data.

field-symbols: <t_tab> TYPE STANDARD TABLE,

<wa_str> type any.

wa_fieldcat-fieldname = 'FLD1'.

wa_fieldcat-tabname = 'TAB'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-inttype = 'C'.

wa_fieldcat-intlen = w_len1. " determine during run time

APPEND wa_fieldcat TO t_fieldcat.

wa_fieldcat-fieldname = 'FLD2.

wa_fieldcat-tabname = 'TAB'.

wa_fieldcat-datatype = 'CHAR'.

wa_fieldcat-inttype = 'C'.

wa_fieldcat-intlen = w_len2. " determine during run time

APPEND wa_fieldcat TO t_fieldcat.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_fieldcat

IMPORTING

ep_table = new_table.

ASSIGN new_table->* TO <t_tab>.

CREATE DATA new_line LIKE LINE OF <t_tab>.

ASSIGN new_line->* TO <wa_str>.

Reward points if it was useful...

Regards

Prax