Skip to Content
Technical Articles

Automatic Creation and Submission of Change Request for Customer

Purpose:

We had a requirement automatically create and submit change request for CUSTOMER and monitor based on CUSTOMER TYPE Rules where the data is received from third party system i.e.,CRM system through a middle ware system.

In the below example it is shown that to create a CUSTOMER Change Request and Submit for review & approvals. Also, create a change request for existing CUSTOMER along with submit Review and approval.

Similar example can be used for any other Auto creation of Change request for Material or Business Partner or Supplier & Submit Change Request.

 

Basic Content to Know on API:

Master Data Governance (MDG)

Application Programming Interface (API)

 

The MDG framework several interfaces that are used by the delivered SAP MDG applications and also can be used by other external applications (like customer applications) in order to handle the governance process and the related entity data.

 

The detail information of API has been shared in the below link

https://help.sap.com/viewer/6d52de87aa0d4fb6a90924720a5b0549/1709%20000/en-US/498c9232-a8ce-462b-95f0-717ac9016b7c.html#:~:text=Features&text=The%20Governance%20API%20covers%20the,handle%20multiple%20change%20requests%20simultaneously.

 

Below are the API with their Purpose in a tabular format to understand easily

 

API Interface Implementation Class
Change Request API IF_USMD_CRREQUEST_API CL_USMD_CRREQUEST_API
External Mode API IF_USMD_MODEL_EXT CL_USMD_MODEL_EXT
Governance API IF_USMD_GOV_API CL_USMD_GOV_API
Convenience API IF_USMD_CONV_SOM_GOV_API CL_USMD_CONV_SOM_GOV_API
Context API IF_USMD_APP_CONTEXT CL_USMD_APP_CONTEXT

 

API Main Purpose
Change Request API Handling of change request and partly changing and reading entity
External Mode API Reading Entity Data
Governance API Handling of several change request and entity data
Convenience API As Governance API but using single change request
Context API Store and provide context data

 

An RFC has been created to fulfill the requirement and send the data back to CRM on successful creation of Change Request or to send reason of failure like any missing data.

Below Code is used to create a Governance API and also create Change request ID

“ Create an instance of the governance API
IF go_mdg_conv IS NOT BOUND.
TRY .
go_mdg_conv = cl_usmd_conv_som_gov_api=>get_instance(
iv_model_name = 'BP'
).
CATCH cx_usmd_conv_som_gov_api INTO go_som_gov_api_error.  "
et_messages = go_som_gov_api_error->mt_messages.
CATCH cx_usmd_app_context_cons_error INTO go_cons_error.  "
ls_message = go_cons_error->e_message.
APPEND ls_message TO et_messages.
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
*--Create a new change request using change request type 
TRY.
go_mdg_conv->set_environment(
EXPORTING
iv_crequest_type   = im_changereq_type "'CUST1P2'
iv_create_crequest = abap_true
).
CATCH cx_usmd_conv_som_gov_api INTO go_som_gov_api_error.  "
et_messages = go_som_gov_api_error->mt_messages.
RETURN.
ENDTRY.
ev_crequest_id = go_mdg_conv->get_crequest_id( ).
****------- Create Temp key for address " Create Customer
TRY.
go_mdg_conv->create_entity_tmp_key(
EXPORTING
*         iv_lock   = ABAP_TRUE
iv_entity = 'ADDRNO'
IMPORTING
es_key    = ev_temp_key_bp_addr
).
CATCH cx_usmd_conv_som_gov_api INTO go_som_gov_api_error.  "
et_messages = go_som_gov_api_error->mt_messages.
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
TRY.
go_mdg_conv->create_entity_tmp_key(
EXPORTING
*         iv_lock   = ABAP_TRUE
iv_entity =  'BP_HEADER'   "'BP_REL'
IMPORTING
es_key    = ev_temp_key_bp
).
CATCH cx_usmd_conv_som_gov_api INTO go_som_gov_api_error.  "
et_messages = go_som_gov_api_error->mt_messages.
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.

Below logic is used to generate UI screen for Change Request ID created using this above logic

