In this Blog you will learn how to implement the BADI
PRODUCT_CUSTOMER2 (Customer Implementations for Data Import). This BADI gets triggered at the interface data exchange from ECC to CRM.
Below is the scenario where we change the GTIN number of a product by deriving it from custom logic and use it instead of the one passed from ECC.
BADI method MAP_R3_TO_CRM_MATERIAL (Mapping of Material Master Data to Generic Set Types)
This method is used to build custom logic for any data changes during the data exchange.
Method has a deep structure changing parameter
CS_PRODUCT_BDOC Changing COMT_PROD_MATERIAL_BDOC it has all the product related data which can be changed.
Step1: Implement the BADI with a ZXYZ name in SE18 Tcode by clicking one the create implementation as given below.
Step2: Double click on the method MAP_R3_TO_CRM_MATERIAL and give your custom code as give below for my scenario.
method IF_EX_PRODUCT_CUSTOMER2
~MAP_R3_TO_CRM_MATERIAL
.
*PARAMETERS***************************************************************************************
*IS_MARA TYPE CRMS_BAPIMATMRA BAPI CRS Structure for MARA (Material)
*IT_MAKT TYPE BAPIMATMKT_TAB Table of BAPI CRS Structure for MAKT (Material)
*IT_MARM TYPE BAPIMATMRM_TAB Table of BAPI CRS Structure for MARM (Material)
*IT_MARC TYPE BAPIMATMRC_TAB Table of BAPI CRS Structure for MARC (Material)
*IT_MARD TYPE BAPIMATMRD_TAB Table of BAPI CRS Structure for MARD (Material)
*IT_MVKE TYPE BAPIMATMVK_TAB Table of BAPI CRS Structure for MVKE (Material)
*IT_MLAN TYPE BAPIMATMLN_TAB Table of BAPI Structure for MLAN - Material Tax Classif.
*IT_MEAN TYPE BAPIMATMEN_TAB Table of BAPI Structure for MEAN
*IT_MBEW TYPE BAPIMATMBW_TAB Table of BAPI Structure for MBEW
*IT_LONGTEXT TYPE COMT_PRLGTEXT_MAINTAIN_TAB Table of BAPI CRS Structure for STXH (SAPscript Text)
*IT_OTHER_INFO TYPE CND_MAPTT_BAPI_OTHER_INFO TT for BAPIEXTC
*EV_ERROR TYPE COMT_BOOLEAN Logical Variable
*ET_BAPIRETURN TYPE BAPIRET2_TAB Error Messages
*CS_PRODUCT_BDOC TYPE COMT_PROD_MATERIAL_BDOC API Material Data Structure
*PARAMETERS***************************************************************************************
TYPES:
BEGIN OF TY_PROD_1
,
PRODUCT_GUID
Type COMT_PRODUCT_GUID
,
GTIN_GUID
Type COMT_GTIN_GUID
,
UNIT_OF_MEASURE
Type COMT_UNIT
,
GTIN
Type COMT_GTIN
,
GTIN_TYPE
Type COMT_GTIN_TYPE
,
MAIN_GTIN
Type COMT_MAIN_GTIN
,
PRODUCT_ID
TYPE COMT_PRODUCT_ID
,
END OF TY_PROD_1
.
DATA:
GTIN_DATA
TYPE COMT_PROD_MAT_MAINTAIN_API
,
IT_GTIN
TYPE TABLE OF COMT_PR_GTIN
,
WA_GTIN
LIKE LINE OF IT_GTIN
,
WA_GTIN_Y
TYPE COMT_PR_GTIN_MAINTAIN
,
V_PROD_ID
TYPE COMT_PRODUCT_ID
,
IT_PROD
TYPE TABLE OF TY_PROD_1
,
WA_PROD
LIKE LINE OF IT_PROD
,
lv_gtin
TYPE c LENGTH
14.
GTIN_DATA
= CS_PRODUCT_BDOC
-DATA.
IT_GTIN[]
= GTIN_DATA
-COMM_PR_GTIN[]
.
SELECT *
FROM COMM_PRODUCT
AS P INNER
JOIN COMM_PR_GTIN
AS G
ON G
~PRODUCT_GUID
= P
~PRODUCT_GUID
INTO CORRESPONDING
FIELDS OF TABLE IT_PROD
FOR ALL ENTRIES
IN IT_GTIN
WHERE P
~PRODUCT_GUID
= IT_GTIN
-PRODUCT_GUID
.
LOOP AT CS_PRODUCT_BDOC
-DATA-COMM_PR_GTIN
into WA_GTIN
.
IF WA_GTIN
-UNIT_OF_MEASURE
= 'CS'.
READ TABLE IT_PROD
INTO WA_PROD
WITH KEY PRODUCT_GUID
= WA_GTIN
-PRODUCT_GUID
.
IF SY
-SUBRC
EQ 0.
CALL METHOD ME
->GET_NEWGTIN
EXPORTING
EX_PRODID
= WA_PROD
-PRODUCT_ID
IMPORTING
IM_GTIN
= lv_gtin
.
WA_GTIN
-GTIN
= lv_gtin
.
MODIFY CS_PRODUCT_BDOC
-DATA-COMM_PR_GTIN
FROM WA_GTIN
.
ENDIF.
ELSE.
READ TABLE CS_PRODUCT_BDOC
-DATA-COMM_PR_GTIN
into WA_GTIN
WITH KEY data-UNIT_OF_MEASURE
= 'CS'.
IF sy
-subrc
eq 0.
READ TABLE IT_PROD
INTO WA_PROD
WITH KEY PRODUCT_GUID
= WA_GTIN
-PRODUCT_GUID
.
IF SY
-SUBRC
EQ 0.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_PROD
-PRODUCT_ID
IMPORTING
OUTPUT = lv_gtin
.
WA_GTIN
-GTIN
= lv_gtin
.
MODIFY CS_PRODUCT_BDOC
-DATA-COMM_PR_GTIN
FROM WA_GTIN
.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT CS_PRODUCT_BDOC
-DATA-COMM_PR_GTIN
INTO WA_GTIN_Y
. "ASSIGNING <GTIN>..
WA_GTIN_Y
-DATA_X
-GTIN
= 'X'.
WA_GTIN_Y
-UPDATE_TYPE
= 'U'.
MODIFY CS_PRODUCT_BDOC
-DATA-COMM_PR_GTIN
FROM WA_GTIN_Y
.
ENDLOOP.
endmethod.
By following above steps we can implement the BADI to change interface data and learn how to implement deep structure changes as well.