SAP hana官方推荐的创建bp主数据的类是CL_MD_BP_MAINTAIN
客户的创建具体示例代码如下:
代码语言:javascript复制 DATA: LT_RETURN_MAP TYPE MDG_BS_BP_MSGMAP_T.
DATA: LS_RETURN_MAP TYPE MDG_BS_BP_MSGMAP.
DATA: LS_MESSAGE_MAP TYPE MDG_BS_BP_MSGMAP_KEY.
DATA: LT_DATA TYPE CVIS_EI_EXTERN_T,
LT_RETURN TYPE BAPIRETM,
LS_RETURN TYPE BAPIRETI,
LS_RETMSG TYPE LINE OF BAPIRETCT,
LV_TEXT TYPE STRING.
DATA: LS_DATA LIKE LINE OF LT_DATA,
LS_ROLE TYPE BUS_EI_BUPA_ROLES,
LS_PAADR TYPE BUS_EI_BUPA_ADDRESS,
LS_COMPANY TYPE CMDS_EI_COMPANY.
DATA: LV_GUID TYPE GUID_32,
LV_PARTNER LIKE LS_DATA-PARTNER-HEADER-OBJECT_INSTANCE-BPARTNER.
DATA: LS_FUNCTIONS_ST TYPE CMDS_EI_FUNCTIONS,
LS_FUNCTIONS_T TYPE CMDS_EI_FUNCTIONS_T,
LS_FUNCTIONS TYPE CMDS_EI_CMD_FUNCTIONS,
LS_SALES_DATA_ST TYPE CMDS_EI_SALES,
LS_SALES_DATA TYPE CMDS_EI_CMD_SALES.
DATA: LS_PHONE TYPE BUS_EI_BUPA_TELEPHONE.
DATA: LT_PHONE TYPE BUS_EI_BUPA_TELEPHONE_T.
DATA: LS_FAX TYPE BUS_EI_BUPA_FAX.
DATA: LT_FAX TYPE BUS_EI_BUPA_FAX_T.
DATA: LS_MAIL TYPE BUS_EI_BUPA_SMTP.
DATA: LT_MAIL TYPE BUS_EI_BUPA_SMTP_T.
DATA: LS_TAX TYPE CMDS_EI_TAX_IND.
DATA: LT_TAX TYPE CMDS_EI_TAX_IND_T.
DATA: LS_SEGMENTS TYPE UKM_EI_BP_CMS_SGM.
DATA: LS_PROFILE TYPE UKM_EI_BP_CMS.
LOOP AT GT_CUSTOMER INTO GS_CUSTOMER WHERE KUNNR IS INITIAL .
CLEAR: LT_RETURN_MAP,
LS_RETURN_MAP,
LS_MESSAGE_MAP,
LT_DATA,
LT_RETURN,
LS_RETURN,
LS_RETMSG,
LV_TEXT,
LS_DATA,
LS_ROLE,
LS_PAADR,
LS_COMPANY,
LV_GUID,
LV_PARTNER,
LS_FUNCTIONS_ST,
LS_FUNCTIONS_T,
LS_FUNCTIONS,
LS_SALES_DATA_ST,
LS_SALES_DATA,
LS_PHONE,
LT_PHONE,
LS_FAX,
LT_FAX,
LS_MAIL,
LT_MAIL,
LS_TAX,
LT_TAX,
LS_SEGMENTS,
LS_PROFILE.
CALL METHOD CL_SYSTEM_UUID=>IF_SYSTEM_UUID_STATIC~CREATE_UUID_C32
RECEIVING
UUID = LV_GUID.
* Create customer
LS_DATA-PARTNER-HEADER-OBJECT_TASK = 'I'.
LS_DATA-PARTNER-HEADER-OBJECT_INSTANCE-BPARTNER = LV_PARTNER.
LS_DATA-PARTNER-HEADER-OBJECT_INSTANCE-BPARTNERGUID = LV_GUID.
*--- Partner / Central data / common ------------------------------*
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CONTROL-CATEGORY = '2'. "3group "2 Organization
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CONTROL-GROUPING = GS_CUSTOMER-BU_GROUP. "Grouping
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-TITLE_KEY = GS_CUSTOMER-AD_TITLE. "tittle
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-SEARCHTERM1 = GS_CUSTOMER-SORT1 0(20). "Search term 1 for business partner
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-SEARCHTERM2 = GS_CUSTOMER-SORT1 20(20). "Search term 2 for business partner
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_CENTRALDATA-TITLE_KEY = ABAP_TRUE.
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_CENTRALDATA-SEARCHTERM1 = ABAP_TRUE.
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_CENTRALDATA-SEARCHTERM2 = ABAP_TRUE.
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME1 = GS_CUSTOMER-NAME1 0(35).
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME2 = GS_CUSTOMER-NAME1 35(35).
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_ORGANIZATION-NAME1 = ABAP_TRUE.
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_ORGANIZATION-NAME2 = ABAP_TRUE.
*--- Partner / Central data / Address -----------------------------*
LS_PAADR-TASK = 'I'.
LS_PAADR-DATA_KEY-OPERATION = 'XXDFLT'.
LS_PAADR-DATA-POSTAL-DATA-STR_SUPPL3 = GS_CUSTOMER-UNIT.
LS_PAADR-DATA-POSTAL-DATA-CITY = GS_CUSTOMER-CITY1.
LS_PAADR-DATA-POSTAL-DATA-HOUSE_NO = GS_CUSTOMER-HOUSE_NUM1.
LS_PAADR-DATA-POSTAL-DATA-POSTL_COD1 = GS_CUSTOMER-POST_CODE1.
LS_PAADR-DATA-POSTAL-DATA-STREET = GS_CUSTOMER-STREET.
LS_PAADR-DATA-POSTAL-DATA-COUNTRY = GS_CUSTOMER-LAND1.
LS_PAADR-DATA-POSTAL-DATA-REGION = GS_CUSTOMER-REGIO.
LS_PAADR-DATA-POSTAL-DATA-TIME_ZONE = GS_CUSTOMER-TIME_ZONE.
LS_PAADR-DATA-POSTAL-DATA-LANGU = GS_CUSTOMER-LANGU.
LS_PAADR-DATA-POSTAL-DATAX-STR_SUPPL3 = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-CITY = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-HOUSE_NO = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-POSTL_COD1 = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-STREET = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-COUNTRY = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-REGION = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-TIME_ZONE = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-LANGU = ABAP_TRUE.
LS_PAADR-CURRENTLY_VALID = ABAP_TRUE.
" Communication
IF GS_CUSTOMER-TEL_NUMBER IS NOT INITIAL .
*第一个电话
LS_PHONE-CONTACT-TASK = 'I'.
LS_PHONE-CONTACT-DATA-COUNTRY = GS_CUSTOMER-LAND1.
LS_PHONE-CONTACT-DATA-TELEPHONE = GS_CUSTOMER-TEL_NUMBER.
LS_PHONE-CONTACT-DATAX-COUNTRY = 'X'.
LS_PHONE-CONTACT-DATAX-TELEPHONE = 'X'.
APPEND LS_PHONE TO LT_PHONE.
LS_PAADR-DATA-COMMUNICATION-PHONE-PHONE = LT_PHONE.
ENDIF.
IF GS_CUSTOMER-FAX_NUMBER IS NOT INITIAL .
*传真
LS_FAX-CONTACT-TASK = 'I'.
LS_FAX-CONTACT-DATA-COUNTRY = GS_CUSTOMER-LAND1.
LS_FAX-CONTACT-DATA-FAX = GS_CUSTOMER-FAX_NUMBER.
LS_FAX-CONTACT-DATAX-COUNTRY = 'X'.
LS_FAX-CONTACT-DATAX-FAX = 'X'.
APPEND LS_FAX TO LT_FAX.
LS_PAADR-DATA-COMMUNICATION-FAX-FAX = LT_FAX.
ENDIF.
IF GS_CUSTOMER-SMTP_ADDR IS NOT INITIAL .
**电子邮件
LS_MAIL-CONTACT-TASK = 'I'.
LS_MAIL-CONTACT-DATA-E_MAIL = GS_CUSTOMER-SMTP_ADDR.
LS_MAIL-CONTACT-DATAX-E_MAIL = 'X'.
APPEND LS_MAIL TO LT_MAIL.
LS_PAADR-DATA-COMMUNICATION-SMTP-SMTP = LT_MAIL.
ENDIF.
APPEND LS_PAADR TO LS_DATA-PARTNER-CENTRAL_DATA-ADDRESS-ADDRESSES.
*----------------- PARTNER / CENTRAL DATA / ROLE -----------------*
*-------------- Adding multiple roles for the BP------------------*
*-------------- Partner / Central data / role --------------------*
LS_ROLE-TASK = 'I'.
LS_ROLE-DATA_KEY = 'GZ0001'.
LS_ROLE-DATA-ROLECATEGORY = 'FLCU01'.
LS_ROLE-DATA-VALID_FROM = SY-DATUM.
LS_ROLE-DATA-VALID_TO = '99991231'.
LS_ROLE-CURRENTLY_VALID = ABAP_TRUE.
LS_ROLE-DATAX-VALID_FROM = ABAP_TRUE.
LS_ROLE-DATAX-VALID_TO = ABAP_TRUE.
APPEND LS_ROLE TO LS_DATA-PARTNER-CENTRAL_DATA-ROLE-ROLES.
LS_DATA-PARTNER-CENTRAL_DATA-ROLE-CURRENT_STATE = ABAP_TRUE.
*------------- Partner / Central data / role ---------------------*
LS_ROLE-TASK = 'I'.
LS_ROLE-DATA_KEY = 'GZ0002'.
LS_ROLE-DATA-ROLECATEGORY = 'FLCU00'.
LS_ROLE-DATA-VALID_FROM = SY-DATUM.
LS_ROLE-DATA-VALID_TO = '99991231'.
LS_ROLE-CURRENTLY_VALID = ABAP_TRUE.
LS_ROLE-DATAX-VALID_FROM = ABAP_TRUE.
LS_ROLE-DATAX-VALID_TO = ABAP_TRUE.
APPEND LS_ROLE TO LS_DATA-PARTNER-CENTRAL_DATA-ROLE-ROLES.
LS_DATA-PARTNER-CENTRAL_DATA-ROLE-CURRENT_STATE = ABAP_TRUE.
*Credit limit
*----------------- Partner / UKMBP_DATA -----------------*
LS_ROLE-TASK = 'I'.
LS_ROLE-DATA_KEY = 'UKM000'.
LS_ROLE-DATA-ROLECATEGORY = 'UKM000'.
LS_ROLE-DATA-VALID_FROM = SY-DATUM.
LS_ROLE-DATA-VALID_TO = '99991231'.
LS_ROLE-DATAX-VALID_FROM = ABAP_TRUE.
LS_ROLE-DATAX-VALID_TO = ABAP_TRUE.
APPEND LS_ROLE TO LS_DATA-PARTNER-CENTRAL_DATA-ROLE-ROLES.
LS_PROFILE-DATA-LIMIT_RULE = 'B2B-NEW'.
LS_PROFILE-DATAX-LIMIT_RULE = ABAP_TRUE.
LS_DATA-PARTNER-UKMBP_DATA-PROFILE = LS_PROFILE.
LS_SEGMENTS-TASK = 'I'.
LS_SEGMENTS-DATA_KEY-PARTNER = LV_PARTNER.
LS_SEGMENTS-DATA_KEY-CREDIT_SGMNT = GS_CUSTOMER-UKM_CREDIT_SGMNT.
LS_SEGMENTS-DATA-CREDIT_LIMIT = GS_CUSTOMER-LIMIT.
LS_SEGMENTS-DATA-LIMIT_VALID_DATE = GS_CUSTOMER-DATET.
LS_SEGMENTS-DATA-LIM_VAL_DATE_REQ = GS_CUSTOMER-DATET.
LS_SEGMENTS-DATA-X_LIMIT_ZERO = ABAP_TRUE.
LS_SEGMENTS-DATAX-CREDIT_LIMIT = ABAP_TRUE.
LS_SEGMENTS-DATAX-LIMIT_VALID_DATE = ABAP_TRUE.
LS_SEGMENTS-DATAX-LIM_VAL_DATE_REQ = ABAP_TRUE.
LS_SEGMENTS-DATAX-X_LIMIT_ZERO = ABAP_TRUE.
APPEND LS_SEGMENTS TO LS_DATA-PARTNER-UKMBP_DATA-SEGMENTS-SEGMENTS.
*-------------- Customer / Header ---------------------------------*
LS_DATA-CUSTOMER-HEADER-OBJECT_TASK = 'I'.
LS_DATA-CUSTOMER-HEADER-OBJECT_INSTANCE = LV_PARTNER.
LS_DATA-ENSURE_CREATE-CREATE_CUSTOMER = ABAP_TRUE.
*--------------- Customer / Company data -------------------------*
LS_COMPANY-TASK = 'I'.
LS_COMPANY-DATA_KEY-BUKRS = P_BUKRS. " company code
LS_COMPANY-DATA-ZTERM = GS_CUSTOMER-ZTERM. " terms of payment
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GS_CUSTOMER-AKONT
IMPORTING
OUTPUT = LS_COMPANY-DATA-AKONT.
LS_COMPANY-DATAX-ZTERM = 'X'.
LS_COMPANY-DATAX-AKONT = 'X'.
APPEND LS_COMPANY TO LS_DATA-CUSTOMER-COMPANY_DATA-COMPANY.
"TAX
IF GS_CUSTOMER-TAXKD IS NOT INITIAL .
LS_TAX-TASK = 'I'.
LS_TAX-DATA_KEY-ALAND = 'CA'.
LS_TAX-DATA_KEY-TATYP = 'CTX1' .
LS_TAX-DATA-TAXKD = GS_CUSTOMER-TAXKD.
LS_TAX-DATAX-TAXKD = 'X'.
APPEND LS_TAX TO LT_TAX.
ENDIF.
IF GS_CUSTOMER-TAXKD1 IS NOT INITIAL .
LS_TAX-TASK = 'I'.
LS_TAX-DATA_KEY-ALAND = 'CA'.
LS_TAX-DATA_KEY-TATYP = 'CTX2'.
LS_TAX-DATA-TAXKD = '1'.
LS_TAX-DATAX-TAXKD = GS_CUSTOMER-TAXKD1.
APPEND LS_TAX TO LT_TAX.
ENDIF.
IF GS_CUSTOMER-TAXKD2 IS NOT INITIAL .
LS_TAX-TASK = 'I'.
LS_TAX-DATA_KEY-ALAND = 'CA'.
LS_TAX-DATA_KEY-TATYP = 'CTX3'.
LS_TAX-DATA-TAXKD = '1'.
LS_TAX-DATAX-TAXKD = GS_CUSTOMER-TAXKD2.
APPEND LS_TAX TO LT_TAX.
ENDIF.
LS_DATA-CUSTOMER-CENTRAL_DATA-TAX_IND-TAX_IND = LT_TAX.
**---------------SALES ORG AND DIST & DIVISION MANDATORY FIELDS-----*
LS_SALES_DATA_ST-TASK = 'I'.
LS_SALES_DATA_ST-DATA_KEY-VKORG = GS_CUSTOMER-VKORG.
LS_SALES_DATA_ST-DATA_KEY-VTWEG = GS_CUSTOMER-VTWEG.
LS_SALES_DATA_ST-DATA_KEY-SPART = GS_CUSTOMER-SPART.
LS_SALES_DATA_ST-DATA-KALKS = GS_CUSTOMER-KALKS.
LS_SALES_DATA_ST-DATA-INCO1 = GS_CUSTOMER-INCO1.
LS_SALES_DATA_ST-DATA-INCOV = GS_CUSTOMER-INCOV.
LS_SALES_DATA_ST-DATA-INCO2_L = GS_CUSTOMER-INCO2_L.
LS_SALES_DATA_ST-DATA-VKBUR = GS_CUSTOMER-VKBUR.
LS_SALES_DATA_ST-DATA-WAERS = GS_CUSTOMER-WAERS.
LS_SALES_DATA_ST-DATA-ZTERM = GS_CUSTOMER-ZTERM.
LS_SALES_DATA_ST-DATA-LPRIO = GS_CUSTOMER-LPRIO.
LS_SALES_DATA_ST-DATA-KZAZU = ABAP_TRUE.
LS_SALES_DATA_ST-DATA-AWAHR = '100'.
LS_SALES_DATA_ST-DATAX-KALKS = ABAP_TRUE.
LS_SALES_DATA_ST-DATAX-INCO1 = ABAP_TRUE.
LS_SALES_DATA_ST-DATAX-INCOV = ABAP_TRUE.
LS_SALES_DATA_ST-DATAX-INCO2_L = ABAP_TRUE.
LS_SALES_DATA_ST-DATAX-VKBUR = ABAP_TRUE.
LS_SALES_DATA_ST-DATAX-WAERS = ABAP_TRUE.
LS_SALES_DATA_ST-DATAX-ZTERM = ABAP_TRUE.
LS_SALES_DATA_ST-DATAX-LPRIO = ABAP_TRUE.
LS_SALES_DATA_ST-DATAX-KZAZU = ABAP_TRUE.
LS_SALES_DATA_ST-DATAX-AWAHR = ABAP_TRUE.
**------------------- Business Partner Details -------------------*
LS_FUNCTIONS_ST-DATA_KEY-PARVW = 'AG'.
LS_FUNCTIONS_ST-DATA-DEFPA = 'X'.
APPEND LS_FUNCTIONS_ST TO LS_FUNCTIONS_T.
LS_FUNCTIONS_ST-DATA_KEY-PARVW = 'RE'.
LS_FUNCTIONS_ST-DATA-DEFPA = 'X'.
APPEND LS_FUNCTIONS_ST TO LS_FUNCTIONS_T.
LS_FUNCTIONS_ST-DATA_KEY-PARVW = 'RG'.
LS_FUNCTIONS_ST-DATA-DEFPA = 'X'.
APPEND LS_FUNCTIONS_ST TO LS_FUNCTIONS_T.
LS_FUNCTIONS_ST-DATA_KEY-PARVW = 'WE'.
LS_FUNCTIONS_ST-DATA-DEFPA = 'X'.
APPEND LS_FUNCTIONS_ST TO LS_FUNCTIONS_T.
LS_FUNCTIONS-FUNCTIONS = LS_FUNCTIONS_T.
LS_SALES_DATA_ST-FUNCTIONS = LS_FUNCTIONS.
LS_SALES_DATA_ST-FUNCTIONS-CURRENT_STATE = 'X'.
APPEND LS_SALES_DATA_ST TO LS_SALES_DATA-SALES.
APPEND LS_FUNCTIONS_ST TO LS_FUNCTIONS-FUNCTIONS.
LS_DATA-CUSTOMER-SALES_DATA = LS_SALES_DATA.
**--------------End of sales data---------------------------*
**-----------Finally fill the main data structure-----------*
APPEND LS_DATA TO LT_DATA.
**----------------validating BP data------------------------*
CALL METHOD CL_MD_BP_MAINTAIN=>VALIDATE_SINGLE
EXPORTING
I_DATA = LS_DATA "lt_data
* i_data_db =
* iv_suppress_taxjur_check = 'X'
IMPORTING
ET_RETURN_MAP = LT_RETURN_MAP. "lt_return.
**------------------Creating BP ----------------------------*
IF LT_RETURN_MAP IS INITIAL.
CALL METHOD CL_MD_BP_MAINTAIN=>MAINTAIN
EXPORTING
I_DATA = LT_DATA
* i_test_run =
IMPORTING
E_RETURN = LT_RETURN.
**------------------Commit BAPI ----------------------------*
IF LT_RETURN IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
WHILE LV_PARTNER IS INITIAL .
SELECT SINGLE PARTNER
INTO LV_PARTNER FROM BUT000
WHERE PARTNER_GUID = LV_GUID.
ENDWHILE.
IF LV_PARTNER IS NOT INITIAL .
GS_CUSTOMER-MESSAGE = 'SUCCESSFULLY CREATED BP'.
GS_CUSTOMER-KUNNR = LV_PARTNER.
GS_CUSTOMER-ICONS = ICON_GREEN_LIGHT.
ELSE.
GS_CUSTOMER-KUNNR = LV_PARTNER.
GS_CUSTOMER-ICONS = ICON_RED_LIGHT.
ENDIF.
ELSE.
LOOP AT LT_RETURN INTO LS_RETURN.
LOOP AT LS_RETURN-OBJECT_MSG INTO LS_RETMSG.
CLEAR: LV_TEXT.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = LS_RETMSG-ID
MSGNR = LS_RETMSG-NUMBER
MSGV1 = LS_RETMSG-MESSAGE_V1
MSGV2 = LS_RETMSG-MESSAGE_V2
MSGV3 = LS_RETMSG-MESSAGE_V3
MSGV4 = LS_RETMSG-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT = LV_TEXT.
CONCATENATE GS_CUSTOMER-MESSAGE LV_TEXT INTO GS_CUSTOMER-MESSAGE.
ENDLOOP.
ENDLOOP.
GS_CUSTOMER-ICONS = ICON_RED_LIGHT.
ENDIF.
ELSE.
LOOP AT LT_RETURN_MAP INTO LS_RETURN_MAP.
CLEAR: LV_TEXT.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = LS_RETURN_MAP-ID
MSGNR = LS_RETURN_MAP-NUMBER
MSGV1 = LS_RETURN_MAP-MESSAGE_V1
MSGV2 = LS_RETURN_MAP-MESSAGE_V2
MSGV3 = LS_RETURN_MAP-MESSAGE_V3
MSGV4 = LS_RETURN_MAP-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT = LV_TEXT.
CONCATENATE GS_CUSTOMER-MESSAGE LV_TEXT INTO GS_CUSTOMER-MESSAGE.
ENDLOOP.
GS_CUSTOMER-ICONS = ICON_RED_LIGHT.
ENDIF.
MODIFY GT_CUSTOMER FROM GS_CUSTOMER.
ENDLOOP.
供应商BP创建实例代码如下
代码语言:javascript复制DATA : LT_RETURN_MAP TYPE MDG_BS_BP_MSGMAP_T.
DATA : LS_RETURN_MAP TYPE MDG_BS_BP_MSGMAP.
DATA : LS_MESSAGE_MAP TYPE MDG_BS_BP_MSGMAP_KEY.
DATA : LT_DATA TYPE CVIS_EI_EXTERN_T,
LT_RETURN TYPE BAPIRETM,
LS_RETURN TYPE BAPIRETI,
LS_RETMSG TYPE LINE OF BAPIRETCT,
LV_TEXT TYPE STRING.
DATA: LS_DATA LIKE LINE OF LT_DATA,
LS_ROLE TYPE BUS_EI_BUPA_ROLES,
LS_PAADR TYPE BUS_EI_BUPA_ADDRESS,
LS_COMPANY TYPE VMDS_EI_COMPANY.
DATA: LV_GUID TYPE GUID_32,
LV_PARTNER LIKE LS_DATA-PARTNER-HEADER-OBJECT_INSTANCE-BPARTNER.
DATA: LS_FUNCTIONS_ST TYPE VMDS_EI_FUNCTIONS,
LS_FUNCTIONS_T TYPE VMDS_EI_FUNCTIONS_T,
LS_FUNCTIONS TYPE VMDS_EI_VMD_FUNCTIONS,
LS_PURCHASING_DATA TYPE VMDS_EI_PURCHASING,
LT_PURCHASING_DATA TYPE VMDS_EI_PURCHASING_T.
DATA: LS_PHONE TYPE BUS_EI_BUPA_TELEPHONE.
DATA: LT_PHONE TYPE BUS_EI_BUPA_TELEPHONE_T.
DATA: LS_FAX TYPE BUS_EI_BUPA_FAX.
DATA: LT_FAX TYPE BUS_EI_BUPA_FAX_T.
DATA: LS_MAIL TYPE BUS_EI_BUPA_SMTP.
DATA: LT_MAIL TYPE BUS_EI_BUPA_SMTP_T.
LOOP AT GT_VENDOR INTO GS_VENDOR WHERE LIFNR IS INITIAL .
CLEAR:LT_RETURN_MAP,
LS_RETURN_MAP,
LS_MESSAGE_MAP,
LT_DATA,
LT_RETURN,
LS_RETURN,
LS_RETMSG,
LV_TEXT,
LS_DATA,
LS_ROLE,
LS_PAADR,
LS_COMPANY,
LV_GUID,
LV_PARTNER,
LS_FUNCTIONS_ST,
LS_FUNCTIONS_T,
LS_FUNCTIONS,
LS_PURCHASING_DATA,
LT_PURCHASING_DATA,
LS_PHONE,
LT_PHONE,
LS_FAX,
LT_FAX,
LS_MAIL,
LT_MAIL.
CALL METHOD CL_SYSTEM_UUID=>IF_SYSTEM_UUID_STATIC~CREATE_UUID_C32
RECEIVING
UUID = LV_GUID.
* Create customer
LS_DATA-PARTNER-HEADER-OBJECT_TASK = 'I'.
LS_DATA-PARTNER-HEADER-OBJECT_INSTANCE-BPARTNER = LV_PARTNER.
LS_DATA-PARTNER-HEADER-OBJECT_INSTANCE-BPARTNERGUID = LV_GUID.
*--- Partner / Central data / common ------------------------------*
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CONTROL-CATEGORY = '2'. "3group "2 Organization
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CONTROL-GROUPING = GS_CUSTOMER-BU_GROUP. "Grouping
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-TITLE_KEY = GS_VENDOR-AD_TITLE. "tittle
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-SEARCHTERM1 = GS_VENDOR-SORT1 0(20). "Search term 1 for business partner
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_CENTRALDATA-SEARCHTERM2 = GS_VENDOR-SORT1 20(20). "Search term 2 for business partner
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_CENTRALDATA-TITLE_KEY = ABAP_TRUE.
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_CENTRALDATA-SEARCHTERM1 = ABAP_TRUE.
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_CENTRALDATA-SEARCHTERM2 = ABAP_TRUE.
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME1 = GS_VENDOR-NAME1 0(35).
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATA-BP_ORGANIZATION-NAME2 = GS_VENDOR-NAME1 35(35).
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_ORGANIZATION-NAME1 = ABAP_TRUE.
LS_DATA-PARTNER-CENTRAL_DATA-COMMON-DATAX-BP_ORGANIZATION-NAME2 = ABAP_TRUE.
*--- Partner / Central data / Address -----------------------------*
LS_PAADR-TASK = 'I'.
LS_PAADR-DATA_KEY-OPERATION = 'XXDFLT'.
LS_PAADR-DATA-POSTAL-DATA-STR_SUPPL3 = GS_VENDOR-UNIT.
LS_PAADR-DATA-POSTAL-DATA-CITY = GS_VENDOR-CITY1.
LS_PAADR-DATA-POSTAL-DATA-HOUSE_NO = GS_VENDOR-HOUSE_NUM1.
LS_PAADR-DATA-POSTAL-DATA-POSTL_COD1 = GS_VENDOR-POST_CODE1.
LS_PAADR-DATA-POSTAL-DATA-STREET = GS_VENDOR-STREET.
LS_PAADR-DATA-POSTAL-DATA-COUNTRY = GS_VENDOR-LAND1.
LS_PAADR-DATA-POSTAL-DATA-REGION = GS_VENDOR-REGIO.
LS_PAADR-DATA-POSTAL-DATA-TIME_ZONE = GS_VENDOR-TIME_ZONE.
LS_PAADR-DATA-POSTAL-DATA-LANGU = GS_VENDOR-LANGU.
LS_PAADR-DATA-POSTAL-DATAX-STR_SUPPL3 = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-CITY = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-HOUSE_NO = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-POSTL_COD1 = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-STREET = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-COUNTRY = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-REGION = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-TIME_ZONE = ABAP_TRUE.
LS_PAADR-DATA-POSTAL-DATAX-LANGU = ABAP_TRUE.
LS_PAADR-CURRENTLY_VALID = ABAP_TRUE.
" Communication
IF GS_VENDOR-TEL_NUMBER IS NOT INITIAL .
*第一个电话
LS_PHONE-CONTACT-TASK = 'I'.
LS_PHONE-CONTACT-DATA-COUNTRY = GS_VENDOR-LAND1.
LS_PHONE-CONTACT-DATA-TELEPHONE = GS_VENDOR-TEL_NUMBER.
LS_PHONE-CONTACT-DATAX-COUNTRY = 'X'.
LS_PHONE-CONTACT-DATAX-TELEPHONE = 'X'.
APPEND LS_PHONE TO LT_PHONE.
LS_PAADR-DATA-COMMUNICATION-PHONE-PHONE = LT_PHONE.
ENDIF.
IF GS_VENDOR-FAX_NUMBER IS NOT INITIAL .
*传真
LS_FAX-CONTACT-TASK = 'I'.
LS_FAX-CONTACT-DATA-COUNTRY = GS_VENDOR-LAND1.
LS_FAX-CONTACT-DATA-FAX = GS_VENDOR-FAX_NUMBER.
LS_FAX-CONTACT-DATAX-COUNTRY = 'X'.
LS_FAX-CONTACT-DATAX-FAX = 'X'.
APPEND LS_FAX TO LT_FAX.
LS_PAADR-DATA-COMMUNICATION-FAX-FAX = LT_FAX.
ENDIF.
IF GS_VENDOR-SMTP_ADDR IS NOT INITIAL .
**电子邮件
LS_MAIL-CONTACT-TASK = 'I'.
LS_MAIL-CONTACT-DATA-E_MAIL = GS_VENDOR-SMTP_ADDR.
LS_MAIL-CONTACT-DATAX-E_MAIL = 'X'.
APPEND LS_MAIL TO LT_MAIL.
LS_PAADR-DATA-COMMUNICATION-SMTP-SMTP = LT_MAIL.
ENDIF.
APPEND LS_PAADR TO LS_DATA-PARTNER-CENTRAL_DATA-ADDRESS-ADDRESSES.
*----------------- PARTNER / CENTRAL DATA / ROLE -----------------*
*-------------- Adding multiple roles for the BP------------------*
*-------------- Partner / Central data / role --------------------*
LS_ROLE-TASK = 'I'.
LS_ROLE-DATA_KEY = 'GZ0003'.
LS_ROLE-DATA-ROLECATEGORY = 'FLVN00'.
LS_ROLE-DATA-VALID_FROM = SY-DATUM.
LS_ROLE-DATA-VALID_TO = '99991231'.
LS_ROLE-CURRENTLY_VALID = ABAP_TRUE.
LS_ROLE-DATAX-VALID_FROM = ABAP_TRUE.
LS_ROLE-DATAX-VALID_TO = ABAP_TRUE.
APPEND LS_ROLE TO LS_DATA-PARTNER-CENTRAL_DATA-ROLE-ROLES.
"LS_DATA-PARTNER-CENTRAL_DATA-ROLE-CURRENT_STATE = ABAP_TRUE.
*------------- Partner / Central data / role ---------------------*
LS_ROLE-TASK = 'I'.
LS_ROLE-DATA_KEY = 'GZ0004'.
LS_ROLE-DATA-ROLECATEGORY = 'FLVN01'.
LS_ROLE-DATA-VALID_FROM = SY-DATUM.
LS_ROLE-DATA-VALID_TO = '99991231'.
LS_ROLE-CURRENTLY_VALID = ABAP_TRUE.
LS_ROLE-DATAX-VALID_FROM = ABAP_TRUE.
LS_ROLE-DATAX-VALID_TO = ABAP_TRUE.
APPEND LS_ROLE TO LS_DATA-PARTNER-CENTRAL_DATA-ROLE-ROLES.
"LS_DATA-PARTNER-CENTRAL_DATA-ROLE-CURRENT_STATE = ABAP_TRUE.
*-------------- Vendor / Header ---------------------------------*
LS_DATA-VENDOR-HEADER-OBJECT_TASK = 'I'.
LS_DATA-VENDOR-HEADER-OBJECT_INSTANCE = LV_PARTNER.
LS_DATA-ENSURE_CREATE-CREATE_VENDOR = ABAP_TRUE.
*--------------- Vendor / Company data -------------------------*
LS_COMPANY-TASK = 'I'.
LS_COMPANY-DATA_KEY-BUKRS = P_BUKRS. " company code
LS_COMPANY-DATA-ZTERM = GS_VENDOR-ZTERM. " terms of payment
LS_COMPANY-DATA-REPRF = GS_VENDOR-REPRF. " terms of payment
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GS_VENDOR-AKONT
IMPORTING
OUTPUT = LS_COMPANY-DATA-AKONT.
LS_COMPANY-DATAX-ZTERM = 'X'.
LS_COMPANY-DATAX-AKONT = 'X'.
LS_COMPANY-DATAX-REPRF = 'X'.
APPEND LS_COMPANY TO LS_DATA-VENDOR-COMPANY_DATA-COMPANY.
**---------------Purchasing Data----------------------*
LS_PURCHASING_DATA-TASK = 'I'.
LS_PURCHASING_DATA-DATA_KEY-EKORG = GS_VENDOR-EKORG.
LS_PURCHASING_DATA-DATA-INCO1 = GS_VENDOR-INCO1.
LS_PURCHASING_DATA-DATA-INCOV = GS_VENDOR-INCOV.
LS_PURCHASING_DATA-DATA-INCO2_L = GS_VENDOR-INCO2_L.
LS_PURCHASING_DATA-DATA-WAERS = GS_VENDOR-WAERS.
LS_PURCHASING_DATA-DATA-ZTERM = GS_VENDOR-ZTERM.
LS_PURCHASING_DATA-DATAX-INCO1 = ABAP_TRUE.
LS_PURCHASING_DATA-DATAX-INCOV = ABAP_TRUE.
LS_PURCHASING_DATA-DATAX-INCO2_L = ABAP_TRUE.
LS_PURCHASING_DATA-DATAX-WAERS = ABAP_TRUE.
LS_PURCHASING_DATA-DATAX-ZTERM = ABAP_TRUE.
**------------------- Business Partner Details -------------------*
LS_FUNCTIONS_ST-DATA_KEY-PARVW = 'BA'.
LS_FUNCTIONS_ST-DATA-DEFPA = 'X'.
APPEND LS_FUNCTIONS_ST TO LS_FUNCTIONS_T.
LS_FUNCTIONS_ST-DATA_KEY-PARVW = 'LF'.
LS_FUNCTIONS_ST-DATA-DEFPA = 'X'.
APPEND LS_FUNCTIONS_ST TO LS_FUNCTIONS_T.
LS_FUNCTIONS_ST-DATA_KEY-PARVW = 'RS'.
LS_FUNCTIONS_ST-DATA-DEFPA = 'X'.
APPEND LS_FUNCTIONS_ST TO LS_FUNCTIONS_T.
LS_FUNCTIONS-FUNCTIONS = LS_FUNCTIONS_T.
LS_PURCHASING_DATA-FUNCTIONS = LS_FUNCTIONS.
LS_PURCHASING_DATA-FUNCTIONS-CURRENT_STATE = 'X'.
APPEND LS_PURCHASING_DATA TO LS_DATA-VENDOR-PURCHASING_DATA-PURCHASING.
**--------------End of sales data---------------------------*
**-----------Finally fill the main data structure-----------*
APPEND LS_DATA TO LT_DATA.
**----------------validating BP data------------------------*
CALL METHOD CL_MD_BP_MAINTAIN=>VALIDATE_SINGLE
EXPORTING
I_DATA = LS_DATA "lt_data
* i_data_db =
* iv_suppress_taxjur_check = 'X'
IMPORTING
ET_RETURN_MAP = LT_RETURN_MAP. "lt_return.
**------------------Creating BP ----------------------------*
IF LT_RETURN_MAP IS INITIAL.
CALL METHOD CL_MD_BP_MAINTAIN=>MAINTAIN
EXPORTING
I_DATA = LT_DATA
* i_test_run =
IMPORTING
E_RETURN = LT_RETURN.
**------------------Commit BAPI ----------------------------*
IF LT_RETURN IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
WHILE LV_PARTNER IS INITIAL .
SELECT SINGLE PARTNER
INTO LV_PARTNER FROM BUT000
WHERE PARTNER_GUID = LV_GUID.
ENDWHILE.
GS_VENDOR-MESSAGE = 'SUCCESSFULLY CREATED BP'.
GS_VENDOR-LIFNR = LV_PARTNER.
GS_VENDOR-ICONS = ICON_GREEN_LIGHT.
ELSE.
LOOP AT LT_RETURN INTO LS_RETURN.
LOOP AT LS_RETURN-OBJECT_MSG INTO LS_RETMSG.
CLEAR: LV_TEXT.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = LS_RETMSG-ID
MSGNR = LS_RETMSG-NUMBER
MSGV1 = LS_RETMSG-MESSAGE_V1
MSGV2 = LS_RETMSG-MESSAGE_V2
MSGV3 = LS_RETMSG-MESSAGE_V3
MSGV4 = LS_RETMSG-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT = LV_TEXT.
CONCATENATE GS_VENDOR-MESSAGE LV_TEXT INTO GS_VENDOR-MESSAGE.
ENDLOOP.
ENDLOOP.
GS_VENDOR-ICONS = ICON_RED_LIGHT.
ENDIF.
ELSE.
LOOP AT LT_RETURN_MAP INTO LS_RETURN_MAP.
CLEAR: LV_TEXT.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = LS_RETURN_MAP-ID
MSGNR = LS_RETURN_MAP-NUMBER
MSGV1 = LS_RETURN_MAP-MESSAGE_V1
MSGV2 = LS_RETURN_MAP-MESSAGE_V2
MSGV3 = LS_RETURN_MAP-MESSAGE_V3
MSGV4 = LS_RETURN_MAP-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT = LV_TEXT.
CONCATENATE GS_VENDOR-MESSAGE LV_TEXT INTO GS_VENDOR-MESSAGE.
ENDLOOP.
GS_VENDOR-ICONS = ICON_RED_LIGHT.
ENDIF.
MODIFY GT_VENDOR FROM GS_VENDOR.
ENDLOOP.