Tuesday, 21 August 2012

BOL Change

DATA: lr_core TYPE REF TO cl_crm_bol_core.
lr_core = cl_crm_bol_core=>get_instance( ).
lr_core->start_up( 'BT' ).
*Get the BOL Core instance
lr_core = cl_crm_bol_core=>get_instance( ).

DATA:lv_query TYPE REF TO cl_crm_bol_query_service.
lv_query = cl_crm_bol_query_service=>get_instance( 'BTQuery1O' ).
** Set a search criterion
lv_query->set_property( iv_attr_name = 'OBJECT_ID' iv_value = '8000002731' ).

*Get Search Criteria
DATA:lv_objid TYPE REF TO data.
lv_objid = lv_query->get_property( iv_attr_name = 'OBJECT_ID' ).

*Get Corresponding Text for a given value.
*Text will be fetched from Domain If available or else,
*fetch from GENIL Component
DATA:lv_sex TYPE string.
lv_sex = lv_query->get_property_text( 'SEX' ).

* Execute the query and receive result
DATA:lv_result TYPE REF TO if_bol_entity_col.
lv_result = lv_query->get_query_result( ).
IF lv_result IS NOT INITIAL.
  DATA:lr_orderheader TYPE REF TO cl_crm_bol_entity,
       lr_order TYPE REF TO cl_crm_bol_entity.
  lr_order ?= lv_result->get_current( ).
  TRY.
      CALL METHOD lr_order->get_related_entity
        EXPORTING
          iv_relation_name = 'BTOrderHeader'
        RECEIVING
          rv_result        = lr_orderheader.
    CATCH cx_crm_genil_model_error .
  ENDTRY.

  lr_orderheader->switch_to_change_mode( ).
  IF lr_orderheader->lock( ) = 'X'.
    IF lr_orderheader->is_changeable( ) = 'X'.

*      lr_orderheader->set_property( iv_attr_name = 'DESCRIPTION'
*                                                     iv_value     = 'Description Changed' ). or

      lr_orderheader->if_bol_bo_property_access~set_property( iv_attr_name = 'DESCRIPTION'
                                                                                                iv_value     = 'Description Changed' ).

*Send All Changes to BO Layer
      lr_core->modify( ).

*6.  Save and Commit the Changes Using Global Tranaction Context
      DATA:lv_transaction TYPE REF TO if_bol_transaction_context .
      lv_transaction = lr_core->get_transaction( ).
      lv_transaction->save( ).
      lv_transaction->commit( ).
    ENDIF.
  ENDIF.
ENDIF.

BOL Create

DATA: lv_bol_core TYPE REF TO cl_crm_bol_core.
*Get the BOL Core instance
lv_bol_core = cl_crm_bol_core=>get_instance( ).
*Load the component set
lv_bol_core->load_component_
set( 'BT' ).

*1.  Build Parameters to create an Entity
*    Here a Order with Technical Name 'BTOrder'
DATA lt_parms TYPE crmt_name_value_pair_tab.
DATA ls_parms TYPE crmt_name_value_pair.

ls_parms-name = 'PROCESS_TYPE'.
ls_parms-value = 'BPAT'.
APPEND ls_parms TO lt_parms.

*2.  Get Factory for Business Object
DATA:lv_order_factory TYPE REF TO cl_crm_bol_entity_factory.
lv_order_factory = lv_bol_core->get_entity_
factory( 'BTOrder' ).

*3.  Create Root Entity
DATA:lv_order TYPE REF TO cl_crm_bol_entity.
lv_order = lv_order_factory->create( lt_parms ).

*4.  Create Child Objects
DATA:lv_order_header TYPE REF TO cl_crm_bol_entity,
     lv_actity_header TYPE REF TO cl_crm_bol_entity.

lv_order_header = lv_order->create_related_
entity( 'BTOrderHeader' ).
lv_actity_header = lv_order->create_related_
entity( 'BTHeaderActivityExt' ).

*5.  Submit Root Objects and Child Objects Which are created
lv_bol_core->modify( ).

*6.  Save and Commit Changes Using Global Tranaction Context
DATA:lv_transaction TYPE REF TO if_bol_transaction_context .
lv_transaction = lv_bol_core->get_transaction( ).
lv_transaction->save( ).
lv_transaction->commit( ).