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: 

Adding data in char fields of internal table together

Former Member
0 Kudos

Hello,

I have an internal table with several fields in it including 2 character fields that contain amounts in them - F_OLD and F_NEW. I need to be able to add up the data in F_OLD and put it into a variable (I_OLD) and add up the data in F_NEW and put it into a variable (I_NEW). See an example of the data in the internal table here:

F_OLD and F_NEW are CHAR 254.

Record 1:

CHANGENR 2520026

TABKEY 010920000008300010

F_OLD 100

F_NEW 200

Record 2:

CHANGENR 2520026

TABKEY 010920000008300020

F_OLD 80

F_NEW 150

I want to have I_OLD = 100 + 80 and I_NEW = 200 + 150.

I don't think I can use COLLECT because not all the non-numeric fields will be the same. I don't think I can use SUM because it can only be used with numeric data types, and my data type here is CHAR.

Thanks in advance for your help,

Angela

1 ACCEPTED SOLUTION

Former Member
0 Kudos

what you can do is increase your internal table by 2 more fields (numerics) and move the contents of your CHAR fields to these. Then, perform your summations.

regards,

robert.

2 REPLIES 2

Former Member
0 Kudos

You want all the same CHANGENR to have a different variable?

You can use collect, but you would need to pass it to a second table with f_old and f_new as numeric types.

Or if you want the whole sum, just sum each pass of the table into the variable

Former Member
0 Kudos

what you can do is increase your internal table by 2 more fields (numerics) and move the contents of your CHAR fields to these. Then, perform your summations.

regards,

robert.