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: 

how to print the no.series

Former Member
0 Kudos

i want a solution for the problem.

i want to print the nos in this pattern.

1 2 3 4 5

5 4 3 2

2 3 4

4 3

3

13 REPLIES 13

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Interesting requirement? Why?

There must be a reason, right?

report zrich_0002.


write:/ '1 2 3 4 5'.
write:/ '5 4 3 2'.
write:/ '2 3 4'.
write:/ '4 3'.
write:/ '3'.

Regards,

Rich Heilman

Former Member
0 Kudos

Report just_joking.

write: / '1 2 3 4 5'.

write: / '5 4 3 2'.

write: / '2 3 4'.

write: / '4 3'.

write: / '3'.

***

Really just joking

(but isn't it a solution?!?!?)

P.S.: O.k. Rich, again some seconds faster. Get the points.

P.S.2: Seems that we're thinking the same way...

Message was edited by: Jürgen Mayer

Former Member
0 Kudos

oh! nice answer rich but i want to do it using loops.

plz send answer using loop concept.

0 Kudos

Hi Prashanth,

Try this..

DATA: V_TEST value '1'.

WRITE:/ V_TEST.

DO 4 TIMES.

V_TEST = V_TEST + 1.

WRITE: V_TEST.

ENDDO.

WRITE:/ V_TEST.

DO 3 TIMES.

V_TEST = V_TEST - 1.

WRITE: V_TEST.

ENDDO.

WRITE:/ V_TEST.

DO 2 TIMES.

V_TEST = V_TEST + 1.

WRITE: V_TEST.

ENDDO.

WRITE:/ V_TEST.

DO 1 TIMES.

V_TEST = V_TEST - 1.

WRITE: V_TEST.

ENDDO.

WRITE:/ V_TEST.

Message was edited by: Phani Kiran Nudurupati

0 Kudos

Ok, I figured. Try something like this.



report zrich_0002.

data: s type string.

data: begin of itab occurs 0,
      s(1) type c,
      end of itab..

s = '1 2 3 4 5'.

split s at space into table itab.

perform write_list.

sort itab descending by s.
perform write_list.

sort itab ascending by s.
perform write_list.

sort itab descending by s.
perform write_list.

sort itab ascending by s.
perform write_list.


*&---------------------------------------------------------------------*
*&      Form  write_list
*&---------------------------------------------------------------------*
form write_list.

  loop at itab.
    if sy-tabix = 1.
      write:/ itab-s.
    else.
      write: itab-s.
    endif.
  endloop.

  delete itab index 1.

endform.

Here is a little cleaner sample. Roughly the same.

report zrich_0002.

data: s type string.
data: switch(1) type c value 'A'.
data: begin of itab occurs 0,
      s(1) type c,
      end of itab..

s = '1 2 3 4 5'.

split s at space into table itab.

while sy-subrc  = 0.

  case switch.
    when 'A'.
      sort itab ascending by s.
      switch = 'D'.
    when 'D'.
      sort itab descending by s.
      switch = 'A'.
  endcase.

  perform write_list.

  if itab[] is initial.
    exit.
  endif.

endwhile.

*&---------------------------------------------------------------------*
*&      Form  write_list
*&---------------------------------------------------------------------*
form write_list.

  loop at itab.
    if sy-tabix = 1.
      write:/ itab-s.
    else.
      write: itab-s.
    endif.
  endloop.

  delete itab index 1.

endform.

Regards,

Rich Heilman

0 Kudos

Unoffical Challenge!!!!!!

Let's see how many DIFFERENT ways we can do this using ABAP.

No, there is no prize, just the knowledge.

Regards,

Rich Heilman

0 Kudos

> Unoffical Challenge!!!!!!

>

> Let's see how many DIFFERENT ways we can do this

> using ABAP.

>

> No, there is no prize, just the knowledge.

>

> Regards,

> Rich Heilman

Did I meet your challenge Rich? It was really challenging to come up with a generic solution. I tried mine with a couple of numbers and it seems to work. Of course, I didn't take care of negative number input.

0 Kudos

Hi Srinivas,

I am trying a demo program with tabstrips.I dragged a tabstrip control and I just want to name the subscreens.I have 3 tab controls. I am using sap gui pagin technique.How do I name The subscreens. I can just name tab buttons or whole table control. I want to name the subscreens and assign them to push buttons.

Please help me.Dont mind If it is really bothering you.

Srinivas I f u can help me please answer this quoestion.

Regards,

Vijay.

Former Member
0 Kudos

hi i got solution using loops what i want.

and thanks for ur answers. they are also nice.

here how i have done.

data: f1 type i value 1,

f2 type i,

f3 type i value 6.

while f1 < 4.

f2 = f1.

f3 = f3 - 1.

while f2 <= f3.

write: f2.

f2 = f2 + 1.

endwhile.

write: /.

f1 = f1 + 1.

f2 = f2 - 1.

while f2 >= f1.

write: f2.

f2 = f2 - 1.

endwhile.

write: /.

endwhile.

0 Kudos

Hi Prashanth,

I used Do loop & you used While loop.

we can do this any no of types....

Former Member
0 Kudos

Here is your solution for any number. Please reward and close the post if answered.


PARAMETERS: p_number TYPE i.
DATA: toggle      TYPE c,
      row_numbers TYPE i,
      start       TYPE i.

DO p_number TIMES.
  NEW-LINE.
  row_numbers = p_number - sy-index + 1.
  IF toggle = space.
    DO row_numbers TIMES.
      start = start + 1.
      WRITE start.
    ENDDO.
    toggle = 'X'.
  ELSE.
    DO row_numbers TIMES.
      WRITE start.
      start = start - 1.
    ENDDO.
    CLEAR toggle.
  ENDIF.
ENDDO.

Former Member
0 Kudos

hi prashnath ,

hope this works ...

report zcount.

data : n type i value 5 , count type i value 1 , incr type i.

while n ne 0.

perform looping using count n incr.

n = n - 1.

count = count - incr.

endwhile.

form looping using count n incr.

if count > 3.

incr = -1.

else .

incr = 1.

endif.

skip.

do n times.

write : count.

count = count + incr.

enddo.

end form.

ps : reward points if helpful

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Prashanth, no reward points for these helpful answers?

Srinivas, I like your sample code. Works really well.

Regards,

Rich Helman