‎2007 Dec 18 4:45 AM
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????
‎2007 Dec 18 4:49 AM
Hi,
can you pls paste the code so that we can check it
regards,
siva chalasani.
‎2007 Dec 18 4:52 AM
The internal table must be sorted in ascending order by the specified search key and make sure it doesn't have duplicates.
‎2007 Dec 18 5:07 AM
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.
‎2007 Dec 18 5:36 AM
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.
‎2007 Dec 18 7:04 AM
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
‎2007 Dec 18 7:06 AM
‎2007 Dec 18 7:07 AM
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
‎2007 Dec 18 7:10 AM
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.
‎2007 Dec 18 7:12 AM
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.
‎2007 Dec 18 7:14 AM
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.
‎2007 Dec 18 7:51 AM
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