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

problem with read statement

Former Member
0 Likes
1,762

Hi experts,

i ahve a problem with read statement. i have put the read statement in the loop but it always reads the 1st record.. please help me guys..

if u need my code..i shall paste it here..

Regards ,

Sunita.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,648

please paste the code..

thanks

13 REPLIES 13
Read only

Former Member
0 Likes
1,649

please paste the code..

thanks

Read only

0 Likes
1,648

use this syntax if u are using read statement inside the loop.

read table itab index sy-tabix.

if u are using inside loop it will get all records

Read only

0 Likes
1,648

mibght be:

loop at a into wa.

read table b into wb with key (field of b) = wa-field of a

endloop.

now problemmight be that in tab a there might be multiple recors containing a..so when you do read on b it will retrieve you first recod of b based on condition ..so always you gettin same record

Read only

0 Likes
1,648

hi experts,

loop at it_trip.
    READ TABLE it_ptrv_head  WITH KEY  pernr  = it_trip-pernr.
READ TABLE it_ptrv_srec WITH KEY pernr = it_ptrv_head-pernr.
    READ TABLE it_ptrv_sadd WITH KEY pernr = it_ptrv_srec-pernr.
endloop.

so can u now tell me y it always reads only 1st record .

regards,

sunita.

Read only

0 Likes
1,648

can you be more elaborate...which read is giving you first record ..what is your expected result?

and after each read where are you passing the value..

if you are using the read data after end loop..then you will get single record only....

and every read..plz dont forget to put sy-subrc check..you might have empty internal table in between

Read only

0 Likes
1,648

Hi,

Use work area to read all of your records,

DATA : wa_trip like line of it_trip .

loop at it_trip into wa_trip .

READ TABLE it_ptrv_head WITH KEY pernr = wa_trip-pernr.

endloop.

similarly rread all your records inside the loop.hope this will helps you,if you want more help send all of your code.

Regds,

Sree.

Read only

0 Likes
1,648

Hi,

Can you show your full code?

You are using 3 Read statement in this loop. In which read statement you want to capture the data?

Thanks.

Read only

0 Likes
1,648

Hi,

Change with the following i think you will find the problem i think some of you internal table have no pernr..

and you are not Checking sy-subrc so facing such problem.

LOOP AT it_trip.
  READ TABLE it_ptrv_head  WITH KEY pernr  = it_trip-pernr.
  IF sy-subrc = 0.
    READ TABLE it_ptrv_srec WITH KEY pernr = it_ptrv_head-pernr.
    IF sy-subrc = 0.
      READ TABLE it_ptrv_sadd WITH KEY pernr = it_ptrv_srec-pernr.
      IF sy-subrc = 0.
      ENDIF.
    ENDIF.
  ENDIF.
ENDLOOP.

kind Regards.

Faisal

Edited by: Faisal Altaf on Feb 8, 2009 12:17 PM

Read only

0 Likes
1,648

Hi Sunita,

Please check the table entries of it_trip, if the pernr field in that table has the same value for every record, if so then it will always show you the first record, or check if the last record of it_trip pernr field matches the first record in that case as the loop ends it will show you the first record.

Regards,

Siddarth

Read only

Former Member
0 Likes
1,648

hi,

the read statemnet will get the first successful record based on tyeh key.Suppose for the same key 2 0r 3 records are there,then always the first successful record will be returned.in ur case may be the first record itself satisfying the key.

Read only

faisalatsap
Active Contributor
0 Likes
1,648

Hi,

are you using Index or table key ?

Kind Regards,

Faisal

Edited by: Faisal Altaf on Feb 8, 2009 11:48 AM

Read only

shishupalreddy
Active Contributor
0 Likes
1,648

Hello Sunitha ,

Loop at itab .

read table jtab { with key f1 = itab-f1 } OR index sy-tabix .

Endloop.

This will fetch as per the access to the JTAB table data .

If u r still facing the problem please paste u r code.

Regardss

Read only

Former Member
0 Likes
1,648

hi Sunitha,

Besides checking the return code..

loop at it_trip.

READ TABLE it_ptrv_head WITH KEY pernr = it_trip-pernr.

READ TABLE it_ptrv_srec WITH KEY pernr = it_ptrv_head-pernr.

READ TABLE it_ptrv_sadd WITH KEY pernr = it_ptrv_srec-pernr.

write:/ it_ptrv_head-pernr,

it_ptrv_srec-pernr,

it_ptrv_sadd-pernr,

endloop.

Regards,

Mdi.Deeba