SAP CRM – Maintain partners on a CRM order

In this article I’m going to show how to replace the current business partner assigned to a partner function on a CRM order.

CONSTANTS:
  co_order_guid     TYPE crmt_object_guid VALUE '00505685289E1EE68896E4172B205EAC', " CRMD_ORDERADM_H-GUID
  co_prt_function   TYPE crmt_partner_fct VALUE 'SLFN0003',                         " Parnter function
  co_new_partner_no TYPE crmt_partner_no  VALUE 'PE00640399',                        " New Partner No which replaces the old/current Partner
  co_old_partner_no TYPE crmt_partner_no  VALUE 'PE00640309'.                        " Partner No currently assigned to the partner function

DATA:
  lt_partners          TYPE comt_partner_comt,
  ls_partner           LIKE LINE OF lt_partners,
  lo_order             TYPE REF TO cl_ags_crm_1o_api,
  lv_log_handle        TYPE balloghndl.

cl_ags_crm_1o_api=>get_instance(
EXPORTING
    iv_header_guid                = co_order_guid
    iv_process_mode               = 'B' "A=create|B=change|C=Display|D=delete
    IMPORTING
      eo_instance = lo_order
).

ls_partner-ref_partner_no   = co_old_partner_no.
ls_partner-ref_partner_fct  = co_prt_function.
ls_partner-ref_no_type      = 'BP'.
ls_partner-ref_display_type = 'BP'.

ls_partner-error_flag = ' '.

ls_partner-partner_no    = co_new_partner_no.
ls_partner-partner_fct   = co_prt_function.
ls_partner-kind_of_entry = 'C'. "' '=Unknown|A=Automatic determination|B=Selected|C=Manual Entry|D=Via Interface
ls_partner-display_type  = 'BP'.
ls_partner-no_type       = 'BP'.

ls_partner-mainpartner   = 'X'.

INSERT ls_partner INTO TABLE lt_partners.

lo_order->set_partners(
  EXPORTING
    it_partner        = lt_partners    " Transfer Table for Partners to Partner Processing
).

IF sy-subrc = 0.
  lo_order->save( CHANGING cv_log_handle = lv_log_handle ).
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDIF.

Leave a Reply