Application Development 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: 

Display sum of all lines of field value in internal table

sun_light
Explorer
0 Kudos
1,468

Hi experts, I wants to display the sum of particular column present in my internal table.

I tried to use at first. Sum.

But not works, attached my code.

Help to solve this..20221227-195731.jpg

1 ACCEPTED SOLUTION

Eduardo-CE
Active Participant
1,214

Hello,

My guess is that status_msg_no is not a numeric type, this code works for me:

  TYPES: BEGIN OF ty_data,
value TYPE i,
END OF ty_data.

DATA: lt_data TYPE STANDARD TABLE OF ty_data,
lw_data TYPE ty_data,
lv_sum TYPE i.

lt_data = VALUE #(
( value = 1 )
( value = 2 )
( value = 3 )
( value = 4 )
( value = 5 )
).

LOOP AT lt_data INTO lw_data.

AT LAST.
SUM.
lv_sum = lw_data-value.
ENDAT.

ENDLOOP.

WRITE lv_sum.
6 REPLIES 6

Eduardo-CE
Active Participant
1,215

Hello,

My guess is that status_msg_no is not a numeric type, this code works for me:

  TYPES: BEGIN OF ty_data,
value TYPE i,
END OF ty_data.

DATA: lt_data TYPE STANDARD TABLE OF ty_data,
lw_data TYPE ty_data,
lv_sum TYPE i.

lt_data = VALUE #(
( value = 1 )
( value = 2 )
( value = 3 )
( value = 4 )
( value = 5 )
).

LOOP AT lt_data INTO lw_data.

AT LAST.
SUM.
lv_sum = lw_data-value.
ENDAT.

ENDLOOP.

WRITE lv_sum.

0 Kudos
1,214

Thanks, this works

Eduardo-CE
Active Participant
0 Kudos
1,214

Hello,

My guess is that status_msg_no is not a numeric data type, this code works for me:

  TYPES: BEGIN OF ty_data,
value TYPE i,
END OF ty_data.

DATA: lt_data TYPE STANDARD TABLE OF ty_data,
lw_data TYPE ty_data,
lv_sum TYPE i.

lt_data = VALUE #(
( value = 1 )
( value = 2 )
( value = 3 )
( value = 4 )
( value = 5 )
).

LOOP AT lt_data INTO lw_data.

AT LAST.
SUM.
lv_sum = lw_data-value.
ENDAT.

ENDLOOP.

WRITE lv_sum.

Regards,

Eduardo.

0 Kudos
1,214

It appears you posted the same answer twice. I have removed the duplicate.

Kind regards,

--Jerry

Make sure to subscribe to What's New!

Sandra_Rossi
Active Contributor
1,214

Please, better post code as text so that people who want to answer don't have to type the code manually.

If in future questions you have to show something which is not text, please embed the images instead of proposing hyperlinks, it's more user-friendly (allows reading without need of clicking and seeing images on separate screens).

Sandra_Rossi
Active Contributor
1,214
gv_total = 0.
LOOP AT itab INTO line.
gv_total = gv_total + line-number.
ENDLOOP.