hi,
try like this
data: numb type i value '12345',
sum type i.
while numb > 0.
numb = numb %10. [ modulo division --- remainder odf division]
sum = sum + numb.
numb = numb /1 0.
endwhile
iwrite:/10 sum.
if helpful reward some points.
with regards,
Suresh Aluri.
Hi Vinod,
The below code will satisfy your requirement.
give any number as parameter, it will give the sum of all digits.
REPORT zkk_sum.
parameters: p_num type i.
data: v_num(30) type c,
v_length type i,
v_sum type i,
v_count type i.
move p_num to v_num.
v_length = strlen( v_num ).
do v_length times.
v_count = v_count + 1.
v_sum = v_sum + ( v_num+v_count(1) ).
enddo.
write:/ 'The Sum of ', p_num, 'is ', v_sum.
Hi,
Try the below code its working.
DATA: char(5) TYPE c VALUE '12345'. DATA: len TYPE i. DESCRIBE FIELD char LENGTH len in CHARACTER MODE. DATA: count type i. do len times. data: n type n. data: i type i. data: in type i. in = sy-index - 1. n = char+in(1). i = n. count = count + i. enddo. write: count.
Regards,
Sesh
Add comment