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 table inside a loop

Former Member
0 Likes
18,627

Hi,

I would like to seek advice on this.

I have 2 internal table as below. The problem is although i have the same set of data in both internal table but

why sy-subrc still returns 4. I found out anln2 map to different ones. Why read table not able to pick the same anln2 even though it has the same value of anln2 in itab2.

LOOP AT it_itab1 INTO wa_itab1.

READ TABLE it_itab2 INTO wa_itab2

WITH KEY glla = wa_itab2-glia

cctrla = wa_itab2-cctria

anln1 = wa_itab2-anln1

anln2 = wa_itab2-anln2.

IF sy-subrc = 0.

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,748

Dear Please check the below code

same as urs but small mofications

>

> Hi,

> I would like to seek advice on this.

> I have 2 internal table as below. The problem is although i have the same set of data in both internal table but

> why sy-subrc still returns 4. I found out anln2 map to different ones. Why read table not able to pick the same anln2 even though it has the same value of anln2 in itab2.

>

> LOOP AT it_itab1 INTO wa_itab1.

> READ TABLE it_itab2 INTO wa_itab2

> WITH KEY glla = wa_itab1-glia

> cctrla = wa_itab2-cctria

> anln1 = wa_itab2-anln1

> anln2 = wa_itab2-anln2.

> IF sy-subrc = 0.

>

>

> Thanks

LOOP AT it_itab1 INTO wa_itab1.
    READ TABLE it_itab2 INTO wa_itab2
                             WITH KEY glla   = wa_itab1-glia
IF sy-subrc = 0.
                                        cctrla = wa_itab1-cctria
                                        anln1  = wa_itab1-anln1
                                        anln2  = wa_itab1-anln2.
  ENDIF.
ENDLOOP.

Thanks

Surendra P

8 REPLIES 8
Read only

Former Member
0 Likes
5,749

Dear Please check the below code

same as urs but small mofications

>

> Hi,

> I would like to seek advice on this.

> I have 2 internal table as below. The problem is although i have the same set of data in both internal table but

> why sy-subrc still returns 4. I found out anln2 map to different ones. Why read table not able to pick the same anln2 even though it has the same value of anln2 in itab2.

>

> LOOP AT it_itab1 INTO wa_itab1.

> READ TABLE it_itab2 INTO wa_itab2

> WITH KEY glla = wa_itab1-glia

> cctrla = wa_itab2-cctria

> anln1 = wa_itab2-anln1

> anln2 = wa_itab2-anln2.

> IF sy-subrc = 0.

>

>

> Thanks

LOOP AT it_itab1 INTO wa_itab1.
    READ TABLE it_itab2 INTO wa_itab2
                             WITH KEY glla   = wa_itab1-glia
IF sy-subrc = 0.
                                        cctrla = wa_itab1-cctria
                                        anln1  = wa_itab1-anln1
                                        anln2  = wa_itab1-anln2.
  ENDIF.
ENDLOOP.

Thanks

Surendra P

Read only

Former Member
0 Likes
5,748

Hello


READ TABLE it_itab2 INTO wa_itab2
WITH KEY glla = wa_itab1-glia " wa_itab1 instead of wa_itab2
cctrla = wa_itab1-cctria
anln1 = wa_itab1-anln1
anln2 = wa_itab1-anln2.

Read only

Former Member
0 Likes
5,748

hi,

cctrla = wa_itab2-cctria

-


> are these the same or sy-subrc = 4 is because of this

and most importantly it must be wa_tab1 in the compare fields...

not wa_tab2

Regards,

Abhijit G. Borkar

Read only

Former Member
5,748

Hi ,

The reason behind the unsucessful READ is that you are having a loop in ITAB1. So in that loop for any READ statement you should use work area of ITAB1 in KEY addition.

Here you are looping in ITAB1 but using the work area of ITAB2 (which is not yet populated) . Hence SY-SUBRC always return the valu 4.

Hope this will help you.

Regards,

Nikhil

Read only

Former Member
0 Likes
5,748
WITH KEY glla = wa_itab2-glia
cctrla = wa_itab2-cctria
anln1 = wa_itab2-anln1
anln2 = wa_itab2-anln2.

change this itab2 in with key to itab1.. how can you read a work area data which is not yet filled??

WITH KEY glla = wa_itab1-glia " i am just making it as itab1 inplace of itab2
cctrla = wa_itab1-cctria
anln1 = wa_itab1-anln1
anln2 = wa_itab1-anln2.

Read only

Former Member
0 Likes
5,748

Hi,

please replace

WITH KEY glla = wa_itab2-glia

cctrla = wa_itab2-cctria

anln1 = wa_itab2-anln1

anln2 = wa_itab2-anln2.

BY

WITH KEY glla = wa_itab1-glia

cctrla = wa_itab1-cctria

anln1 = wa_itab1-anln1

anln2 = wa_itab1-anln2.

The values in wa_itab2 are intial before read. You need to use wa_itab1 which have the values after looping.

Hope it will help you...

Read only

Former Member
0 Likes
5,748

hi,

please see this ..

LOOP AT it_itab1 INTO wa_itab1.
READ TABLE it_itab2 INTO wa_itab2
WITH KEY glla = wa_itab1-glia
cctrla = wa_itab1-cctria
anln1 = wa_itab1-anln1
anln2 = wa_itab1-anln2.
IF sy-subrc = 0.
---
--
endif.
endloop.

thanks

Read only

Former Member
0 Likes
5,748

it's just your spelling mistake