‎2007 Apr 10 12:57 PM
Hi All,
data: begin of t_kna1 occurs 0,
kunnr like kna1-kunnr,
name1 like kna1-name1,
end of t_kna1.
select kunnr name1 from kna1 into table t_kna1.
sort t_kna1 by kunnr name1.
loop at t_bseg.
read table t_kna1 with key kunnr = t_bseg-kunnr name1 = t_bseg-name1
binary search.
............
endloop.
loop at t_bseg.
read table t_kna1 with key name1 = t_bseg-name1
kunnr = t_bseg-kunnr binary search.
............
endloop.
In the above sample code we are reading the table t_kna1 with different key sequence.What is difference in that which should be followed why? whether the second one is wrong or what?
‎2007 Apr 10 1:04 PM
Hi Sri ram,
there might be littel difference in reading the records from the internal table "<b>t_kna1</b> " for the second and first case as the key sequence in the read statement is different....
In the <b>first case</b> the records are read firstly based upon the kunnnr and then based upon the name field...
whereas in the <b>second case</b> as per the key sequnece in the read statement
the filtering of the read statement is done initially by the name 1 field and then the kunnr field.
Regards ,
Ginni.
Reward if helpful.
‎2007 Apr 10 1:00 PM
Hi,
you can only use the binary search for fields on which the table is sorted.
So the first READ TABLE is working, the second IS NOT !
You can add a SORT T_KNA BY NAME1 KUNNR before the second loop-statement.
regards,
Hans
Please reward all helpful answers !!!!!
‎2007 Apr 10 1:01 PM
Hi,
In both cases no need to use NAME1 field as key field to read, as it is a description field.
Right thing is:
read table t_kna1 with key kunnr = t_bseg-kunnr binary search.
binary search reads data fast.
But you must sort the internal table first with that field.
reward points if useful
regards,
ANJI
‎2007 Apr 10 1:01 PM
Hi Shri,
It depends on the requirement for searching in the internal table..
Both are correct but you have to sort for that particular fields which you are using as key.( not to sort all the fields when one is required..)
‎2007 Apr 10 1:04 PM
Hi,
it will be better if u write like first statement, bcoz it is as per standard.
Hope this will help you for this and for your previous post.
Award all helpful answers and close the post as answered.
‎2007 Apr 10 1:04 PM
Hi Sri ram,
there might be littel difference in reading the records from the internal table "<b>t_kna1</b> " for the second and first case as the key sequence in the read statement is different....
In the <b>first case</b> the records are read firstly based upon the kunnnr and then based upon the name field...
whereas in the <b>second case</b> as per the key sequnece in the read statement
the filtering of the read statement is done initially by the name 1 field and then the kunnr field.
Regards ,
Ginni.
Reward if helpful.