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

Passing values to dynamically created internal table

Former Member
0 Likes
721

Hi,

I have the flat file data as

f1,f2,f3........so on

where f1 f2 and f3 are field names.

I have a variable var which contains the data

V1,0001,0002.........so on

data: var type string.

The value of field f1 is v1

The value of field f2 is 0001

The value of field f3 is 0002.......so on

FIELD-SYMBOLS: <fs_1> TYPE STANDARD TABLE

I have dynamically created an internal table for fields f1 f2 f3 ...... using

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt_fieldcatalog

IMPORTING

ep_table = <fs_data>

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

ASSIGN <fs_data>->* TO <fs_1>.

Now for <fs_1> I have to pass the corresponding values of the fields f1 f2 f3 .

How can i solve this.

Thanks and regards ,

Parvatha Reddy

6 REPLIES 6
Read only

Pawan_Kesari
Active Contributor
0 Likes
668
DATA: new_line TYPE REF TO data.

CREATE DATA new_line LIKE LINE OF <fs_1>. 
ASSIGN new_line->*  TO <fs_2>.

ASSIGN COMPONENT 1 OF STRUCTURE <fs_2> TO <fs_3>.
<fs_3> = f1 .

ASSIGN COMPONENT 2 OF STRUCTURE <fs_2> TO <fs_3>.
<fs_3> =f2.

ASSIGN COMPONENT 3 OF STRUCTURE <fs_2> TO <fs_3>.
<fs_3> =f3.
Read only

0 Likes
668

Hi,

There is no data in <fs_1>.

I need to pass the data form the string var to the fields of <fs_1>..

Read only

0 Likes
668

Hi,

There is no data in <fs_1>.

I need to pass the data form the string var to the fields of <fs_1>..

I understand that you want to populate the internal table <fs_1>.

for that you fist need work area.. use below statement to create work area..

DATA: new_line TYPE REF TO data.
 
CREATE DATA new_line LIKE LINE OF <fs_1>. 
ASSIGN new_line->*  TO <fs_2>.

<fs_2> is not your work aread...

to assign value to each field of you work aread <fs_2>. use statement

ASSIGN COMPONENT 1 OF STRUCTURE <fs_2> TO <fs_3>.
<fs_3> = f1 .

now <fs_3> will point to the first field of work area <fs_2>, f1 is value from your string .. repeat above for each field in workarea, by increasing the component number. Once your work area is filled

append it to table.

append <fs_2> to <fs_1>

apologies if I am not getting the requiremnt correctly..

Read only

Former Member
0 Likes
668

Hi Parvatha Reddy,

Use SPLIT command to get the individual values.

DATA:

BEGIN OF ITAB OCCURS 0,

F1 TYPE WHAT EVER U USED,

F2 TYPE WHAT EVER U USED,

.

.

.

Fn TYPE WHAT EVER U USED,

END OF ITAB.

FIELD-SYMBOLS:

<FS> TYPE ANY.

LOOP AT ITAB.

ASSIGN ITAB TO <FS>.

SPLIT <FS> AT ' ' INTO V1,V2, ....Vn.

  • Where V1,V2 ....Vn are same type like F!,F2,...Fn.

  • Do What ever u want with the individual values u got in V!,V2,...,Vn.

ENDLOOP.

Hope this helps u.

Regards,

Rama.Pammi

Read only

0 Likes
668

HI,

I will not know the no of fields f1, f2 ,......... This list of fields may be extended

So, I can not declare the exact no of variables that can be used in split command

Read only

0 Likes
668

try this,

First use SPIT command and get the result in table.

SPLIT dobj AT sep INTO TABLE result_tab.

by counting the number of lines in result_tab, you can determine how many fields you need in internal table.

Second, populate the fieldcatelog with those many fields and create your dynamic internal table.

Note:

You can use SPLIT command and get result in internal table.

Edited by: Pawan Kesari on Jan 22, 2009 6:30 PM