03-25-2008 7:05 AM
Hi All,
I am using Read statement with sy-index as follows but it is not working, please help and let me know where i am going wrong.
LOOP AT gt_zrb_tb_x_plnt_st INTO wa_zrb_tb_x_plnt_st.
READ TABLE gt_mara1 INDEX sy-index INTO wa_mara.
IF wa_mara-mstae NE wa_zrb_tb_x_plnt_st-mstae.
CALL FUNCTION 'MARA_SINGLE_READ'
EXPORTING
matnr = wa_mara-matnr
sperrmodus = 'E'
IMPORTING
wmara = gt1_mara
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP.
03-25-2008 7:10 AM
Hi,
use
READ TABLE gt_mara1 INDEX sy-tabix INTO wa_mara.
instead of using sy-index.
rgds,
bharat.
03-25-2008 7:08 AM
Hi
write it as
READ TABLE gt_mara1 INTO wa_mara INDEX sy-index .
Regards
Aditya
03-25-2008 7:09 AM
Are you sure both have the same number of records and in the same order??? Alternatively you might try using key fields something like MATNR in your case.
03-25-2008 7:10 AM
Hi,
use
READ TABLE gt_mara1 INDEX sy-tabix INTO wa_mara.
instead of using sy-index.
rgds,
bharat.
03-25-2008 7:32 AM
Hi Bharat,
Your answer has solved my problem but can you please explain me the difference between sy-index and sy-tabix. How it works?
Thanks.
Sunanda.
03-25-2008 7:35 AM
Hi,
sy-index will give u current iteration number in do...enddo,while...endwhile,...
sy-tabix will give u the table index number(i.e,the number of record u r currently working with)
rgds,
bharat.
03-25-2008 7:13 AM
Hi,
Change your read statement and check.
READ TABLE gt_mara1 INTO wa_mara INDEX sy-tabix.
IF SY-SUBRC = 0.
WRITE:/ 'success'.
else.
WRITE:/ 'unable to read'.
endif.
sy-tabix is related to internal tables(default value 1),
sy-index is related to loop at itab-endloop statements.
Regards,
Chandu.
03-25-2008 7:14 AM
Hi
You can use
READ TABLE gt_mara1 INTO wa_mara index sy-index.
but this sequence must same as the your main itab
or you can with key
READ TABLE gt_mara1 INTO wa_mara with key matnr = wa_zrb_tb_x_plnt_st-matnr
binary search.'
regards
shiva
03-25-2008 7:15 AM
hi sunanda,
1.Wht is the error it is showing.
2.If the sy subrc is failing then the the table gt_mara1 might not be having any data .If it has data then please check the sy-index in debugging check how many records the table is having and compare them.
regards
jyo
03-25-2008 7:18 AM
Hi,
If your requirement is to read the itab gt_mara1 bsed on the loop count, use sy-tabix instead of sy-index. Sy-tabix gives the loop count.