SAP/Module
[N] BP 생성 API
성공보다는 가치를..
2024. 4. 24. 14:30
728x90
사용 Class - CL_MD_BP_MAINTAIN
*&---------------------------------------------------------------------*
*& Report zbp_create_simple
*&---------------------------------------------------------------------*
*& Create basic BP with vendor role via
*& Central API class CL_MD_BP_MAINTAIN
*&---------------------------------------------------------------------*
REPORT zbp_create_simple.
CONSTANTS:
c_task_insert TYPE bus_ei_object_task VALUE 'I'.
DATA:
s_bp TYPE cvis_ei_extern,
t_bp TYPE cvis_ei_extern_t,
t_address TYPE bus_ei_bupa_address_t,
t_role TYPE bus_ei_bupa_roles_t,
t_ident_numbers TYPE bus_ei_bupa_identification_t,
t_taxnumbers TYPE bus_ei_bupa_taxnumber_t,
t_return TYPE bapiretm,
v_bu_partner TYPE bu_partner,
v_error TYPE abap_bool.
PARAMETERS:
p_test TYPE abap_bool AS CHECKBOX.
START-OF-SELECTION.
*------------------------------------------------------------------------------
* Create GUID for new BP
*------------------------------------------------------------------------------
TRY.
DATA(v_guid) = cl_system_uuid=>if_system_uuid_static~create_uuid_c32( ).
CATCH cx_uuid_error INTO DATA(r_uuid_exc).
MESSAGE r_uuid_exc->get_text( ) TYPE 'E'.
ENDTRY.
*------------------------------------------------------------------------------
* Header and common central data
*------------------------------------------------------------------------------
s_bp-partner-header-object_task = c_task_insert. "'I' for new BP
s_bp-partner-header-object_instance-bpartnerguid = v_guid.
* Category: 1 for Person, 2 for Organization, 3 for Group
s_bp-partner-central_data-common-data-bp_control-category = '2'.
* The grouping depends on the system settings
s_bp-partner-central_data-common-data-bp_control-grouping = 'ZCRE'.
s_bp-partner-central_data-common-data-bp_centraldata-searchterm1 = 'SAP SE'.
s_bp-partner-central_data-common-data-bp_organization-name1 = 'SAP SE'.
s_bp-partner-central_data-common-data-bp_organization-name2 = 'Test BP'.
* Mark as changed
s_bp-partner-central_data-common-datax-bp_organization-name1 = abap_true.
s_bp-partner-central_data-common-datax-bp_organization-name2 = abap_true.
*------------------------------------------------------------------------------
* VAT number (needed for BPs located in the EU)
*
* Number is normally validated by function module VAT_REGISTRATION_NUMBER_CHECK
* Tax types are stored in table TFKTAXNUMTYPE
*------------------------------------------------------------------------------
APPEND INITIAL LINE TO t_taxnumbers ASSIGNING FIELD-SYMBOL(<fs_taxnumbers>).
<fs_taxnumbers>-task = c_task_insert.
<fs_taxnumbers>-data_key-taxtype = 'DE0'.
<fs_taxnumbers>-data_key-taxnumber = 'DE143454214'. "SAP SE VAT reg. number
s_bp-partner-central_data-taxnumber-taxnumbers = t_taxnumbers.
*------------------------------------------------------------------------------
* Address data
*------------------------------------------------------------------------------
APPEND INITIAL LINE TO t_address ASSIGNING FIELD-SYMBOL(<fs_address>).
<fs_address>-task = c_task_insert.
* Operations are store in table TB008S
<fs_address>-data_key-operation = 'XXDFLT'. "Standard operation
<fs_address>-data-postal-data-city = 'Walldorf'.
<fs_address>-data-postal-data-postl_cod1 = '69190'.
<fs_address>-data-postal-data-street = 'SAP street'.
<fs_address>-data-postal-data-country = 'DE'.
<fs_address>-data-postal-data-langu = 'E'.
* Mark as changed
<fs_address>-data-postal-datax-city = abap_true.
<fs_address>-data-postal-datax-postl_cod1 = abap_true.
<fs_address>-data-postal-datax-street = abap_true.
<fs_address>-data-postal-datax-country = abap_true.
<fs_address>-data-postal-datax-region = abap_true.
<fs_address>-data-postal-datax-langu = abap_true.
* Add address to main structure
s_bp-partner-central_data-address-addresses = t_address.
*------------------------------------------------------------------------------
* Roles
*------------------------------------------------------------------------------
APPEND INITIAL LINE TO t_role ASSIGNING FIELD-SYMBOL(<fs_role>).
<fs_role>-task = c_task_insert.
<fs_role>-data_key = 'FLVN01'. "Role key - Vendor
*<fs_role>-data_key = 'FLCU01'. "Role key - customer
* Add role to main structure
s_bp-partner-central_data-role-roles = t_role.
*------------------------------------------------------------------------------
* Validate data
*------------------------------------------------------------------------------
cl_md_bp_maintain=>validate_single(
EXPORTING
i_data = s_bp
IMPORTING
et_return_map = DATA(t_return_map)
).
IF line_exists( t_return_map[ type = 'E' ] ) OR
line_exists( t_return_map[ type = 'A' ] ).
LOOP AT t_return_map INTO DATA(s_return_map).
WRITE:/ s_return_map-message.
ENDLOOP.
EXIT.
ENDIF.
*------------------------------------------------------------------------------
* Call API
*------------------------------------------------------------------------------
* Add single BP to IMPORTING table
INSERT s_bp INTO TABLE t_bp.
cl_md_bp_maintain=>maintain(
EXPORTING
i_data = t_bp
i_test_run = p_test
IMPORTING
e_return = t_return
).
* Check result
LOOP AT t_return INTO DATA(s_return).
LOOP AT s_return-object_msg INTO DATA(s_msg).
IF s_msg-type = 'E' OR s_msg-type = 'A'.
* Error occurred
v_error = abap_true.
ENDIF.
WRITE:/ s_msg-message.
ENDLOOP.
ENDLOOP.
IF v_error IS INITIAL.
CASE p_test.
WHEN abap_true.
* Test mode
WRITE:/ |BP data is ok.|.
WHEN abap_false.
* Non-test mode => Perform COMMIT
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
* Get number of new BP (it's not returned by the API)
IMPORT lv_partner TO v_bu_partner FROM MEMORY ID 'BUP_MEMORY_PARTNER'.
WRITE:/ |Business Partner { v_bu_partner } has been created.|.
ENDCASE.
ENDIF.
출처 : https://sapspaces.com/create-business-partner-via-api-class-cl_md_bp_maintain/
- 은행 시작 & 종료일이 안먹을 경우 BANKDETAIL-TIME_DEPENDENT = X
Note - https://me.sap.com/notes/0003426099
- 주소에서 체크테이블 오류가 발생할 경우
Note - https://userapps.support.sap.com/sap/support/knowledge/en/3109298
728x90