Skip to Content
Technical Articles

SAP ECC CRM Interface BADI Implementation

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 LENGTH 14.
GTIN_DATA CS_PRODUCT_BDOCDATA.
IT_GTIN[] GTIN_DATACOMM_PR_GTIN[].
SELECT FROM COMM_PRODUCT AS P INNER JOIN COMM_PR_GTIN AS 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_GTINPRODUCT_GUID.
LOOP AT CS_PRODUCT_BDOCDATACOMM_PR_GTIN into WA_GTIN.
IF WA_GTINUNIT_OF_MEASURE ‘CS’.
READ TABLE IT_PROD INTO WA_PROD WITH KEY PRODUCT_GUID WA_GTINPRODUCT_GUID.
IF SYSUBRC EQ 0.
CALL METHOD ME->GET_NEWGTIN
EXPORTING
EX_PRODID  WA_PRODPRODUCT_ID
IMPORTING
IM_GTIN    lv_gtin.

WA_GTINGTIN lv_gtin.
MODIFY CS_PRODUCT_BDOCDATACOMM_PR_GTIN FROM WA_GTIN.
ENDIF.
ELSE.
READ TABLE CS_PRODUCT_BDOCDATACOMM_PR_GTIN into WA_GTIN WITH KEY dataUNIT_OF_MEASURE ‘CS’.
IF sysubrc eq 0.
READ TABLE IT_PROD INTO WA_PROD WITH KEY PRODUCT_GUID WA_GTINPRODUCT_GUID.
IF SYSUBRC EQ 0.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
INPUT        WA_PRODPRODUCT_ID
IMPORTING
OUTPUT        lv_gtin.
WA_GTINGTIN lv_gtin.
MODIFY CS_PRODUCT_BDOCDATACOMM_PR_GTIN FROM WA_GTIN.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT CS_PRODUCT_BDOCDATACOMM_PR_GTIN INTO WA_GTIN_Y“ASSIGNING <GTIN>..
WA_GTIN_YDATA_XGTIN ‘X’.
WA_GTIN_YUPDATE_TYPE ‘U’.
MODIFY CS_PRODUCT_BDOCDATACOMM_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.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.