10-10-2007 6:02 PM
Hello Experts.
my code is like this.
sort it_matnr by matnr.
loop at itab_result.
read table it_matnr with key matnr = itab_result-matnr binary search.
.....
endloop.
there are nearly 2000 records in it_matnr . The records which satisfy the above condition is there here in this internal table. But it is unable to read the record which matches the condition. One thing is that , there are more than one record with the same material. ie mblnr is different but material is the same. In it_matnr table i have only 1 field ie matnr ,so i need to compare only with the matnr.I also tried by sorting it_result by matnr but of no use. Then finally I used loop at where matnr = it_result-matnr , it is working fine. But due to performance reasons we should not use this. so please tell me what to do and correct the code.
10-10-2007 6:07 PM
How you are sorting the itab_result.
sort it_matnr by matnr. " -> comment the sort
loop at itab_result.
read table it_matnr with key matnr = itab_result-matnr. " Comment binary search.
.....
endloop.
Now see the results.
Thanks
Seshu
10-10-2007 6:28 PM
Try this:
SORT it_matnr BY matnr.
LOOP AT itab_result.
READ TABLE it_matnr
WITH KEY matnr = itab_result-matnr
BINARY SEARCH.
* Process record
LOOP AT it_matnr FROM sy-tabix.
IF it_matnr <> itab_result-matnr.
EXIT.
ENDIF.
* Process record
ENDLOOP.
ENDLOOP.
Rob
10-11-2007 5:34 AM
Hi
i am sending you a sample code where i had writen for my program
there i did't faced any performance problem
sort it_sobid by objid.
LOOP AT IT_SOBID INTO WA_SOBID." where otype eq s_otype and objid eq s_objid.
READ TABLE IT_HRP1026 WITH KEY OBJID = WA_SOBID-SOBID OTYPE = WA_SOBID-SCLAS INTO WA_HRP1026.
IF SY-SUBRC EQ 0.
READ TABLE IT_HRP1000 WITH KEY OBJID = WA_SOBID-SOBID INTO WA_HRP1000.
WA_OUTPUT-OBJID = WA_HRP1026-OBJID.
WA_OUTPUT-BEGDA = WA_SOBID-BEGDA.
WA_OUTPUT-ENDDA = WA_SOBID-ENDDA.
WA_OUTPUT-AEDTM = WA_HRP1026-AEDTM.
WA_OUTPUT-UNAME = WA_HRP1026-UNAME.
APPEND WA_OUTPUT TO IT_OUTPUT.
CLEAR WA_OUTPUT.
ENDIF.
ENDLOOP.
<b>Reward if usefull</b>
10-11-2007 5:35 AM
Hi
if the multiple entries are there, then it will change all the values which macthes the matnr. look for some different field which changes each time and has different value
Regards
Shiva
10-11-2007 5:43 AM
hi,
read statement suppress duplicate records..it reads only the first record when
there are duplicate records.
hence you have to use nested loops.
ie. loop at itab_result.
loop at it_matnr.
endloop.
endloop.
if performance is taken into accout write where condition
i.e., loop at itab_result.
loop at it_matnr where matnr = itab_result-matnr.
endloop.
endloop.
regards
sree
10-11-2007 5:45 AM
Hi Shiva,
Try this.
data : wa_itab_result like line of itab_result.
sort it_matnr by matnr.
loop at itab_result into <b>wa_itab_result</b>.
read table it_matnr with key matnr = <b>wa_itab_result-</b>matnr binary search.
.....
endloop.
Reward if Useful.
Regards,
Chitra
10-11-2007 5:57 AM
Hi,
Try with this following code,
sort it_matnr by matnr.
loop at itab_result.
<b>Clear : it_matnr</b> " u should use always clear stat before READ, suppose if read statement fails it contains the previous read data.
read table it_matnr with key matnr = itab_result-matnr binary search.
.....
endloop
if u using version above 4.7e use the following code.
data : wa_itab_result like line of itab_result.
sort it_matnr by matnr.
loop at itab_result into wa_itab_result.
<b>Clear : it_matnr</b> " u should use always clear stat before READ, suppose if read statement fails it contains the previous read data.
read table it_matnr with key matnr = wa_itab_result-matnr binary search.
.....
clear : itab_matnr.
endloop.
<b>Reward with points if useful.</b>
Regards,
Vijay
10-11-2007 11:18 AM
1. Make sure that the table IT_MATNR is not getting updated inside the loop. Because it will then destroy the sorting.
2. Secondly, if there are multiple records in IT_MATNR for the same material then it will search for the first record encountered in binary algo. So it is advisable that you may provide further filter criteria if possible. check if ITAB_RESULT & IT_MATNR have any other matching field that can be put in filter criteria.
3.Thirdly, check if your requirement can be achieved by STABLE SORT.
<b>SORT <itab> ... STABLE BY <f1>[ASCENDING/DESCENDING].</b>
It will allows you to perform a stable sort, that is, the relative sequence of lines that are unchanged by the sort is not changed. If you do not use the STABLE option, the sort sequence is not preserved. If you sort a table several times by the same key, the sequence of the table entries will change in each sort. However, a stable sort takes longer than an unstable sort.
4. Lastly, you can use parallel cursor technique of multiple loops which is given below:
LOOP AT itab_result.
READ TABLE it_matnr
WITH KEY matnr = itab_result-matnr
BINARY SEARCH.
Process record
LOOP AT it_matnr FROM sy-tabix.
IF it_matnr <> itab_result-matnr.
EXIT.
ENDIF.
Process record based on yuor condition
ENDLOOP.
ENDLOOP.