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 INPUT INTIGERS

former_member814849
Discoverer
0 Kudos

If I give input parameter (type string) = 45612789 output should be 42 (i.e., 4+5+6+1+2+7+8+9 = 42 ).

1 ACCEPTED SOLUTION

shantraj
Explorer

Please check the below offset method.

data(lv_add) = str1+0(1) + str1+1(1) + str1+2(1) + str1+3(1) + str1+4(1) + str1+5(1) + str1+6(1) + str1+7(1).

3 REPLIES 3

FredericGirod
Active Contributor

This is an exercise, you should do it instead of asking expert to do it for you. Otherwise you will stay as Padawan all your life.

shantraj
Explorer

Please check the below offset method.

data(lv_add) = str1+0(1) + str1+1(1) + str1+2(1) + str1+3(1) + str1+4(1) + str1+5(1) + str1+6(1) + str1+7(1).

0 Kudos

Thank you Shantraj for your valuable feedback.

it is correct for only string length 8.

Meanwhile i tried and got the logic. Here it is.

SELECTION-SCREEN BEGIN OF BLOCK B WITH FRAME TITLE TEXT-001.
PARAMETER P1 TYPE STRING.
SELECTION-SCREEN END OF BLOCK B.

DATA: A TYPE I,
B TYPE I,
C TYPE I,
L TYPE I.

L = STRLEN( P1 ).

DO L TIMES.
A = P1+B(1).
B = B + 1.
C = C + A.
ENDDO.

WRITE: 'Sum of all the digits is =', C LEFT-JUSTIFIED.