2009 Aug 13 1:12 PM
Hello everybody,
There are many records in my table for a given MATNR (non-key field).
If I have to Update only the first record where this MATNR occurs, how shud I proceed ?
Thanks
2009 Aug 13 1:17 PM
Hi,
Sort the internal table by matnr and then read table with INDEX 1 and update.
Regds,
Anil
2009 Aug 13 1:18 PM
sort itab by matnr.
loop at itab.
at new matnr.
update.
endat.
endloop.
Kiran
2009 Aug 13 1:21 PM
Hi,
Try this.
data: flag.
Sort Itab by matnr.
loop at itab.
on change of matnr.
flag = 'X'.
endon.
if flag = 'X'.
update table itab.
endif.
endloop.
Regards,
Satish
2009 Aug 13 1:24 PM
2009 Aug 13 1:26 PM
loop on the internal table and move these entries into a temporary internal table. before updating, check if the entry exists in the temporary internal table. if it doesnot exist update the entry.
loop at itab into wa_itab.
read it_temp into wa_temp with key matnr = wa_itab-matnr.
if sy-subrc = 0.
CONTINUE.
else.
update the entry acc to ur req.
move wa_itab-matnr to it_temp. " it_temp is the temporary table which has matnr.
endif.
endloop.
what happens with this is, for the 1st entry in the loop. it will read the temp table and as it is still empty it updates the first matnr and moves it to the temp table. so if the second entry in the loop is the same matnr again, it will chk in the temp table and it is present there so it goes to CONTINUE statement and gets the next entry in the loop and the process continues.
2009 Aug 13 1:32 PM
This is a waste of memory.
the read statement with a where condition will find the first occurence if itab is a standard table. Assigning the result to field symbol made it possible to directly change the value without memory to memory copy.
read table itab where.... assigning <p>.
if sy-subrc = 0.
<p>-matnr = 1234.
endif.
Read table for a standard tabl will always read from the beginning.
2009 Aug 13 1:35 PM
it is for the internal table.
and this is one of the ways that cane be helpful.instead of read we can use FIND to find the entries in the temp table.
2009 Aug 13 1:59 PM
Cause you only need to find one value you dont need to use find.
2009 Aug 13 1:38 PM
data: v_matnr type matnr.
loop at itab.
if v_matnr is initial or v_matnr ne itab-matnr.
v_matnr = itab-matnr.
.......
change wa here
....
modify itab .
endif.
endloop.
Edited by: mayank jain on Aug 13, 2009 3:00 PM