TRY.
lv_uuid_16 = cl_system_uuid=>create_uuid_x16_static( ).
CATCH cx_uuid_error INTO lo_error.
CLEAR lv_uuid_16.
ENDTRY.

Below Logic is used to fill the required Entity Data to create a Customer with reference to data received from data from CRM system.

*Create all the data references needed to maintain the Entity
"Create a data reference of the key structure / table of entity
*--------------------------------------------------------------------*
*      'BP_HEADER'
*--------------------------------------------------------------------*
*      FIELD-SYMBOLS : "<fs_bp_header>         TYPE /mdgbp/_s_bp_pp_bp_header,
*                      <lt_anydata_bp_header> TYPE ANY TABLE.
DATA: lv_uuid_16  TYPE sysuuid_x16.
DATA  lo_error TYPE REF TO cx_root.
DATA :et_entity_data TYPE        usmd_gov_api_ts_ent_data,
et_entity_keys TYPE        usmd_gov_api_ts_ent_tabl.
DATA go_core_error TYPE REF TO cx_usmd_gov_api_core_error .
DATA lo_ent_error TYPE REF TO cx_usmd_gov_api_entity_write.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'BP_HEADER'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_bp_header>.
ASSIGN l_t_entity->* TO <lt_anydata_bp_header>.
TRY.
lv_uuid_16 = cl_system_uuid=>create_uuid_x16_static( ).
CATCH cx_uuid_error INTO lo_error.
CLEAR lv_uuid_16.
ENDTRY.
<fs_bp_header>-bp_header = ev_temp_key_bp.
<fs_bp_header>-bp_guid   = lv_uuid_16.
<fs_bp_header>-bu_group  = lv_bu_group.
<fs_bp_header>-bu_type   = 2.
INSERT <fs_bp_header> INTO TABLE <lt_anydata_bp_header>.
CLEAR : lw_entity_keys,lt_entity_keys_lock.
lw_entity_keys-entity = 'BP_HEADER'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
INSERT lw_entity_keys INTO TABLE lt_entity_keys_lock.
CLEAR lw_entity_data.
lw_entity_data-entity = 'BP_HEADER'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
*-----Before making changes to an object, the object needs to be Enqueued even if this is a creation scenario------*
TRY.
go_mdg_conv->enqueue_entity (
EXPORTING
it_entity_keys = lt_entity_keys_lock     ).
CATCH cx_usmd_conv_som_gov_api INTO go_som_gov_api_error.  "
et_messages = go_som_gov_api_error->mt_messages.
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
*--------------------------------------------------------------------*
*       ADDRNO
*--------------------------------------------------------------------*
FIELD-SYMBOLS : <fs_addrno>         TYPE /mdgbp/_s_bp_ky_addrno,
<lt_anydata_addrno> TYPE ANY TABLE.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'ADDRNO'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_addrno>.
ASSIGN l_t_entity->* TO <lt_anydata_addrno>.
<fs_addrno>-addrno = ev_temp_key_bp_addr.
INSERT <fs_addrno> INTO TABLE <lt_anydata_addrno>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'ADDRNO'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR : lw_entity_keys,lt_entity_keys_lock.
lw_entity_keys-entity = 'ADDRNO'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
INSERT lw_entity_keys INTO TABLE lt_entity_keys_lock.
*lock the entity
TRY.
go_mdg_conv->enqueue_entity(
EXPORTING
it_entity_keys = lt_entity_keys_lock
*               iv_lock_mode   = 'E'
).
CATCH cx_usmd_conv_som_gov_api INTO go_som_gov_api_error.  "
et_messages = go_som_gov_api_error->mt_messages.
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
*------*Write the entity data to the change request------*
TRY.
go_mdg_conv->write_entity_data(it_entity_data = et_entity_data ).
CLEAR et_entity_data.
CATCH cx_usmd_gov_api_core_error INTO go_core_error.
et_messages = go_core_error->mt_messages.
CATCH cx_usmd_gov_api_entity_write INTO lo_ent_error.
et_messages = lo_ent_error->mt_messages.
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.    "
ENDTRY.
*--------------------------------------------------------------------*
*       BP_ROLE
*--------------------------------------------------------------------*
*      FIELD-SYMBOLS : <fs_bp_role>         TYPE /mdgbp/_s_bp_pp_bp_role,
*                      <lt_anydata_bp_role> TYPE ANY TABLE.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'BP_ROLE'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_bp_role>.
ASSIGN l_t_entity->* TO <lt_anydata_bp_role>.
<fs_bp_role>-bp_header = ev_temp_key_bp.
<fs_bp_role>-bp_rol_id = 'FLCU01'.
INSERT <fs_bp_role> INTO TABLE <lt_anydata_bp_role>.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'BP_ROLE'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
CLEAR lw_entity_data.
lw_entity_data-entity = 'BP_ROLE'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
ENDIF.
*--------------------------------------------------------------------*
*       'ADDRESS'
*--------------------------------------------------------------------*
*    FIELD-SYMBOLS: <fs_address>         TYPE /mdgbp/_s_bp_pp_address,
*                   <lt_anydata_address> TYPE ANY TABLE.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'ADDRESS'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_address>.
ASSIGN l_t_entity->* TO <lt_anydata_address>.
<fs_address>-addrno    = ev_temp_key_bp_addr.
<fs_address>-bp_header = ev_temp_key_bp.
<fs_address>-type      = 1.
INSERT <fs_address> INTO TABLE <lt_anydata_address>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'ADDRESS'.
lw_entity_data-entity_data = l_t_entity.
*       Lw_entity_data-entity_attributes = .
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'ADDRESS'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
*--------------------------------------------------------------------*
*       'BP_CENTRL'
*--------------------------------------------------------------------*
*    FIELD-SYMBOLS :
*      <fs_bp_centrl>      TYPE /mdgbp/_s_bp_pp_bp_centrl,
*      <fs_bp_cusgen>      TYPE /mdgbpx/_s_bp_pp_bp_cusgen,
*      <fs_bp_cus_cc>      TYPE /mdgbpx/_s_bp_pp_bp_cus_cc,
*      <fs_bp_mlt_as>      TYPE /mdgbpx/_s_bp_pp_bp_mlt_as,
*      <lt_anydata_centrl> TYPE ANY TABLE.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'BP_CENTRL'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_bp_centrl>.
ASSIGN l_t_entity->* TO <lt_anydata_centrl>.
<fs_bp_centrl>-bp_header =  ev_temp_key_bp.
<fs_bp_centrl>-name_org1 =  is_bpcentral-name_org1. "'WG Tech'.
<fs_bp_centrl>-name_org2 =  is_bpcentral-name_org2. "'WG Tech'.
<fs_bp_centrl>-bu_sort1 =   is_bpcentral-bu_sort1.  "'WG'.
INSERT <fs_bp_centrl> INTO TABLE <lt_anydata_centrl>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'BP_CENTRL'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
***Create Key struct
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'BP_CENTRL'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
*--------------------------------------------------------------------*
*       'AD_TEL'
*--------------------------------------------------------------------*
IF is_adtel-t_number IS NOT INITIAL.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'AD_TEL'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_ad_tel>.
ASSIGN l_t_entity->* TO <lt_anydata_ad_tel>.
<fs_ad_tel>-addrno    = ev_temp_key_bp_addr.
<fs_ad_tel>-bp_header = ev_temp_key_bp.
<fs_ad_tel>-t_number  = is_adtel-t_number.
INSERT <fs_ad_tel> INTO TABLE <lt_anydata_ad_tel>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'AD_TEL'.
lw_entity_data-entity_data = l_t_entity.
*       Lw_entity_data-entity_attributes = .
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'AD_TEL'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
ENDIF.
*--------------------------------------------------------------------*
*       'AD_FAX'
*--------------------------------------------------------------------*
IF is_adfax-f_number IS NOT INITIAL.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'AD_FAX'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_ad_fax>.
ASSIGN l_t_entity->* TO <lt_anydata_ad_fax>.
<fs_ad_fax>-addrno    = ev_temp_key_bp_addr.
<fs_ad_fax>-bp_header = ev_temp_key_bp.
<fs_ad_fax>-f_number  = is_adfax-f_number.
INSERT <fs_ad_fax> INTO TABLE <lt_anydata_ad_fax>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'AD_FAX'.
lw_entity_data-entity_data = l_t_entity.
*       Lw_entity_data-entity_attributes = .
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'AD_FAX'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
ENDIF.
**--------------------------------------------------------------------*
**      'BP_ADDR'
**--------------------------------------------------------------------*
FIELD-SYMBOLS: <fs_bp_addr>         TYPE /mdgbp/_s_bp_pp_bp_addr,
<lt_anydata_bp_addr> TYPE ANY TABLE.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'BP_ADDR'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_bp_addr>.
ASSIGN l_t_entity->* TO <lt_anydata_bp_addr>.
<fs_bp_addr>-addrno    = ev_temp_key_bp_addr.
<fs_bp_addr>-bp_header = ev_temp_key_bp.
INSERT <fs_bp_addr> INTO TABLE <lt_anydata_bp_addr>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'BP_ADDR'.
lw_entity_data-entity_data = l_t_entity.
*      Lw_entity_data-entity_attributes = .
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'BP_ADDR'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
*--------------------------------------------------------------------*
*       'AD_POSTAL'
*--------------------------------------------------------------------*
*    FIELD-SYMBOLS: <fs_ad_postal>      TYPE /mdgbp/_s_bp_pp_ad_postal,
*                   <lt_anydata_postal> TYPE ANY TABLE.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'AD_POSTAL'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_ad_postal>.
ASSIGN l_t_entity->* TO <lt_anydata_postal>.
ASSIGN COMPONENT 'ADDRNO' OF STRUCTURE <fs_ad_postal>
TO FIELD-SYMBOL(<lfv_field_val>).
IF sy-subrc EQ 0.
<lfv_field_val> = ev_temp_key_bp_addr.
ENDIF.
ASSIGN COMPONENT 'BP_HEADER' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = ev_temp_key_bp.
ENDIF.
ASSIGN COMPONENT 'STREET' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = is_address-street.
ENDIF.
ASSIGN COMPONENT 'DISTRICT' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = is_address-district.
ENDIF.
ASSIGN COMPONENT 'DEFLTCOMM' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = is_address-defltcomm.
ENDIF.
ASSIGN COMPONENT 'RFE_POSTL' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = is_address-rfe_postl..
ENDIF.

