Application Development 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 statement not working

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

use

READ TABLE gt_mara1 INDEX sy-tabix INTO wa_mara.

instead of using sy-index.

rgds,

bharat.

9 REPLIES 9

Former Member
0 Kudos

Hi

write it as

READ TABLE gt_mara1 INTO wa_mara INDEX sy-index .

Regards

Aditya

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hi,

use

READ TABLE gt_mara1 INDEX sy-tabix INTO wa_mara.

instead of using sy-index.

rgds,

bharat.

0 Kudos

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.

0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

jyotheswar_p2
Active Participant
0 Kudos

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

Former Member
0 Kudos

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.