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.

Former Member
0 Kudos

Hi Gurus.

I am using binary search to read data from internal table with approx more than 3lacs records. Also my table is sorted by BUKRS BELNR. But the problem is that i am getting records from lower half of table only and first half of table is ignoring, so i am not able to get all records. If i use nornal search, i am geting 7856 records and if i use binary search, i am geting only 1786 records....Can anyone help me why this is happening????

11 REPLIES 11

Former Member
0 Kudos

Hi,

can you pls paste the code so that we can check it

regards,

siva chalasani.

Former Member
0 Kudos

The internal table must be sorted in ascending order by the specified search key and make sure it doesn't have duplicates.

0 Kudos

Hi PV

Actually my table contain line items. I am reading header data from bkpf for a single day. and for that document nos i am fetching line items. But if i use join or for all entries, i will get time exceed errror. so i get Period of that single day and taking data for that period from BSIS and then reading BKPF.. and only taking that line items for which document no in BKPF...

my code is like

SELECT-OPTIONS: cpudt FOR sy-datum DEFAULT '20030102'.

SELECT bukrs belnr gjahr monat FROM bkpf

INTO CORRESPONDING FIELDS OF TABLE ibkpf

WHERE ( cpudt IN cpudt OR aedat IN cpudt ).

ibkpf1[] = ibkpf[].

SORT ibkpf1 BY monat.

DELETE ADJACENT DUPLICATES FROM ibkpf1 COMPARING monat.

IF ibkpf1[] IS NOT INITIAL.

SELECT * FROM bsis INTO TABLE ibsis

FOR ALL ENTRIES IN ibkpf1 WHERE gjahr = ibkpf1-gjahr

AND monat = ibkpf1-monat.

SORT ibsis BY bukrs belnr.

LOOP AT ibsis.

READ TABLE ibkpf WITH KEY bukrs = ibsis-bukrs

belnr = ibsis-belnr

BINARY SEARCH.

IF sy-subrc NE 0.

DELETE ibsis.

ENDIF.

ENDLOOP.

ENDIF.

0 Kudos

Hi,

create one workarea and read the internal table into work area like loop at itab into wa_itab..

than it will work, whenever we use Read statement work area has to be defined...

Thanks,

Tirumal.

0 Kudos

Hi PKB,

create one workarea and read the internal table into work area like loop at itab into wa_itab..than it will work, whenever we use Read statement work area has to be defined...

SELECT-OPTIONS: cpudt FOR sy-datum DEFAULT '20030102'.

SELECT bukrs belnr gjahr monat FROM bkpf

INTO CORRESPONDING FIELDS OF TABLE ibkpf

WHERE ( cpudt IN cpudt OR aedat IN cpudt ).

ibkpf1] = ibkpf[.

SORT ibkpf1 BY monat.

DELETE ADJACENT DUPLICATES FROM ibkpf1 COMPARING monat.

IF ibkpf1[] IS NOT INITIAL.

SELECT * FROM bsis INTO TABLE ibsis

FOR ALL ENTRIES IN ibkpf1 WHERE gjahr = ibkpf1-gjahr

AND monat = ibkpf1-monat.

SORT ibsis BY bukrs belnr.

LOOP AT ibsis.

*READ TABLE ibkpf into wa_ibsis WITH KEY bukrs = ibsis-bukrs*

belnr = ibsis-belnr

BINARY SEARCH.

IF sy-subrc NE 0.

DELETE

0 Kudos

Hi Gurus..

Please help me regarding this problem..

former_member402443
Contributor
0 Kudos

Hi PKB,

create one workarea and read the internal table into work area like loop at itab into wa_itab..than it will work, whenever we use Read statement work area has to be defined...

IF ibkpf1[] IS NOT INITIAL.

SELECT * FROM bsis INTO TABLE ibsis

FOR ALL ENTRIES IN ibkpf1 WHERE gjahr = ibkpf1-gjahr

AND monat = ibkpf1-monat.

SORT ibsis BY bukrs belnr.

LOOP AT ibsis.

READ TABLE ibkpf into wa_ibsis WITH KEY bukrs = ibsis-bukrs

belnr = ibsis-belnr

BINARY SEARCH.

endloop.

and rest of the your code is okye.

Rewards points if useful

Regards

Manoj Kumar

Former Member
0 Kudos

Hi,

Sort the internal table with all other fields, if you look at BKPF table you have BUKRS, BELNR, GJAHR and Monat are key fields. So sort based on these fields. Then read the table using binary search.

Then also if you are facing problem. Then better to delete the Binary search, sometimes binary search leads to incorrect data.

Thanks,

Sriram Ponna.

Former Member
0 Kudos

Hi,

Sort the internal table with all other fields, if you look at BKPF table you have BUKRS, BELNR, GJAHR and Monat are key fields. So sort based on these fields. Then read the table using binary search.

Then also if you are facing problem. Then better to delete the Binary search, sometimes binary search leads to incorrect data.

Thanks,

Sriram Ponna.

Former Member
0 Kudos

Hi,

Sort the internal table with all other fields, if you look at BKPF table you have BUKRS, BELNR, GJAHR and Monat are key fields. So sort based on these fields. Then read the table using binary search.

Then also if you are facing problem. Then better to delete the Binary search, sometimes binary search leads to incorrect data.

Thanks,

Sriram Ponna.

Former Member
0 Kudos

Hi PKB,

whenever we are going to use READ TABLE using Binary Search what are the fields we are giving in the where condition that fields must be sorted.

- Selva