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: 

use do - enddo.

Former Member
0 Kudos
132

please can anybody write this using do -


enddo


*DATA: BEGIN OF numbers,
*        one   TYPE p LENGTH 8 DECIMALS 0 VALUE 10,
*        two   TYPE p LENGTH 8 DECIMALS 0 VALUE 20,
*        three TYPE p LENGTH 8 DECIMALS 0 VALUE 30,
*        four  TYPE p LENGTH 8 DECIMALS 0 VALUE 40,
*        five  TYPE p LENGTH 8 DECIMALS 0 VALUE 50,
*      END OF numbers,
*
*      sum     TYPE i.
*
*
*SELECT-OPTIONS position FOR sum.
*
*ADD numbers-one THEN numbers-two
*                UNTIL numbers-five
*                ACCORDING TO position
*                GIVING sum.
*
*                write:/ sum.

Code Formatted by: Alvaro Tejada Galindo on Feb 5, 2008 3:24 PM

2 REPLIES 2

Former Member
0 Kudos
49

Why not give it a try yourself and get back to the forum if you have problems.

Rob

Former Member
0 Kudos
49

Hi Shaik,

I donot know what the select option field position is for , but assuming that all you need to do is sum all the fields of numbers structure i.e numbers-one + numbers-two.....and so on to get the result 150 and using do ..enddo.

To that, use the following code:

DATA : BEGIN of NUMBERS ,

place type p decimals 0, "place represents one, two, three and so on.....I dont need 5 different memory areas,i can achieve the

END of NUMBERS, "same result with just one field.

SUM type i value 0.

select-options position for sum.

numbers-place = 10. "initialising with first value for one =10.

do 5 times.

sum = sum + numbers-place."first time in do loop this is 0 = 010 i.e 10, then 1020 ,then 30+30 and so on.

numbers-place = numbers-place + 10.

enddo.

write : sum. "this gives result as 1020304050 =150.

Hope this helps answering your problem. <REMOVED BY MODERATOR>

Thanks.

Deepti

Edited by: Alvaro Tejada Galindo on Feb 5, 2008 4:38 PM