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

calculation on dynamic Internal table fields

Former Member
0 Likes
826

Hi Experts

I have one dynamic internal table in this i have to do some calcultaions.

dynamic inertnal table fields

quanity

c010

c020

c030

c040

c050

--

--

--

**********

i want to caluclate like for all the records in the internla table

quantity * c010

quantity * c020

quantity * c030

-


***

is it possible, how can it be done.

Thanks

Farooq

5 REPLIES 5
Read only

Former Member
0 Likes
685

Hi ,

Try like this

1 ) 1st calculate the number of records in that internal table

2)

Do i_values_count times.

clear var1.
Var1 = quantity * <fs>-field1.

append var1 to i_itab2.

enddo.

i_values_count is your total count in internal table

var1 for which your calculated value will be moved

i_itab2 which collects all the calculated sum

Regards

Sudhe

Read only

0 Likes
685

Hi,

Thanks for responce.

but here the problem is field names are dynamic.

fields names are not fixed. it may change

***

Quantiy

c010

c050

c070

c100

Read only

Former Member
0 Likes
685

You can do it with field symbols

loop at itab assigning <fs>.

<fs1> = <fs>-quantity * <fs>-c010.

Read only

Former Member
0 Likes
685

Hi..

Try building the logic with:

ASSIGN COMPONENT sy-index OF STRUCTURE <> TO <>. or a similar variant

Regards,

Arun

Read only

rainer_hbenthal
Active Contributor
0 Likes
685

This is more or less not working code, but shows how to achieve that:


loop at itab assigning <p>.
  do 5 times.
    cinx = sy-index.
    shift cinx left by 1 places.
    overlay cinx with '000'.
    concatenate '<p>-c' cinx into varname.
    assign <fs> to varname.
    <fs> = <fs> * qty.
  enddo.
endloop.

cinx should be a c var in length 3, <p> a fieldsymbol with linetype of your table, and <fs> a field symbol type to your columns. This will upodate c010, c020, c030, c040 and c050. You have to modify the do statements to fit your needs.