cancel
Showing results for 
Search instead for 
Did you mean: 

Modify Busines Partner data on save event using BDT

fszenborn
Discoverer
0 Kudos
795

Hi

How to manipulate BP data before save event in order to add additional role to BP?

I have requirement to add additional role for busines partner(BP) whenever a new BP is created with the Busines Partner (Gen.) role. To achieve this I decided to create function module and attach it to DSAVE event using BDT.

The problem that I am facing is that the code is not saving data to database when executed via BDT event.
The below program works only when executed as executable program. I know that this is due to need of BAPI transaction commit. However I don't know how to achieve the same result using BDT event.
Can anyone help me with this and give any hints how to properly manipulate BP's data in BDT event?


 CONSTANTS:
c_task_update TYPE bus_ei_object_task VALUE 'U',
DATA:
ls_bp TYPE cvis_ei_extern,
lt_bp TYPE cvis_ei_extern_t,
lt_role TYPE bus_ei_bupa_roles_t,
lt_return TYPE bapiretm,
ev_guid TYPE bu_partner_guid,
ls_but000 LIKE but000,
lv_edit_mode TYPE irtp_us_status-act.
CALL FUNCTION 'BUPA_NUMBERS_GET' "
EXPORTING
iv_partner = '78' ""Busines partner ID to be added with new role
IMPORTING
ev_partner_guid = ev_guid.

ls_bp-partner-header-object_task = c_task_update. " ls_bp-partner-header-object_instance-bpartnerguid = ev_guid. *------------------------------------------------------------------------------ * Role *------------------------------------------------------------------------------ APPEND INITIAL LINE TO lt_role ASSIGNING FIELD-SYMBOL(<fs_role>). <fs_role>-task = c_task_update. <fs_role>-data_key = 'UKM000'. "Role key - SAP credit managemnt * Add role to main structure ls_bp-partner-central_data-role-roles = lt_role. ls_bp-partner-central_data-role-current_state = abap_true. *------------------------------------------------------------------------------ * Call API *------------------------------------------------------------------------------ INSERT ls_bp INTO TABLE lt_bp. cl_md_bp_maintain=>maintain( EXPORTING i_data = lt_bp IMPORTING e_return = lt_return ). CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

Accepted Solutions (1)

Accepted Solutions (1)

fszenborn
Discoverer
0 Kudos

Finally I managed to create FM module that automatically creates SAP UKM Role on BDT DSAVE event.

The code below:

FUNCTION z_bp_test2.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"----------------------------------------------------------------------
  CONSTANTS: gc_con_create    TYPE irtp_us_status-act VALUE '01',
             gc_ukm_role_code TYPE bu_partnerrole VALUE 'UKM000'.

  DATA: io_facade        TYPE REF TO cl_ukm_facade,

        io_partner       TYPE REF TO cl_ukm_business_partner,

        io_bupa_factory  TYPE REF TO cl_ukm_bupa_factory,

        io_account       TYPE REF TO cl_ukm_account,

        lw_bp_credit_sgm TYPE ukm_s_bp_cms_sgm,

        lwa_ukm_s_bp_cms TYPE ukm_s_bp_cms,

        lv_partner       TYPE bu_partner,

        lv_credit_sgmnt  TYPE ukm_credit_sgmnt,

        lt_current_roles TYPE TABLE OF bup_bprole,

        ls_ukm_role_data TYPE bup_bprole,

        ls_but000        LIKE but000,

        ls_config        LIKE z_bp_credit_t,

        ls_ukm_role      TYPE but100,

        lv_edit_mode     TYPE irtp_us_status-act.

*"----------------------------------------------------------------------
*"*"Check whether BP qualifies as a newly created for automatic assignment of credit management role and load configuration from maintenance view
*"----------------------------------------------------------------------
  CALL FUNCTION 'BUS_PARAMETERS_ISSTA_GET'
    IMPORTING
      e_aktyp = lv_edit_mode.

  IF lv_edit_mode <> gc_con_create .
    EXIT.
  ENDIF.

  CALL FUNCTION 'BUP_BUPA_BPROLES_GET'
    TABLES
      t_bproles = lt_current_roles.

  READ TABLE lt_current_roles INTO ls_ukm_role_data INDEX 1.

  SELECT * FROM z_bp_credit_t INTO ls_config WHERE bp_role EQ ls_ukm_role_data-role.

  ENDSELECT.

  IF ls_config IS INITIAL.
    EXIT.
  ENDIF.

*"----------------------------------------------------------------------
*"*"Assign credit management data and save
*"----------------------------------------------------------------------

  CALL FUNCTION 'BUP_BUPA_BUT000_GET'
    IMPORTING
      e_but000 = ls_but000.

  lv_partner = ls_but000-partner.
  lv_credit_sgmnt = ls_config-credit_sgmnt.

  io_facade = cl_ukm_facade=>create( i_activity = cl_ukm_cnst_eventing=>bp_maintenance ).

  io_bupa_factory = io_facade->get_bupa_factory( ).

  io_partner = io_bupa_factory->get_business_partner( lv_partner ).

  io_partner->get_bp_cms( IMPORTING es_bp_cms = lwa_ukm_s_bp_cms ).

  lwa_ukm_s_bp_cms-limit_rule = ls_config-limit_rule.

  io_partner->set_bp_cms( lwa_ukm_s_bp_cms ).

  CALL METHOD io_bupa_factory->get_credit_account
    EXPORTING
      i_partner         = lv_partner
      i_credit_sgmnt    = lv_credit_sgmnt
    RECEIVING
      ro_credit_account = io_account.

  io_account->get_bp_cms_sgm( IMPORTING es_bp_cms_sgm = lw_bp_credit_sgm ).

  lw_bp_credit_sgm-credit_limit = ls_config-credit_limit.
  lw_bp_credit_sgm-limit_valid_date = ls_config-lim_val_date.
  lw_bp_credit_sgm-limit_chg_date = sy-datum.

  io_account->set_bp_cms_sgm( EXPORTING is_bp_cms_sgm = lw_bp_credit_sgm ).

  ls_ukm_role-partner = lv_partner.
  ls_ukm_role-rltyp = gc_ukm_role_code.
  ls_ukm_role-valid_from = 20210401000000.
  ls_ukm_role-valid_to = 99991231235959.
  INSERT but100 FROM ls_ukm_role.

  io_bupa_factory->save_all(
  EXPORTING
  i_upd_task = abap_true ).

ENDFUNCTION.

Answers (1)

Answers (1)

GitteGreibe
Participant
0 Kudos

Hi Filip

You can consider to start creating the BP in the UKM000 role instead of starting the creation process in the General role.

If you just add the UKM000 role to the BP you create, will you then not need to fill in some data for this BP role?

BR Gitte.