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: 

Problem with Binary search statement

Former Member
0 Kudos

Hi,

I have problem with reading the internal with Binary search.

I have two internal tables BSAS and BSIS. In BSAS I have 1,200,000 line items and BSIS 500,000 line items. I need to delete the line items if BSIS-BELNR NE BSAS-AUGBL.

I am using the following code :

LOOP AT gt_bsas .

READ TABLE gt_bsis WITH KEY bukrs = gt_bsas-bukrs

belnr = gt_bsas-augbl

gjahr = gt_bsas-gjahr.

IF sy-subrc NE 0.

DELETE gt_bsas.

CLEAR gt_bsas.

ELSE.

-


endif.

endloop.

By this execution of the loop is taking long time. If I use the binary search it is fast but result is not correct.

Please suggest me, how to resolve this issue.

Thanks,

Sri.

4 REPLIES 4

former_member181962
Active Contributor
0 Kudos

HI Sriram,

The read statement should not be used in conjunction with the NOT EQUALS operator.

REad return one record if the ocndition matches.

There will be definitely more than ONE record for NOT EQUALS condition.

Hence it is not only taking so much time, but also is wrong usage.

REgards,

Ravi

rahulkavuri
Active Contributor
0 Kudos

hi collect the value of sy-tabix into variable

DELETE gt_bsas index v_tabix.

LOOP AT gt_bsas .

v_tabix = sy-tabix.

READ TABLE gt_bsis WITH KEY bukrs = gt_bsas-bukrs

belnr = gt_bsas-augbl

gjahr = gt_bsas-gjahr

binary search.

IF sy-subrc NE 0.

DELETE gt_bsas index v_tabix.

CLEAR gt_bsas.

ELSE.

-


endif.

endloop.

Former Member
0 Kudos

hi Sriram,

do this way..


data : v_tabix  like sy-tabix.

sort gt_bsas by <all Key Fields>.

 LOOP AT gt_bsas .

 v_tabix = sy-tabix.

READ TABLE gt_bsis WITH KEY bukrs = gt_bsas-bukrs
belnr = gt_bsas-augbl
gjahr = gt_bsas-gjahr.

IF sy-subrc NE 0.
*DELETE gt_bsas.
DELETE gt_bsas index v_tabix..
CLEAR gt_bsas.

ELSE.
------------------------
endif.
endloop.

Former Member
0 Kudos

Try this way:

LOOP AT gt_bsas .

<b>SORT GT_BSIS BY BUKRS BELNR GJAHR.</b>

READ TABLE gt_bsis WITH KEY bukrs = gt_bsas-bukrs

belnr = gt_bsas-augbl

gjahr = gt_bsas-gjahr

<b>BINARY SEARCH.</b>

<b>IF sy-subrc eq 0.</b>

****Do Nothing.

ELSE.

<b>DELETE gt_bsas sy-tabix.</b>

CLEAR gt_bsas.

endif.

endloop.

1. Also make sure that the KEY mentioned in READ statement follows the same seqeunce of gt_bsis structure.

Thanks,

Santosh

Message was edited by:

SKJ