10-08-2007 7:10 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 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-08-2007 7:15 PM
Hi Shiva,
You need to check for Sy-Subrc while using READ TABLE command...and more over, I assume itab_result must have a matnr which you need to check in READ TABLE...assuming you have matnr in itab_result too...then
sort it_matnr by matnr.
loop at itab_result.
read table it_matnr with key matnr = itab_result<b>-matnr</b> binary search.
<b>if sy-subrc eq 0.
.....
endif.</b>
endloop.
Regards,
Vivek
10-08-2007 7:15 PM
Hi Shiva,
You need to check for Sy-Subrc while using READ TABLE command...and more over, I assume itab_result must have a matnr which you need to check in READ TABLE...assuming you have matnr in itab_result too...then
sort it_matnr by matnr.
loop at itab_result.
read table it_matnr with key matnr = itab_result<b>-matnr</b> binary search.
<b>if sy-subrc eq 0.
.....
endif.</b>
endloop.
Regards,
Vivek
10-08-2007 7:17 PM
Shiva,
Shouldn't the statement be
read table it_matnr with key matnr = itab_result-matnr binary search.
Regards
Aneesh.
10-08-2007 9:43 PM
You have forgotten to write the component name (MATNR) at the end of internal table itab_result in your read statement. You were asking SAP to compare it_matnr-matnr with the entire internal table header line of internal table itab_result. If internal table itab_result has more components than MATNR your read will fail. Look at the change you need to make in bold.
loop at itab_result.
read table it_matnr with key matnr = itab_result<b>-matnr</b> binary search.
.....
endloop.
10-09-2007 4:31 AM
As you said :
" ... finally I used loop at where matnr = it_result-matnr ... "
is successful,
then your code is supposed to be like this :
sort it_matnr by matnr.
loop at itab_result.
read table it_matnr with key
matnr = itab_result-matnr binary search.
.....
endloop.
yes there is a lack of fieldname in your current code "-matnr"
rgds,
Tuwuh Sih Winedya
10-09-2007 5:58 AM
Hi Shiva,
Remember one thing while using READ statement and in that internal table having more than one records for with key condition it read the first record of similar records in IT. suppose in your code it_matnr having 5 records having same material number then READ statement fetch first record.
sort it_matnr by matnr.
<b>delete adjacent duplicates from it_matnr</b>.
loop at itab_result.
<b>clear it_matnr.</b> " you should clear the IT before READ statement.
read table it_matnr with key matnr = <b>itab_result-matnr</b> binary search.
if sy-subrc eq 0. " use the sy-subrc check for every READ statement
.....
.....
endif.
endloop.
Reward with points if helpful.
<b>Regards,</b>
Vijay
10-09-2007 6:07 AM
first of all use
read table it_matnr with key matnr = itab_result<b>-matnr</b> binary search.
n for improving performance u may add
<b>transporting no fields</b> at the end of read stmt
10-09-2007 7:37 AM
Hi,
u have missed the field name <b>MATNR</b> while reading the table
sort it_matnr by matnr.
loop at itab_result.
read table it_matnr with key matnr = itab_result-<b>MATNR</b> binary search.
....
endloop.
10-10-2007 5:28 AM
Hi Shiva,
Use this.
sort it_matnr by matnr.
loop at itab_result.
read table it_matnr with key matnr = itab_result-<b>MATNR</b> binary search.
.....
endloop.
Reward if Useful.
Regards,
Chitra