Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

read

Former Member
0 Likes
795

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
772

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

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
772

In this case you should use a LOOP with a WHERE.

Loop at itab where kunnr = '100'.

endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
772

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.

Read only

Former Member
0 Likes
772

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

Read only

Former Member
0 Likes
773

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

Read only

Former Member
0 Likes
772

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

Read only

0 Likes
772

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

Read only

Former Member
0 Likes
772

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.