‎2011 Feb 18 6:47 PM
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
‎2011 Feb 18 10:28 PM
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
‎2011 Feb 18 10:28 PM
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
‎2011 Feb 19 9:02 AM
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
‎2011 Feb 19 11:41 AM
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.
‎2011 Feb 19 1:13 PM
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
‎2011 Feb 20 7:46 AM
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