‎2007 May 08 2:39 PM
hi experts,
by using read.how can we read the number which appears several times.ie we have kunnr = 100 ,5 times.how can we read 2nd one by using read.
thanks in advance
‎2007 May 08 2:44 PM
Hi,
If you want to use the statment READ, then you need to use the perfect condition in the KEY(Where condition of the READ statment), so the perfect value will come . if you have the same records, then use the LOOP AT statment, if you find the correct record then use the EXIT statment to comeout from the LOOP
Regards
Sudheer
‎2007 May 08 2:41 PM
‎2007 May 08 2:42 PM
Hi,
data:i_kna1 type kna1 occurs 0 with header line.
select * from kna1 into i_kna1 where kunnr = '100'.
write:/ i_kna1-name1,i_kna1-land1.
endselect.
rgds,
bharat.
‎2007 May 08 2:43 PM
Hi
U can't do it, u have to use the LOOP/ENDLOOP statament instead of READ.
LOOP AT ITAB WHERE KUNNR = '100'.
ENDLOOP.
If you want to use the READ statament u have to read all and stop if the field has the value you want to read:
DO.
READ TABLE ITAB INDEX SY-TABIX.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
IF ITAB-KUNNR = '100'.
ENDIF.
ENDDO.But the performance are very bad for this solution, so LOOP/ENDLOOP is better.
Max
‎2007 May 08 2:44 PM
Hi,
If you want to use the statment READ, then you need to use the perfect condition in the KEY(Where condition of the READ statment), so the perfect value will come . if you have the same records, then use the LOOP AT statment, if you find the correct record then use the EXIT statment to comeout from the LOOP
Regards
Sudheer
‎2007 May 08 2:49 PM
Hi Surendra,
Use Loop ......Endloop command for reading data of an internal table.
Loop at itab where kunnr = '100'.
write: i_tab-kunnr.
endloop.
Reward points if helpful.
Regards,
Hemant
‎2007 May 15 12:06 PM
hi, you shouldn't use loop...endloop especially for larger tables.
you could do this one:
* Sort the table so that the same kunnr's are close together
SORT itab BY kunnr.
* Using BINARY SEARCH will make the code very fast
READ TABLE itab INTO w_itab1 WITH KEY kunnr = '100' BINARY SEARCH.
indx = sy-tabix.
* Now you know where the first entry is, and because you sorted before, all same * entries for kunnr = 100 will be beneath
WHILE sy-subrc = 0.
indx = indx + 1.
READ TABLE itab INTO w_itab2 INDEX indx.
if w_itab2-kunnr <> w_itab-kunnr.
sy-subrc = 99.
else.
* do something
endif.
ENDWHILE.Please reward, if helpful
‎2007 May 15 12:09 PM
hi,
loop at itab where kunnr =100.
read table <itab name> with key kunnr = itab-kunnr.
if sy-subrc = 0.
<statements>.
endif.
endloop.
Reward with points if helpful.