Hi experts,
I would like to read the most recent entry from an internal table itab based on a condition.
Let’s assume the table looks like this and is sorted by the field Timestamp:
Flag | Timestamp (DD-MM-YYYY HH:MM:SS) |
A | 01-03-2024 12:00:00 |
C | 01-03-2024 11:00:00 |
A | 29-02-2024 15:27:00 |
B | 29-02-2024 14:13:00 |
A | 28-02-2024 10:00:00 |
I would like to fetch the most recent entry for which Flag is either B or C and I know that a possible solution would be to loop through the table:
IF wa-flag = ‘B’ or wa-flag = ‘C’.
EXIT.
ENDIF.
ENDLOOP.
* Continue processing using wa
However, since I am already perfoming this opration in a nested loop, I would like to avoid adding another loop to the logic.
I also found solutions suggesting to use READ TABLE statements for each of the conditions, but they so not seem to be applicable in the situation described above:
Are there any alternatives to looping through the entire table to fetch the most recent entry for which Flag is either B or C? Would SELECT – FROM @itab for example be a valid and recommended approach in this situation?
I’d highly appreciate any thoughts and suggestions in this regard.