Bubble Sort

 data str_abap_rocks(100) value 'ABAP Editor rocks!!!'. 

WRITE: str_abap_rocks.

types: begin of ty_id,

        id type int4,

        end of ty_id.

types: ty_id2 type standard table of ty_id with empty key.

data: it_d type table of int4,

    it_d3 type table of ty_id,

      wa_d type int4.

data: lv_np type i,

      lv_ns type i.

it_d = VALUE #( ( 4 ) ( 1 ) ( 3 ) ( 2 ) ( 5 ) ).


DESCRIBE table it_d lines data(lv_lines).

write:/ lv_lines.

new-line.

lv_np = 0.

lv_ns = 0.

while sy-index < lv_lines.

data(wa_bd) = it_d[ 1 ].

lv_np = lv_np + 1.

loop at it_d into data(wa_cd) from 2 to lv_lines - sy-index + 1.

if ( wa_bd  > wa_cd ).

lv_ns = lv_ns + 1.

it_d[ sy-tabix ] = wa_bd.

it_d[ sy-tabix - 1 ] = wa_cd.

else.

wa_bd = wa_cd.

endif.

endloop.

endwhile.


WRITE: lv_ns.

WRITE: lv_np.

new-line.


DATA(it_d2) = VALUE ty_id2( FOR wa_d2 IN it_d ( id = wa_d2 ) ).

 

LOOP at it_d2 into data(wa_d3).

    write: wa_d3-id.

endloop.


Comments

Popular posts from this blog

Can Reach program ( 1 d arrray)

Fibonacci - Tabulated 1d array manipulation