‎2009 May 25 9:21 AM
Hi All ,
There is a small confusion i am having in my mind so wanted to clear it
In my internal table i have 4 fields
1. Material no.
2.material plant no.
3.sold to party
4.ship to party
I need to read this internal table different times in different places based on various keys as like
Read itab with key material no BINARY SEARCH.
Read itab with key material plant no. BINARY SEARCH.
Read itab with key sold to party BINARY SEARCH.
Read itab with key ship to party BINARY SEARCH.
So my questions is shld i sort the table by each key sepertly before reading it
like this
sort itab by material no
Read itab with key material no BINARY SEARCH.
sort itab by material plant no
Read itab with key material plant no. BINARY SEARCH.
sort itab by sold to party
Read itab with key sold to party BINARY SEARCH.
sort itab by ship to party
Read itab with key ship to party BINARY SEARCH.
Or i can once sort table by material no material plant no sold to party ship to party
Please explain me how best this can be done and why?
Regards
Bhanu
‎2009 May 25 9:25 AM
If your read statements are inside a same loop then DO NOT USE BINARY SEARCH.
If it is as different places then you have to sort it prior to corresponding read statements. But in these cases, you should be very cautious while reading data with binary search as if the sorting is not proper, you will get abrupt results.
Do not go for BINARY SEARCH in such cases.
‎2009 May 25 9:44 AM
If you use binary search you must sort the table, otherwise the results are unpredictable.
‎2009 May 25 9:49 AM
Dear Bhanu,
As you want to read a internal table with different variable field, then you can sort your internal table with hierarchy and avoid 'Binary Search ' to read the record.
Hope this will solve your problem. Feel free to ask if you have still any doubt.
Regards,
Vijay
‎2009 May 25 9:54 AM
i am using this read statement inside a loop which is unavoidable so for sure i should not use sort inside
loop .
sort your internal table with hierarchy ??Can you explain a little bit more?
‎2009 May 25 10:37 AM
Dear Bhanu,
what I mean sort your internal table before loop with say Material no material plant no sold to party ship to party.
so that your internal table will be in sequence. It will become easy to read.
Feel free to ask still you have any doubt.
Regards,
Vijay
‎2009 May 25 9:49 AM
Hi,
Since the condition changes each time, it is good to sort each time based on the read condition and then read using binary search.
‎2009 May 25 10:00 AM
Hi,
Why is it required for you to write 4 read statements... can you do it with one read statement....
Regards,
Siddarth
‎2009 May 25 10:03 AM
Why is it required for you to write 4 read statements... can you do it with one read statement....
Its like i have to read the internal table on different conditions .
Say if
WHEN 'PROGRAM ID 'ABC ON SELECTION SCREEN '
READ ITAB BY MATERIAL NO.
WHEN PROGRAM ID 'XYZ'
I HAVE TO READ ON PLANT KEY
‎2009 May 25 10:13 AM
then probably its better not to use binary search... it will lead on very high performance issue if you do it, because you will have to sort the table again and again and then give a read on it.... so its better just give a read statement to the table removing binary search.....
Regards,
Siddarth
‎2009 May 25 11:19 AM
Hi,
sort itab by material no
Read itab with key material no .
sort itab by material plant no
Read itab with key material plant no.
sort itab by sold to party
Read itab with key sold to party .
sort itab by ship to party
Read itab with key ship to party.
Regards,
munibabu.k
‎2009 May 25 12:01 PM
Hi,
Instead of using the same internal table, copy the table into 4 internal tables and sort it according to the key. Then you can use bianry search.
Regards,
Kiran.
‎2009 May 25 12:13 PM
Do not sort before each read inside a loop, the cost of each sort would far outweigh the binary search effect.
I think Kiran's idea is OK, if the table is not too large, copy it 4 times and sort once by each key.
Look forward to internal tables with secondary indexes, will be in the next Netweaver release.
Thomas
correction: you need 3 tables, mat# and mat# plant# can be handled with the same table. this implies that just mat# is not unique, are you sure a read is sufficient, don't you need a loop here?
‎2009 May 25 12:43 PM
When storing the table three times or four times in the report and if the only purpose of those tables is to be read for ceratin values, i would prefer hashed tables. They are much more performant rather than sorted tables with binary search.
‎2009 May 25 12:59 PM
Yes, if the full key is used for access. If only a part of the key is used (from left to right of course), then sorted tables are the best option.
Thomas
‎2009 May 25 2:37 PM
your task is a bit strange and I guess the reason was giving by you:
> WHEN 'PROGRAM ID 'ABC ON SELECTION SCREEN '
> READ ITAB BY MATERIAL NO.
This looks to me as if you have to use onyl one read type per execution, depending to the
selection.
So it should be enough to sort once also depending on the selection.
To be on the safe side, it would better to split the whole program in different branches, such that
only one branch is used in one execution. Inside the branch there is the sort, the loop and the
respective read binary search inside.
Otherwise, if you really have to read in one program execution with 4 different keys inside one loop.
Then you must prepare 4 identical tables and sort them outside of the loop and use for each
read binary search the respectivly sorted table.
=> and please update to the new Netweaver release. 7.0 EhP 2 as soon as possible, there you can define different secondary keys, which solves your problem.
Siegfried