‎2007 Oct 01 7:10 AM
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
‎2007 Oct 01 7:15 AM
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.
‎2007 Oct 01 7:14 AM
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
‎2007 Oct 01 7:14 AM
‎2007 Oct 01 7:14 AM
Try using a static var.
Statics: l_stat.
read table xyz index l_stat. " incrment l_stat
read table xyz index l_stat.
‎2007 Oct 01 7:15 AM
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.
‎2007 Oct 01 7:16 AM
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.
‎2007 Oct 01 7:19 AM
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.