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 record

Former Member
0 Likes
627

Hello Experts,

I need to sum up the values of an internal table record.

data: l_demand type p decimals 2.

The itab is:

MATNR DEMAND

....................

A005 100.00

A005 200.00

A005 300.00

A005 450.00

A005 325.00

Now I would want to get the sum of all values "DEMAND" into variable "l_demand".

Can you please tell me how can I do that?

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
600

Hi,

Try this..

LOOP AT ITAB.

AT LAST.

SUM.

L_DEMAND = ITAB-DEMAND.

ENDAT.

ENDLOOP.

WRITE: / L_DEMAND.

Thanks,

Naren

7 REPLIES 7
Read only

Former Member
0 Likes
601

Hi,

Try this..

LOOP AT ITAB.

AT LAST.

SUM.

L_DEMAND = ITAB-DEMAND.

ENDAT.

ENDLOOP.

WRITE: / L_DEMAND.

Thanks,

Naren

Read only

ferry_lianto
Active Contributor
0 Likes
600

Hi,

You can also code like this.


LOOP AT ITAB.
  L_DEMAND = L_DEMAND + ITAB-DEMAND
ENDLOOP.

WRITE: / L_DEMAND.

Regards,

Ferry Lianto

Read only

0 Likes
600

Thank you very much for the help.

Read only

0 Likes
600

Hi

LOOP AT ITAB FROM 1

TO 12.

L_DEMAND = L_DEMAND + ITAB-DEMAND.

ENDLOOP.

Max

Read only

Former Member
0 Likes
600

Hi,

Try this..Exit out of the loop if the current row is greater than 12.

LOOP AT ITAB.

IF SY-TABIX > 12.

EXIT.

ENDIF.

L_DEMAND = L_DEMAND + ITAB-DEMAND.

ENDLOOP.

WRITE: / L_DEMAND.

Thanks,

Naren

Read only

Former Member
0 Likes
600

Hi,

Please remember to award points for helpful answers..

Thanks,

Naren

Read only

0 Likes
600

thnx for all help.

sorry for the delay in rewarding points.