Ok, let's try another explanation.
You are selection AFRU by LTXA1 = CHARG.
Probably in any point AFRU-LTXA1 is filled with CHARG. But LTXA1 is a text field without index, and a search by it can be very bad.
So, let's try to get this charg in another way, and then select AFRU by it's index field RUECK.
We can start selection all orders that have CHARG meeting our conditions.
Select *
from AFPO
into IT_AFPO
for all entries in git_mseg_conv
where CHARG = git_mseg_conv-charg.
" For now we have all orders with your batchs (CHARG).
Select *
from AFKO
into IT_AFKO
for all entries in IT_AFPO
where AUFNR = IT_AFPO-AUFNR and
WERKS = p_werks.
" Now we all orders filtered by werks too
Select *
from afvc
into IT_AFVC
for all entries in IT_AFPO
where AUFPL = IT_AFPO-AUFPL.
" Now we have all operations that match CHARG and WERKS parameters
Select *
from AFRU
into IT_AFRU
for all entries in IT_AFVC
where RUECK = IT_AFVC-RUECK.
" Now, we should get the same results you need. All Confirmations that match initial CHARG and WERKS.
But in this scenario, we used most key fields, and all search have been doing with few entries each time we go forward.
Hope it helps,
Frisoni