ASSIGN COMPONENT 'CITY1' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = is_address-city1.
ENDIF.
ASSIGN COMPONENT 'REF_POSTA' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = lv_country_key.
ENDIF.
ASSIGN COMPONENT 'POBOX_CTY' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = lv_country_key.
ENDIF.
ASSIGN COMPONENT 'RFE_POST' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = lv_region.
ENDIF.
ASSIGN COMPONENT 'RFE_POSTL' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = is_address-rfe_postl.
ENDIF.
ASSIGN COMPONENT 'POST_COD1' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = is_address-post_cod1.
ENDIF.
ASSIGN COMPONENT 'POST_COD2' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = is_address-post_cod1.
ENDIF.
ASSIGN COMPONENT 'PO_BOX' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
<lfv_field_val> = is_address-po_box.
ENDIF.
ASSIGN COMPONENT 'LANGU_COM' OF STRUCTURE <fs_ad_postal>
TO <lfv_field_val>.
IF sy-subrc EQ 0.
IF is_bucusgen-cus_langu IS NOT INITIAL.
<lfv_field_val> = lv_langu.
ELSE.
<lfv_field_val> = 'EN'.
ENDIF.
ENDIF.

INSERT <fs_ad_postal> INTO TABLE <lt_anydata_postal>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'AD_POSTAL'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'AD_POSTAL'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
*--------------------------------------------------------------------*
*       'BP_CUS_CC'
*--------------------------------------------------------------------*
IF is_bpcuscc-company IS NOT INITIAL.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'BP_CUS_CC'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_bp_cus_cc>.
ASSIGN l_t_entity->* TO <lt_anydata_bp_cus_cc>.
<fs_bp_cus_cc>-bp_header = ev_temp_key_bp.
<fs_bp_cus_cc>-assgnm_id = '0000000002'.
<fs_bp_cus_cc>-company   = is_bpcuscc-company.
INSERT <fs_bp_cus_cc> INTO TABLE <lt_anydata_bp_cus_cc>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'BP_CUS_CC'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'BP_CUS_CC'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
ENDIF.
*--------------------------------------------------------------------*
*       'BP_SALES'
*--------------------------------------------------------------------*
IF is_bpsales-vkorg IS NOT INITIAL.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'BP_SALES'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_bp_sales>.
ASSIGN l_t_entity->* TO <lt_anydata_bp_sales>.
<fs_bp_sales>-bp_header = ev_temp_key_bp.
<fs_bp_sales>-vkorg     = is_bpsales-vkorg.
<fs_bp_sales>-csd_zterm = is_bpsales-csd_zterm.
<fs_bp_sales>-csd_waers = is_bpsales-csd_waers.
<fs_bp_sales>-csd_vsbed = is_bpsales-csd_vsbed.
INSERT <fs_bp_sales> INTO TABLE <lt_anydata_bp_sales>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'BP_SALES'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'BP_SALES'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
ENDIF.
*--------------------------------------------------------------------*
*       'BP_ADDUSG'
*--------------------------------------------------------------------*
*    FIELD-SYMBOLS: <fs_bp_addusg>         TYPE /mdgbp/_s_bp_pp_bp_addusg,
*                   <lt_anydata_bp_addusg> TYPE ANY TABLE.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'BP_ADDUSG'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_bp_addusg>.
ASSIGN l_t_entity->* TO <lt_anydata_bp_addusg>.
<fs_bp_addusg>-addrno    = ev_temp_key_bp_addr.
<fs_bp_addusg>-bp_header = ev_temp_key_bp.
<fs_bp_addusg>-bp_adrknd = 'XXDEFAULT'.
<fs_bp_addusg>-xdfadu    = abap_true.
INSERT <fs_bp_addusg> INTO TABLE <lt_anydata_bp_addusg>.
CLEAR lw_entity_data.
lw_entity_data-entity = 'BP_ADDUSG'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'BP_ADDUSG'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
*--------------------------------------------------------------------*
*       'BP_MLT_AS'
*--------------------------------------------------------------------*
*    FIELD-SYMBOLS :
*                    <lt_anydata_bp_mlt_as> TYPE ANY TABLE.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'BP_MLT_AS'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_bp_mlt_as>.
ASSIGN l_t_entity->* TO <lt_anydata_bp_mlt_as>.
IF <lt_anydata_bp_mlt_as> IS INITIAL.
<fs_bp_mlt_as>-bp_header = ev_temp_key_bp.
<fs_bp_mlt_as>-as_type   = 'CUST'.
<fs_bp_mlt_as>-assgnm_id = '0000000002'.
<fs_bp_mlt_as>-object_id = ev_temp_key_bp.
<fs_bp_mlt_as>-standard  = abap_true.
INSERT <fs_bp_mlt_as> INTO TABLE <lt_anydata_bp_mlt_as>.
ENDIF.
CLEAR lw_entity_data.
lw_entity_data-entity = 'BP_MLT_AS'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'BP_MLT_AS'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.
*--------------------------------------------------------------------*
*       'BP_CUSGEN'
*--------------------------------------------------------------------*
*    FIELD-SYMBOLS <lt_anydata_bp_cusgen> TYPE ANY TABLE.
CLEAR: l_s_entity, l_t_entity.
TRY .
go_mdg_conv->get_entity_structure(
EXPORTING
iv_entity_name = 'BP_CUSGEN'
iv_struct_type = go_mdg_conv->gc_struct_key_attr
*           iv_edition     = ABAP_FALSE
IMPORTING
er_structure   = l_s_entity
er_table       = l_t_entity
).
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.
ASSIGN l_s_entity->* TO <fs_bp_cusgen>.
ASSIGN l_t_entity->* TO <lt_anydata_bp_cusgen>.
IF <lt_anydata_bp_cusgen> IS INITIAL.
<fs_bp_cusgen>-bp_header   = ev_temp_key_bp.
<fs_bp_cusgen>-assgnm_id   = '0000000002'.
<fs_bp_cusgen>-kunnr       = gs_kunnr. "ev_temp_key_bp.
<fs_bp_cusgen>-ktokd       = lv_account_group.
<fs_bp_cusgen>-country     = lv_country_key. "'IN'."is_bucusgen-country.
<fs_bp_cusgen>-land1       = lv_country_key. "'IN'."is_bucusgen-country.
<fs_bp_cusgen>-region      = lv_region.      "'IN'."is_bucusgen-country.
IF is_bucusgen-cus_langu IS NOT INITIAL.
<fs_bp_cusgen>-cus_langu     = lv_langu."is_bucusgen-cus_langu.
ELSE.
<fs_bp_cusgen>-cus_langu     = 'EN'.
ENDIF.
INSERT <fs_bp_cusgen> INTO TABLE <lt_anydata_bp_cusgen>.
ENDIF.
CLEAR lw_entity_data.
lw_entity_data-entity = 'BP_CUSGEN'.
lw_entity_data-entity_data = l_t_entity.
INSERT lw_entity_data INTO TABLE et_entity_data.
CLEAR lw_entity_keys.
lw_entity_keys-entity = 'BP_CUSGEN'.
lw_entity_keys-tabl = l_t_entity.
INSERT lw_entity_keys INTO TABLE lt_entity_keys.

