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 in Read statement in loop

former_member267445
Participant
0 Likes
1,388

Dear Guru's

I have a problem in read statement in loop. Let us say i have 10 records in internal table say it_vbap. I am populating the values using loop. in that loop i am reading the same it_vbap for some logic.

For 1st iteration data is coming in proper way, for 2nr iteration also data is coming. For 3rd iteration i am comparing with 2nd record's value and if it is satisfy then i am reading 2nd record for some data. So here after printing 2nd record values i have to print 3rd record and continuously but here i am getting 2nd record values and jumps into 4th record values.

I am missing 3rd record values. Please help me how to resolve this.

Thanks and Regards

Muralikrishna Peravali

1 ACCEPTED SOLUTION
Read only

gouravkumar64
Active Contributor
0 Likes
1,299

Are you using loop condition based on some condition?

Can you paste your code of this part?

11 REPLIES 11
Read only

gouravkumar64
Active Contributor
0 Likes
1,300

Are you using loop condition based on some condition?

Can you paste your code of this part?

Read only

0 Likes
1,299

Hi Kumar,

Thank you for reply.

 

Read only

Former Member
0 Likes
1,299

I hope you are using INDEX to fetch data from your table. that should work fine, post your code in case it is not.

If you are using WITH KEY for the inner read table, you will always get first record that satisfies the criteria.

Read only

0 Likes
1,299

Hi Chinmay,

I am not using the index to fetch the data. Please find the attachment so that you will know

Thanks and Regards,

Muralikrishna

Read only

former_member186491
Contributor
0 Likes
1,299

Hi Muralikrishna,

It seems this is is a prbolem of handling Index.

Once you process one record, your Index must have been incremented by then and perhaps for that reason you might be loosing your 3rd Record to be displayed.

Check from that angle too.

Thanks.

Kumar Saurav.

Read only

0 Likes
1,299

Hi Saurav,

I am not using index in loop.

Read only

Former Member
0 Likes
1,299

You can use like this

Loop at it_tab into wa_itab.

lv_index = sy-tabix + 1.

Read table it_tab with key lv_index.  '2nd entry

regards,

Lokesh

Read only

0 Likes
1,299

Every READ statement will set the following system variables ( and many more )

 

SY-INDEX   - Contains the number of loop passes, including the current loop pass

SY-TABIX   - Current row index

 

Since you have used, READ TABLE with KEY, you cannot guarantee that the records will be read in sequence and I believe this is the issue.

 

If you want to check / compare data in internal tables, you can use the option COMPARING / TRANSPORTING NO FIELDS. If you specify NO FIELDS, no fields are transported this statement only fills the system fields sy-subrc and sy-tabix.

Pseudo code:

LOOP AT itab into wa.

    READ TABLE itab1 INTO wa1 WITH KEY aaaa = wa-bbbb. 

    

    READ TABLE itab2 INTO wa2 WITH KEY cccc = wa-1-aaaa.  <<< SY-TABIX will change again

 

ENDLOOP.

Regards,

Shyam

Read only

former_member267445
Participant
0 Likes
1,299

Hi All,

Thankyou for your informations. But my self resolve the issue. Thank you for all supports

Read only

0 Likes
1,299

If you solve by yourself, then how do you solve the issue? Post here your solution for future reference of other SCN member. Lastly, don't forget to close this thread.

Jake

Read only

0 Likes
1,299

how you resolved this issue i am also facing the same problem kindly help me to resolved this issue??????