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

Former Member
0 Likes
2,474

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
Read only

Former Member
0 Likes
1,713

Hi,

use

READ TABLE gt_mara1 INDEX sy-tabix INTO wa_mara.

instead of using sy-index.

rgds,

bharat.

9 REPLIES 9
Read only

Former Member
0 Likes
1,713

Hi

write it as

READ TABLE gt_mara1 INTO wa_mara INDEX sy-index .

Regards

Aditya

Read only

Former Member
0 Likes
1,713

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.

Read only

Former Member
0 Likes
1,714

Hi,

use

READ TABLE gt_mara1 INDEX sy-tabix INTO wa_mara.

instead of using sy-index.

rgds,

bharat.

Read only

0 Likes
1,713

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.

Read only

0 Likes
1,713

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.

Read only

Former Member
0 Likes
1,713

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.

Read only

Former Member
0 Likes
1,713

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

Read only

jyotheswar_p2
Active Participant
0 Likes
1,713

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

Read only

Former Member
0 Likes
1,713

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.