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

Abap Summation

benlim
Contributor
0 Likes
1,052

Hi Expert,

I have such scenario as below:

int a = 234.

int b = 567.

int c = 876.

int z.

How to add these 3 integer (a, b and c) as below:

z = 2+3+4+5+6+7+8+7+6.

Thanks.

Regards,

-Ben-

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,022

Hi Yen Shen,

Integer Type Fields does not permit subfield access.

Hence assign the Integer Type Fields to a character type fields.

Data M(3) type C.

M = a. a is your integer variable.

then you can access individual subfields like m+0(1) + m+1(1) + m+2(1).

Thanks and Regards,

Vinay Mutt

6 REPLIES 6
Read only

Former Member
0 Likes
1,023

Hi Yen Shen,

Integer Type Fields does not permit subfield access.

Hence assign the Integer Type Fields to a character type fields.

Data M(3) type C.

M = a. a is your integer variable.

then you can access individual subfields like m+0(1) + m+1(1) + m+2(1).

Thanks and Regards,

Vinay Mutt

Read only

0 Likes
1,022

Hi Vinay Mutt,

Thanks for your prompt response.

Never thought and try on summation on character field.

Thanks again!

Regards,

-Ben-

Read only

0 Likes
1,022

Hi Yen,

You can hold your values in char variables. Then you can do the summation character by character. I wrote sample code to the below part. After plus sign, number indicates the offset and the number in the parentheses indicates the length which you want to use.

Regards.

DATA: a(3) TYPE c value '234',

           b(3) TYPE c value '567',

           c(3) TYPE c value '876',

           z TYPE i .

z = a+0(1) + a+1(1) + a+2(1) + b+0(1) + b+1(1) + b+2(1) + c+0(1) + c+1(1) + c+2(1). //result 48


Read only

0 Likes
1,022

Hi Alper,

I have get the solution from .

Thanks for your effort for helping me to write out the sample code.

Aprreciate it

Regards,

-Ben-

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,022

You could also play with the MOD 10 operator di some DO loop.

Regards,

Raymond

Read only

0 Likes
1,022

Hi Raymond,

Thanks for your suggestion. I have get the solution.

Regards,

-Ben-