Wednesday, 21 October 2015

CRM Add Partner to Incident

The following function can be used to add bespoke partner functions to SAP CRM Incidents - in this case, a "Requester".
The bit that threw me was the need for a BAPI-Commit after the CRM_ORDER_SAVE; it seems SAP have added another layer of flexibility / complexity


FUNCTION 
ZSHA_ORDER_MAINTAIN_ADD.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_CALL) TYPE  CRMT_OBJECT_ID
*"     REFERENCE(I_REQUESTER) TYPE  CRMT_PARTNER_NO
*"     REFERENCE(I_SOLD_TO) TYPE  CRMT_PARTNER_NO
*"----------------------------------------------------------------------

datals_partner type CRMT_PARTNER_COM,
      lt_partner type CRMT_PARTNER_COMt,
      lt_guid type CRMT_OBJECT_GUID_TAB,
      ls_guid type CRMT_OBJECT_GUID,
      lt_input_fields type CRMT_INPUT_FIELD_TAB,
      ls_input_fields type CRMT_INPUT_FIELD,
      ls_field_names type CRMT_INPUT_FIELD_NAMES,
      lt_field_names TYPE CRMT_INPUT_FIELD_NAMES_TAB,
      lt_orderadm_h TYPE CRMT_ORDERADM_H_COMT,
      ls_orderadm_h type crmt_orderadm_h_com,
      lt_exception type CRMT_EXCEPTION_T.

CALL FUNCTION 'CRM_ORDERADM_H_GUID_GET_DB'
  EXPORTING
    IV_OBJECT_ID           i_call
*   IV_OBJECT_TYPE         =
  IMPORTING
    ET_GUID                lt_guid
 EXCEPTIONS
   RECORD_NOT_FOUND       1
   OTHERS                 2.

READ TABLE lt_guid into ls_guid INDEX 1.

ls_partner-ref_guid ls_guid.
ls_partner-ref_kind 'A'.
ls_partner-ref_partner_handle '0001'.
ls_partner-kind_of_entry 'C'.
ls_partner-partner_fct 'Z0000015'.
ls_partner-partner_no i_requester.
if ls_partner-partner_no(4ne '0000'.
  CONCATENATE '0000' ls_partner-partner_no into ls_partner-partner_no.
endif.

ls_partner-display_type 'BP'.
ls_partner-no_type 'BP'.


append ls_partner to lt_partner.

*ls_input_fields-REF_HANDLE
ls_input_fields-REF_GUID     ls_guid.
ls_input_fields-REF_KIND     'A'.
ls_input_fields-OBJECTNAME   'PARTNER'.
ls_input_fields-LOGICAL_KEY  '0001'.



ls_field_names-fieldname 'DISPLAY_TYPE'.
INSERT ls_field_names INto table ls_input_fields-FIELD_NAMES.
ls_field_names-fieldname 'KIND_OF_ENTRY'.
INSERT ls_field_names INto table ls_input_fields-FIELD_NAMES.
ls_field_names-fieldname 'NO_TYPE'.
INSERT ls_field_names INto table ls_input_fields-FIELD_NAMES.
ls_field_names-fieldname 'PARTNER_FCT'.
INSERT ls_field_names INto table ls_input_fields-FIELD_NAMES.
ls_field_names-fieldname 'PARTNER_NO'.
INSERT ls_field_names INto table ls_input_fields-FIELD_NAMES.

append ls_input_fields to lt_input_fields.



*ls_orderadm_h-guid = ls_guid.
*append ls_orderadm_h to lt_orderadm_h.


  CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    EXPORTING
*      it_activity_h               = lt_activity_h
*      it_appointment              = lt_appointment
*     it_text                      = lt_text
      it_partner                  lt_partner
*      it_service_os               = lt_service_os
*      it_status                   = lt_status
*      it_sales                    = lt_sales
*      it_service_h                = lt_service_h
  IMPORTING
      ET_EXCEPTION                  lt_exception
    CHANGING
*      ct_orderadm_h                = lt_orderadm_h
      ct_input_fields              lt_input_fields
**    CV_LOG_HANDLE                =
**    CT_PARTNER_ATTRIBUTES        =
**    CT_DOC_FLOW                  =
    EXCEPTIONS
      error_occurred               1
      document_locked              2
      no_change_allowed            3
      no_authority                 4
      OTHERS                       5.

CALL FUNCTION 'CRM_ORDER_SAVE'
  EXPORTING
    IT_OBJECTS_TO_SAVE           lt_guid
*   IV_UPDATE_TASK_LOCAL         = FALSE
*   IV_SAVE_FRAME_LOG            = FALSE
*   IV_NO_BDOC_SEND              = FALSE
*   IT_ACTIVE_SWITCH             =
* IMPORTING
*   ET_SAVED_OBJECTS             =
*   ET_EXCEPTION                 =
*   ET_OBJECTS_NOT_SAVED         =
* CHANGING
*   CV_LOG_HANDLE                =
*   CT_NOCHECK_BEFORE_SAVE       =
 EXCEPTIONS
   DOCUMENT_NOT_SAVED           1
   OTHERS                       2
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.


commit work and wait.

ENDFUNCTION.

No comments:

Post a Comment