Hello Roel,
pls use below code , where i am using looping but based index so it will not hamper performance.(parallel cursor method)
*******************************************************************************
DATA :lv_index LIKE sy-index.
SORT RESUL_PACKAGE BY 0REF_DOC_NR 0REF_DOC_IT 0REF_DOC_AA ZOBJNR .
lv_index = 0.
LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELLDS> FROM lv_index WHERE ZOBJNR = 'KS%' . "
lv_index = lv_index + 1.
LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELLDS_1>
FROM lv_index
WHERE 0REF_DOC_NR = <RESULT_FIELLDS>-0REF_DOC_NR AND
0REF_DOC_IT = <RESULT_FIELLDS>-0REF_DOC_IT AND
0REF_DOC_AA = <RESULT_FIELLDS>-0REF_DOC_AA AND
ZOBJNR = 'OR%'.
*****all below code it to copy forst 10 digits for object number
*****so suppose if you have value KS1234567890
*****then first you replace KS1234567890 with 001234567890 (KS replaced by 00) as mentioned ****** below
replace all occurrences of 'KS' in <RESULT_FIELLDS>-RESULT_FIELD_OBJNR with '00' .
******then replace all 00 if any using below code
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = <RESULT_FIELLDS>-RESULT_FIELD_OBJNR
IMPORTING
OUTPUT = <RESULT_FIELLDS>-RESULT_FIELD_OBJNR .
****** copy first 10 digits into result fields
<RESULT_FIELLDS_1>-RESULT_FIELD_OBJNR = <RESULT_FIELLDS>-RESULT_FIELD_OBJNR+0(10).
ENDLOOP.
ENDLOOP.
***************************************************************************************
may require minor changes.. sit with abaper or let me know in case of any issues.
1) In above code we first sorted Result_package base on fields 0REF_DOC_NR 0REF_DOC_IT 0REF_DOC_AA ZOBJNR.
due to this for a combination of fields 0REF_DOC_NR 0REF_DOC_IT 0REF_DOC_AA , we get ZOBJNR fields always first field starting with 'KS********'
2) we search other records in internal table with same ref doc number, item no & accounting no... and ZOBJNR should be starting with OR*****
If we found any combination then we copy object number .....
Regards,
Hitesh