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

Internal table with data reference variable as component

abdul_hakim
Active Contributor
0 Likes
2,321

Hi

i have a below structure and itab in my program and i have the issue mentioned below..

Data: begin of wa,

col1 type i,

col2 type ref to data,

end of wa.

data itab like table of wa.

create data wa-col2 type p decimals 2.

Now my requirement is to fill the work area wa and append it to the table.

i have used field symbols and references but i am not sucessful as the value of wa-col2 is getting overwritten by the field symbol and it is not accomodating distinct values.

kindly help me out.

thanks

abdul hakim

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
1,450

Hi Abdul,

generic reference fieild like wa-col2 can not be used directly to put in values. Complete your code as

field-symbols:
Data: 
   begin of wa,
  col1 type i,
  col2 type ref to data,
end of wa.
data itab like table of wa.

create data wa-col2 type p decimals 2.  <any> type any.
assign wa-col2->* to <any>.
<any> = '123.45'." or an other type p compatible value
append wa to itab.

Regards,

Clemens

5 REPLIES 5
Read only

Clemenss
Active Contributor
0 Likes
1,451

Hi Abdul,

generic reference fieild like wa-col2 can not be used directly to put in values. Complete your code as

field-symbols:
Data: 
   begin of wa,
  col1 type i,
  col2 type ref to data,
end of wa.
data itab like table of wa.

create data wa-col2 type p decimals 2.  <any> type any.
assign wa-col2->* to <any>.
<any> = '123.45'." or an other type p compatible value
append wa to itab.

Regards,

Clemens

Read only

0 Likes
1,450

hi clemens,

thanks for the help.

my complete code:

data: begin of wa,

col1 type i,

col2 type ref to data,

end of wa.

data itab like table of wa.

field-symbols <fs> type any.

create data wa-col2 type p decimals 2.

assign wa-col2->* to <fs>.

<fs> = '123.45'.

append wa to itab.

<fs> = '456.78'.

append wa to itab.

when i loop through itab the colum wa-col2 only contains 456.78 for both the records. the value 123.45 that i have passed for the first record is lost. how can get the values 123.45 for first record and 456.78 for the second record using this technique.

thanks

abdul hakim

Edited by: Abdul Hakim on Feb 19, 2011 4:02 AM

Read only

0 Likes
1,450

Hi,

Since you are dynamically creating data type for the work area wa-col2, your pointer is pointing the first record all the time.

So the solution is: Create data type for the work area for all the records like below.

create data wa-col2 type p decimals 2.
assign wa-col2->* to <fs>.
<fs> = '123.45'.
append wa to itab.

create data wa-col2 type p decimals 2.
assign wa-col2->* to <fs>.
<fs> = '456.78'.
append wa to itab.

Other choice is declaring wa-col2 globally as TYPE p DECIMALS 2.

Read only

Clemenss
Active Contributor
0 Likes
1,450

Hi Abdul,

>

> create data wa-col2 type p decimals 2.

> assign wa-col2->* to <fs>.

> <fs> = '123.45'.

> append wa to itab.

> <fs> = '456.78'.

> append wa to itab.

You create the dynamic data only once in the work area. The field-symbols assigned always points to the same data object. First you move '123.45' to the data object, then '456.78'. In the itab, you have the same object reference stored in two records.

As Asik already showed, you have to create the data object for each internal table record. Before you create data for the reference col2, it points to nothing. If you create data only once, you have only one data object.

Regards,

Clemens

Read only

0 Likes
1,450

Asik / Clemens,

Thanks a lot. It solved my problem. I was breaking my head for couple of days for this one.. Thanks again.

--Abdul Hakim