Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Program to Update Pricing in CRM retaining Manual Changes

*&-------------------------------------------------------------------
--*
*& Report  ZTEST_SERVICE_PRICE
*&
*&-------------------------------------------------------------------
--*
*&
*&
*&-------------------------------------------------------------------
--*

REPORT ztest_service_price.
DATA:
  lr_core        TYPE REF TO cl_crm_bol_core,
  lr_transaction TYPE REF TO if_bol_transaction_context,
  lv_result      TYPE REF TO if_bol_entity_col,
  lr_entity      TYPE REF TO cl_crm_bol_entity,
  lv_guid        TYPE crmt_genil_object_guid,
  lt_param       TYPE crmt_name_value_pair_tab,
  ls_param       TYPE crmt_name_value_pair,
  lv_success     TYPE abap_bool.

PARAMETERS : p_typ type CRMT_PROCESS_TYPE_DB,
             p_id  type CRMT_OBJECT_ID_DB.
lr_core ?= cl_crm_bol_core=>get_instance( ).
CHECK lr_core IS BOUND.
TRY.
   lr_core->load_component_set( iv_component_set_name = 'ONEORDER' ).

  CATCH cx_crm_genil_general_error .
ENDTRY.

SELECT SINGLE guid
                FROM crmd_orderadm_h
                INTO lv_guid
           WHERE object_id = p_id AND process_type = p_typ.

IF sy-subrc = 0.

  lr_core->get_root_entity(
    EXPORTING
      iv_object_name           =   'BTOrder'  " External Name of Obj
ect
      iv_object_guid           =  lv_guid   " Object GUID in Generic 
Interaction Layer
    RECEIVING
      rv_result                =   lr_entity  " Entity
  ).
*    CATCH cx_crm_genil_model_error.    "
  IF lr_entity IS BOUND.
    lr_entity = lr_entity->get_related_entity( iv_relation_name = 'BT
OrderHeader' ).

    IF lr_entity IS BOUND.
      lr_entity->switch_to_change_mode( ).
    ENDIF.
    IF lr_entity->lock( ) = 'X' AND lr_entity->is_changeable( ) = 'X
'.
      lr_entity->switch_to_change_mode( ).

      IF lr_entity IS BOUND.
        CALL METHOD lr_entity->get_related_entity
          EXPORTING
            iv_relation_name = 'BTHeaderPridoc'
          RECEIVING
            rv_result        = lr_entity.
      ENDIF.

      IF lr_entity IS BOUND.
        CALL METHOD lr_entity->get_related_entity
          EXPORTING
            iv_relation_name = 'CondHSetRel'
          RECEIVING
            rv_result        = lr_entity.
      ENDIF.

      ls_param-name  = 'RETAIN_MANUAL_CONDITIONS'.
      ls_param-value = 'X'.
      APPEND ls_param TO lt_param.

      TRY.
          CALL METHOD lr_entity->execute
            EXPORTING
              iv_method_name = 'Update'                         "#EC 
NOTEXT
              it_param       = lt_param
            RECEIVING
              rv_result      = lv_result.
        CATCH: cx_crm_genil_model_error cx_crm_bol_meth_exec_failed.
          RETURN.
      ENDTRY.

      lr_core->modify( ).

      lr_transaction = lr_entity->get_transaction( ).

Register for Save to Send Bdoc

CALL FUNCTION ‘CRM_EVENT_PUBLISH_OW’

EXPORTING
Iv_obj_name = ‘ORDERADM_H’

Iv_guid_hi = lv_guid   

Iv_kind_hi = ‘A’

Iv_event = ‘SAVE’

EXCEPTIONS

OTHERS = 0.

lv_success = lr_transaction->save( ).
IF lv_success EQ abap_true.
lr_transaction->commit( ).
      ENDIF.

    ENDIF.
  ENDIF.
ENDIF.

You might also like