Skip to Content
0
Feb 11, 2016 at 06:27 AM

Regarding the Binary search in Abap

200 Views

hi all,


I have developed this piece of code in my assignment using the binary search concept.i am not able to find why this code is not working.


please provide me suitable solution so that i can modify this code.



REPORT ZDEMOPROGRAM.

TABLES: vbak,

vbap.

TYPES:BEGIN OF it_vbak,

vbeln TYPE vbak-vbeln,

auart TYPE vbak-auart,

END OF it_vbak.

DATA: it_vbak1 TYPE TABLE OF it_vbak.

DATA:wa_vbak1 TYPE it_vbak.

PARAMETERS: p_vbeln TYPE vbak-vbeln.

SELECT vbeln

auart FROM vbak INTO CORRESPONDING FIELDS OF TABLE it_vbak1.

SORT it_vbak1 BY vbeln.

READ TABLE it_vbak1 INTO wa_vbak1 WITH KEY vbeln = p_vbeln BINARY SEARCH.

IF sy-subrc = 0.

LOOP AT it_vbak1 INTO wa_vbak1 FROM sy-index.

IF wa_vbak1-vbeln <> p_vbeln.

EXIT.

ELSE.

WRITE: / wa_vbak1.

ENDIF.

ENDLOOP.

ENDIF.