Application Development and Automation 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: 
Read only

bubble sort program

Former Member
0 Likes
1,233

HI ,

there is a way to do bubble sort in abap

i.e. program that do that ?

Regards

Chris

3 REPLIES 3
Read only

vijy_mukunthan
Active Contributor
0 Likes
802

Hi Chris

Hi there is no such thing in SAP. At the max in report program you can use Binary search only. Not more than like bubble sort. SAP already implemented this technique in sort. So there is no need to worry about sorting technique again.

Regards

vijay

Read only

0 Likes
802

HI vijay

,

I know that sap do that in sort my question is if i want to write in good code in

abap how it look like ?

Regards

Chris

Edited by: Chris Teb on Aug 25, 2009 6:12 PM

Read only

Former Member
0 Likes
802


Chirs Tebbe wrote:

HI ,

there is a way to do bubble sort in abap

i.e. program that do that ?

Regards

Chris

Hi, it is a very late answer and by now you would have become expert in ABAP , but might be useful for someone. The Bubble Sort Program in ABAP might look like this (using sub routines):

FORM bubblesort_sub_routine USING VALUE(t_unsorted_months) CHANGING gwa_months TYPE t_months.

  DATA: s_months TYPE STANDARD TABLE OF t_months.

  s_months = t_unsorted_months.

  DATA: g_s_bubble TYPE t_months.

  DATA: g_s_current TYPE t_months.

  DESCRIBE TABLE s_months LINES gv_lines.

  WHILE sy-index < 12.

    tempi3 = sy-index.

    tempi5 = 0.

    READ TABLE s_months INTO g_s_bubble INDEX 1.

    LOOP AT s_months INTO g_s_current FROM 2 TO gv_lines - sy-index + 1.

      tempi2 = tempi2 + 1 .

      tempi5 = tempi5 + 1.

      j = sy-tabix.

      IF g_s_bubble-id > g_s_current-id.

        MODIFY s_months FROM g_s_bubble INDEX j.

        MODIFY s_months FROM g_s_current INDEX j - 1.

      ELSE.

        g_s_bubble = g_s_current.

      ENDIF.

    ENDLOOP.

  ENDWHILE.

Best,
Atul

PS: pardon the weird naming convention.