‎2009 Aug 25 4:32 PM
HI ,
there is a way to do bubble sort in abap
i.e. program that do that ?
Regards
Chris
‎2009 Aug 25 4:37 PM
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
‎2009 Aug 25 4:40 PM
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
‎2016 Feb 02 9:44 AM
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.