Write All entities into CR

TRY.
go_mdg_conv->write_entity_data( it_entity_data = et_entity_data ).
CLEAR et_entity_data.
CATCH cx_usmd_gov_api_core_error INTO go_core_error.
et_messages = go_core_error->mt_messages.
CATCH cx_usmd_gov_api_entity_write INTO lo_ent_error.
et_messages = lo_ent_error->mt_messages.
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.    "
ENDTRY.

Below Logic is used to Update Change Request ID with CR Description

Create a new change request using change request type and a description (mandatory)

TRY.
DATA: g_crequest_data TYPE usmd_s_crequest.
g_crequest_data-usmd_crequest    = ev_crequest_id.
g_crequest_data-usmd_creq_type   = im_changereq_type. "'CUST1P2'.
g_crequest_data-usmd_creq_text   = im_changreq_text.  "'Description for Change Request 
g_crequest_data-usmd_creq_status = '01'.              " IM_CHANGREQ_STAT
go_mdg_conv->write_crequest( is_crequest_data =  g_crequest_data ).
CATCH cx_usmd_gov_api_core_error INTO go_core_error.
et_messages = go_core_error->mt_messages.
CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.

Save the change request and the entity data using below logic.

TRY.
go_mdg_conv->save( ).
CATCH cx_usmd_conv_som_gov_api INTO go_som_gov_api_error.  "
et_messages = go_som_gov_api_error->mt_messages.
CATCH cx_usmd_app_context_cons_error INTO go_cons_error.  "
ls_message = go_cons_error->e_message.
APPEND ls_message TO et_messages.
CATCH cx_usmd_gov_api_core_error INTO go_core_error.
et_messages = go_core_error->mt_messages.

Commit and once you save the change request

COMMIT WORK AND WAIT.

Catch the error messages as below and Dequeue all Entities

CATCH cx_usmd_gov_api INTO go_gov_api_error.  "
et_messages = go_gov_api_error->mt_messages.
ENDTRY.

" DEQUE
go_mdg_conv->dequeue_entity_all( ).

If everything is fine, the workflow can be started for the change request and Submit the Change Request for further process

TRY.
        go_gov_api->start_workflow( iv_crequest_id = ev_crequest_id ).
      CATCH cx_usmd_gov_api_core_error.      
    ENDTRY.

 

Conclusion:

Build an RFC an can be called remotely in middle ware PI system where it will transfer data from CRM to SAP MDG where it will create a Change Request and Submit for review, send the created change request information back to CRM.

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