Business Requirement: - Get the KUNN2 – Customer number of business partner into 0CUSTOMER_ATTR.
KUNN2 filed in the KNVP table
Written 2 types of code
- Normal Select query
- Using For All Entries.
Select the function exit -
EXIT_SAPLRSAP_002 – Master data attribute
Select include program – ZXRSAU02
Double click on the ZXRSAU02
1. NORMAL SELECT QUERY
WHEN'0CUSTOMER_ATTR'.
DATA : WA_DATA TYPE BIW_KNA1_S.
DATA : LV_KUNN2 TYPE KUNN2.
LOOPAT I_T_DATA INTO WA_DATA.
SELECTSINGLE KUNN2 FROM KNVP
INTO LV_KUNN2
WHERE KUNNR = WA_DATA-KUNNR AND
PARVW = 'WE'.
IF SY-SUBRC = 0.
WA_DATA-ZZKUNN2 = LV_KUNN2.
MODIFY I_T_DATA FROM WA_DATA.
CLEAR WA_DATA.
ENDIF.
ENDLOOP.
ENDCASE.
Above code below Performance issues
1. Single inside the loop statement , It will hit the data base for ever single record
2. Remove the select statement for the LOOP and use the SELECT for all entries and dump the data in internal table.
3. Use the READ statement inside the LOOP statement instead of SELECT
4. MODIFY statement inside the loop will degrade the performance.
Replace modify statement with field symbols.
NEW CODE
1. Define filed symbols
WHEN'0CUSTOMER_ATTR'.
FIELD-SYMBOLS : <FS_CUST> TYPE BIW_KNA1_S.
2. Define internal table
TYPES : BEGINOF LS_KNVP,
KUNNR TYPE KUNNR,
KUNN2 TYPE KUNN2,
ENDOF LS_KNVP.
DATA : IT_KNVP TYPESTANDARDTABLEOF LS_KNVP,
WA_KNVP LIKELINEOF IT_KNVP.
3. Define dummy itab to use for all entries statement
DATA : IT_DUMMY TYPESTANDARDTABLEOF BIW_KNA1_S.
IT_DUMMY[] = I_T_DATA[].
IFNOT IT_DUMMY[] ISINITIAL.
SELECT KUNNR KUNN2 FROM KNVP
INTOTABLE IT_KNVP FORALL ENTRIES IN IT_DUMMY
WHERE KUNNR = IT_DUMMY-KUNNR AND
PARVW = 'WE'.
IF SY-SUBRC = 0.
SORT IT_KNVP BY KUNNR.
ENDIF.
ENDIF.
REFRESH IT_DUMMY[].
LOOPAT I_T_DATA ASSIGNING<FS_CUST>.
4. READ statement inside the LOOP
READTABLE IT_KNVP INTO WA_KNVP
WITHKEY KUNNR = <FS_CUST>-KUNNR BINARYSEARCH.
IF SY-SUBRC = 0.
<FS_CUST>-ZZKUNN2 = WA_KNVP-KUNN2.
ENDIF.
CLEAR : WA_KNVP.
ENDLOOP.
RSA Extractor output – 0CUSTOMER_ATTR for last column Customer no business partner number.
Thanks,
Phani.