2022 Nov 15 9:00 AM
If I give input parameter (type string) = 45612789 output should be 42 (i.e., 4+5+6+1+2+7+8+9 = 42 ).
2022 Nov 15 9:59 AM
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).
2022 Nov 15 9:52 AM
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.
2022 Nov 15 9:59 AM
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).
2022 Nov 15 11:44 AM
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.