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

internal table read

Former Member
0 Likes
562

Hi

I am reading an internal table twice in a single go. I am getting the first and the second record as obvious while executing the perform once.

What I need to do is, if I read the table in the next go or I execute the perform again, I should get the record third and fourth as a result.

The code is something like this:

Do 2 times.

Perform ABC -> Reads table once and gets the first record.

Perform XYZ -> Reads table once more and gets the second record.

Enddo.

Can anyone suggest logic for this.

Point will be rewarded for the correct logic.

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
543

I am not pretty clear with your requirement but here is a pseudo logic.

clear l_counter.

Do 2 times.

l_counter = l_counter + 1.

Perform ABC -> Reads table once and gets the first record.

l_counter = l_counter + 1.

Perform XYZ -> Reads table once more and gets the second record.

Enddo.

In first DO Loop pass, L_COUTER will be 1, perform ABC will read first record, then counter will value will be 2 and XYZ will read second record.

In the next loop pass, counter will become 3 and ABC will read third record. Then Counter will become 4 and XYZ will read 4th record.

Make sure in PERFORM ABC and XYZ you use COUNTER while reading internal table.

6 REPLIES 6
Read only

abdulazeez12
Active Contributor
0 Likes
543

Hi Vishal-

It depends on what code you have written in Performs..Can you send the complete code so that I can help you out??

Cheers

Read only

former_member189629
Active Contributor
0 Likes
543

Vishal,

Use sy-tabix to direct your READs..

Read only

Former Member
0 Likes
543

Try using a static var.

Statics: l_stat.

read table xyz index l_stat. " incrment l_stat

read table xyz index l_stat.

Read only

Former Member
0 Likes
544

I am not pretty clear with your requirement but here is a pseudo logic.

clear l_counter.

Do 2 times.

l_counter = l_counter + 1.

Perform ABC -> Reads table once and gets the first record.

l_counter = l_counter + 1.

Perform XYZ -> Reads table once more and gets the second record.

Enddo.

In first DO Loop pass, L_COUTER will be 1, perform ABC will read first record, then counter will value will be 2 and XYZ will read second record.

In the next loop pass, counter will become 3 and ABC will read third record. Then Counter will become 4 and XYZ will read 4th record.

Make sure in PERFORM ABC and XYZ you use COUNTER while reading internal table.

Read only

Former Member
0 Likes
543

make use of LOOP statement instead of READ statement

count = 0.

loop at itab where field = value.

count = count + 1.

if count = 3.

itab3 = itab.

elseif count = 4.

itab4 = itab.

endif.

endloop.

Read only

Former Member
0 Likes
543

But a read statement always returns first statement satisfying the criteria then its always going to return the same record for the same selection criteria.

Better keep a counter for the index no to be read.