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: 

printing a series

Former Member
0 Kudos
114

hi ,

how to print the series?

1 3 5 7 9

3 5 7

5

3 5 7

1 3 5 7 9

7 REPLIES 7

Former Member
0 Kudos
81

does any one tried for the answer?

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
81

This may work for ya.




report zrich_0003.

data: s type string.
data: start type i value -2.
data: end type  i value 10.

s = '1 3 5 7 9'.


do 5 times.
  if sy-index <= 3.
    start = start + 2.
    end   = ( end - start ) - 1.
  else.
    start = start - 2.
    end   = ( end + start ) + 3.
  endif.
  write:/ s+start(end).
enddo.

Regards,

RIch Heilman

Former Member
0 Kudos
81
<b>One funny Answer</b>


*&---------------------------------------------------------------------*
*& Report  YCHATEST                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  YCHATEST                                .

data : x type string value '1 3 5 7 9',
       y type string,
       z type string.

write : / x.
z = x.
shift x up to '3'.
shift x right deleting trailing '  9'.
shift x left deleting leading space.
y = x.
write : / x.

shift x up to '5'.
shift x right deleting trailing '  7'.
shift x left deleting leading space.
write : / x.

write : / y.
write : / z.

Message was edited by: chandu

Message was edited by: chandu

Former Member
0 Kudos
81

try this...give any 2 odd numbers and execute...!!!

REPORT  yytest88.

parameters : ulimit(2) type n default 9.

parameters : llimit(2) type n default 1.

data : val(3) type n.

data : notry type i.

notry = ( ( ulimit - llimit ) / 2 ) + 1.

do notry times.

  if ulimit > llimit.
    val = llimit.
    while val <= ulimit.
      write : val no-zero, ' '.
      val = val + 2.
    endwhile.
  else.
    val = ulimit.
    while val <= llimit.
      write : val no-zero, ' '.
      val = val + 2.
    endwhile.
  endif.

  new-line.
  llimit = llimit + 2.
  ulimit = ulimit - 2.

enddo.

0 Kudos
81

Nice snippet...but what's the porpuose? just for fun?

I have made a Decimal to Binary code...it's cool -:P

Grettings,

Blag.

0 Kudos
81

So, do we win a prize, or get the job?

Regards,

Rich Heilman

Former Member
0 Kudos
81

hi prasanth,

try this..

data : low type i , high type i , tlow type i ,thigh type i , count type i value 5, incr1 type i value 2 , incr2 type i.

incr2 = -2.

do count times.

diff = ( high - low ) / 2 + 1.

if low eq high .

incr1 = -2.

incr2 = 2.

endif.

print = low.

do diff times.

write : print.

print = print + 2.

enddo.

skip.

low = low + incr.

high = high + incr.

enddo.

regards

satesh