Thursday, 13 September 2012

BOL Find


*Get the BOL Core instance
DATA: lr_core1 TYPE REF TO cl_crm_bol_core.
*Load the component set Or Component
lr_core1 = cl_crm_bol_core=>get_instance( ).
lr_core1->start_up( 'BP_APPL' ).

*Determine Dynamic Query Services Available
DATA:lv_obj_model  TYPE REF TO if_genil_obj_model.
lv_obj_model = cl_crm_genil_model_service=>get_runtime_model( ).

DATA:lt_query_names TYPE crmt_ext_obj_name_tab.
CALL METHOD lv_obj_model->get_object_list
  EXPORTING
    iv_object_kind     = if_genil_obj_model=>dquery_object
*    iv_ws_enabled_only = ABAP_FALSE
  IMPORTING
    et_object_list     = lt_query_names.


**Select Particular Query
DATA:lv_query_name TYPE crmt_ext_obj_name.
READ TABLE lt_query_names INTO lv_query_name INDEX 6. "'BuilContactAdvancedSearch '

*Create Query Service by passing the dynamic search object name
DATA:lv_query TYPE REF TO cl_crm_bol_dquery_service.
lv_query = cl_crm_bol_dquery_service=>get_instance( lv_query_name ).


*Set General Query parameters for maximum number of hits
DATA lt_parms TYPE crmt_name_value_pair_tab.
DATA ls_parms TYPE crmt_name_value_pair.

ls_parms-name = 'MAX_HITS'.
ls_parms-value = '5'.
APPEND ls_parms TO lt_parms.
lv_query->set_query_parameters( it_parameters = lt_parms ).

*Add Selection Criteria where BP number > 30
CALL METHOD lv_query->add_selection_param
  EXPORTING
    iv_attr_name = 'BP_NUMBER'
    iv_sign      = 'I'
    iv_option    = 'GT'
    iv_low       = '0000311966'                             "0000311966
    iv_high      = ' '.


*Execute Query and Receive Result
DATA:lv_result_tab TYPE REF TO if_bol_entity_col.  "To Capture Multiple Records
lv_result_tab = lv_query->get_query_result( ).

lv_result_tab->sort( iv_attr_name = 'BP_NUMBER'
                     iv_sort_order = if_bol_bo_col=>sort_descending ).

*Use Iterator to access entities in query result
DATA:lv_iterator TYPE REF TO if_bol_entity_col_iterator. "or IF_BOL_ENTITY_COL
lv_iterator = lv_result_tab->get_iterator( ).


DATA:lv_bp TYPE REF TO if_bol_bo_property_access. "CL_CRM_BOL_ENTITY
lv_bp = lv_iterator->find_by_property( iv_attr_name = 'BP_NUMBER'
                                       iv_value = '0000406648' ).


DATA:lv_bp_find TYPE REF TO cl_crm_bol_entity.
lv_bp_find ?= lv_bp.
lv_bp_find = lv_result_tab->find( iv_entity = lv_bp_find ).

*Get First Entity in the result list.
*Entity is contact person here.
DATA:lv_entity TYPE REF TO cl_crm_bol_entity.
lv_entity  = lv_iterator->get_first( ).

*Loop through Further Entities....
WHILE lv_entity IS BOUND. "If lv_entity is not initial..

*Access Attributes of the Business Object (Entity) Selected
  DATA:lv_bpnumber TYPE string,
          lv_contactbp  TYPE string.
 
  lv_bpnumber = lv_entity->get_property_as_string( 'BP_NUMBER' ).
  lv_contactbp  = lv_entity->get_property_as_string( 'CONP_NUMBER' ).

  WRITE: / lv_bpnumber.

  lv_entity = lv_iterator->get_next( ).

ENDWHILE.

BOL Delete


DATA: lr_core TYPE REF TO cl_crm_bol_core.
*Get the BOL Core instance
lr_core = cl_crm_bol_core=>get_instance( ).
*Load the component set
lr_core->load_component_set( 'BP_APPL' ).
*------------------------------------------------------------
*Raise the query instance by passing the search object name
DATA:lr_query TYPE REF TO cl_crm_bol_query_service.
lr_query = cl_crm_bol_query_service=>get_instance(
                  iv_query_name = 'BuilContactPersonSearch' ).

DATA it_parms TYPE crmt_name_value_pair_tab.
DATA wa_parms TYPE crmt_name_value_pair.


wa_parms-name = 'CONP_NUMBER'.
wa_parms-value = '400788'.
APPEND wa_parms TO it_parms.

*Add the selection parameters
CALL METHOD lr_query->set_query_parameters
  EXPORTING
    it_parameters = it_parms.

*Get the result list
DATA:lr_result TYPE REF TO if_bol_entity_col.
lr_result = lr_query->get_query_result( ).

*Get the first entity in the result list
DATA:lr_entity TYPE REF TO cl_crm_bol_entity.
lr_entity ?= lr_result->get_first( ).

DATA lv_string TYPE string.
*-------------------------------------------------------
*Lock and modify the property
IF  lr_entity->lock( ) = if_genil_boolean=>true.
  lr_entity->delete( ).
*RV_STATUS = LR_CORE->ROOT_DELETE( iv_entity = LR_ENTITY ).
  lr_core->modify( ).

  DATA lv_transaction TYPE REF TO if_bol_transaction_context.
  lv_transaction = lr_core->get_transaction( ).
  lv_transaction->save( ).
  lv_transaction->commit( ).
  lr_core->modify( ).
ENDIF.

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( ).

Thursday, 12 July 2012

Most Used Tables in SAP CRM


Most Used Database Tables in SAP CRM

TableDescription
CRMD_ORDERADM_HContains the basic Header Information on Any Transaction created through CRMD_ORDER. This could be lead, opportunity, orders, quotations etc
CRMD_ORDERADM_IContains the basic item Information on Any Transaction created through CRMD_ORDER. This could be lead, opportunity, orders, quotations etc
BUT000 , BUT001Business Partner General Data
BUT100SAP CRM Business Partner Roles
BUT150SAP CRM BP Relationship
COMM_PRODUCTProduct Master
CRMD_ORDER_INDEXDescription
CRMD_PARTNEROrder partner Information
CRM_JESTOrder Status

GUID



What is GUID in SAP CRM ?

As we learnt in SD, a Transaction is uniquely idenfied in the database using a Transaction Number / Document Number. In SAP CRM this uniqueness is not driven by the document number, but by SAP GUID. An SAP GUID is a unique field generated by SAP which will essentially guarantee a big unique alpha-numeric numer that can act as a primary key for the database tables.
As you can see from the basic ORDER table – CRMD_ORDERADM_H, there are two leads with the same Lead Number of #476, but what differentiates the table rows is the GUID. GUIDs are created using the FM – GUID_CREATE.
What intrigues the folks from the core SAP ECC system is that over there there is no concept of GUID, whereas in SAP CRM this becomes the primary key. This was necessitated by a number of problems – Mostly related to the fact that CRM is generally not a master data system and also the fact that CRM is essentially built to interact with mobile clients as well which are not necessarily connected to the server. Let’s consider the following scenarios.
1. A mobile order (say Txn Type – ZTA) was taken by a field rep on his laptop and the laptop generated an order # 1234. This number was generated without consulting the Server and might not reflect the current number range scenarios for the Txn type ZTA. Now what happens when the fields sales rep connects to the server at the end of his day and tries to sync the data ? If the Order # was the only primary key, obviously you are in trouble – especially since its the primary field. So SAP CRM came up with the concept of GUID which uniquely identifes the transaction in the system no matter what.
2. Also, it is not always the case that all transactions need to be created in SAP CRM. For example, regular sales orders can be created in SAP SD whereas Service Orders, leads and opportunities could be created in SAP CRM. Since data needs to be synchronized between the two systems – this could lead to potential issues. Although there are mitigatory mechanisms for situations like this ( Like creating leading systems, making number ranges external in receiving system etc ) SAP has to plan for its own contingencies and GUID is the key for it.

Monday, 9 July 2012

Adding Widgets

Click here to Download

Types of Business Objects in BOL

The business objects are subdivided into 6 kinds:
root objects, 
access objects, 
dependant objects, 
query objects, 
query result objects, 
dynamic query objects.


Root Object:
The root object is the only object within the hierarchy structure of a data model that is assigned as superior object to all the data objects. Each root object is also access data.
Access Object:
An access object is a special type of Business object, who’s ID can be accessed to determine both the attributes of the access object itself and those of its dependent objects.
It is also a root object but it handles transactional data.
Dependent Objects:
A dependent object is a special type of business object whose attributes cannot be determined solely from the business object ID. You can only determine its attributes by using the ID of the superior access object.

 For example: ONEORDER (BOL component set) ô€„º BTOrder (Root Object) ô€„º BTAdminH (Access Object) ô€„ºBTCustomerH (Dependent Object)

Search Objects:

A Query Object is special type of BO, whose attributes are the parameters of search request.
It is like parameters

Dynamic Search Object:

A Query Object is special type of BO, whose attributes are the parameters of search request.  It is possible to create select options of the parameter.

It is like select-options.

Search Result Object:

The result object of a search request has a dictionary structure assigned and displays data from different BOs as a result last.  To link the search result object to the data model hierarchy the search object is associated with the root object of the same component.

After query, the output is there in the search result object like internal table.  Here the internal table has the same structure as the root objects.

BOL Programming - Dquery Objects

*Get the BOL Core instance
DATA: lr_core1 TYPE REF TO cl_crm_bol_core.
*Load the component set Or Component
lr_core1 = cl_crm_bol_core=>get_instance( ).
lr_core1->start_up( 'BP_APPL' ).

*Determine Dynamic Query Services Available
DATA:lv_obj_model  TYPE REF TO if_genil_obj_model.
lv_obj_model = cl_crm_genil_model_service=>get_runtime_model( ).

DATA:lt_query_names TYPE crmt_ext_obj_name_tab.
CALL METHOD lv_obj_model->get_object_list
  EXPORTING
    iv_object_kind     = if_genil_obj_model=>dquery_object
*    iv_ws_enabled_only = ABAP_FALSE
  IMPORTING
    et_object_list     = lt_query_names.


**Select Particular Query
DATA:lv_query_name TYPE crmt_ext_obj_name.
READ TABLE lt_query_names INTO lv_query_name INDEX 6. "'BuilContactAdvancedSearch '

*Create Query Service by passing the dynamic search object name
DATA:lv_query TYPE REF TO cl_crm_bol_dquery_service.
lv_query = cl_crm_bol_dquery_service=>get_instance( lv_query_name ).


*Set General Query parameters for maximum number of hits
DATA lt_parms TYPE crmt_name_value_pair_tab.
DATA ls_parms TYPE crmt_name_value_pair.

ls_parms-name = 'MAX_HITS'.
ls_parms-value = '5'.
APPEND ls_parms TO lt_parms.
lv_query->set_query_parameters( it_parameters = lt_parms ).

*Add Selection Criteria where BP number > 30
CALL METHOD lv_query->add_selection_param
  EXPORTING
    iv_attr_name = 'BP_NUMBER'
    iv_sign      = 'I'
    iv_option    = 'GT'
    iv_low       = '0000311966'
    iv_high      = ' '.


*Execute Query and Receive Result
DATA:lv_result_tab TYPE REF TO if_bol_entity_col.  "To Capture Multiple Records
lv_result_tab = lv_query->get_query_result( ).

*Use Iterator to acces entities in query result
DATA:lv_iterator TYPE REF TO if_bol_entity_col_iterator. "or IF_BOL_ENTITY_COL
lv_iterator = lv_result_tab->get_iterator( ).

*Get First Entity in the result list.
*Entity is contact person here.
DATA:lv_entity TYPE REF TO cl_crm_bol_entity.
lv_entity  = lv_iterator->get_first( ).


*..........Begin of Messages
*Acces Messages of Business Objects
*Use the Message Container Manager
DATA:lv_mcm TYPE REF TO cl_crm_genil_mess_cont_manager.
lv_mcm = lr_core1->get_message_cont_manager( ).

*To Obtain the Message Container for Relavent Object
DATA:lv_object_name TYPE crmt_ext_obj_name,
     lv_object_id TYPE crmt_genil_object_id.

lv_object_name = lv_entity->get_name( ).
lv_object_id   = lv_entity->get_key( ).

DATA:lv_mc TYPE REF TO if_genil_message_container.
lv_mc = lv_mcm->get_message_cont( iv_object_name = lv_object_name
                                  iv_object_id = lv_object_id ).
*Get Relavent messages..
DATA:lv_number_of_errors TYPE int4,
     lt_messages TYPE crmt_genil_message_tab.

*Get Number of Messages Count
lv_number_of_errors = lv_mc->get_number_of_messages( lv_mc->mt_error ).
IF lv_number_of_errors <> 0.
*Get List of Error messages
  lv_mc->get_messages( EXPORTING iv_message_type = lv_mc->mt_error
                       IMPORTING et_messages = lt_messages ).
ENDIF.
*..........End of Messages


*Loop through Further Entities....
WHILE lv_entity IS BOUND. "Means lv_entity is not initial..

*Access Attributes of the Business Objects Selected
  DATA:lv_bpnumber TYPE string,
       lv_contactbp  TYPE string.

  lv_bpnumber = lv_entity->get_property_as_string( 'BP_NUMBER' ).
  lv_contactbp  = lv_entity->get_property_as_string( 'CONP_NUMBER' ).

*Get 1:1 Related Entities of BP of BuilSalesEmployeeRel Child Cardinality 1
  DATA:lv_employee_responsible TYPE REF TO cl_crm_bol_entity. "Only one record
  lv_employee_responsible = lv_entity->get_related_entity( 'BuilSalesEmployeeRel' ).

  DATA:lv_empbp TYPE string.
  lv_empbp = lv_employee_responsible->get_property_as_string( 'SALESEMPLOYEE' ).

*Get 0:n Related Entities of BP of BuilContactPersonAddressRel Child Cardinality 0..n
  DATA:lv_address TYPE REF TO if_bol_entity_col.
  lv_address = lv_entity->get_related_entities( iv_relation_name = 'BuilContactPersonAddressRel' ).

*Use Iterator to acces entities in query result
  DATA:lv_iterator_add TYPE REF TO if_bol_entity_col_iterator. "or IF_BOL_ENTITY_COL
  lv_iterator_add = lv_address->get_iterator( ).

*Get First Entity in the result list.
*Entity is address of BP here.
  DATA:lv_entity_add TYPE REF TO cl_crm_bol_entity.
  lv_entity_add  = lv_iterator_add->get_first( ).
*Loop through all address of BP....
  WHILE lv_entity_add IS BOUND. "Means lv_entity is not initial..
    DATA:lv_stdardaddress  TYPE string.
    lv_stdardaddress = lv_entity_add->get_property_as_string( 'STANDARDADDRESS' ).

    WRITE:/ lv_bpnumber,        "Business Partner
          / lv_contactbp,       "Contact Person
          / lv_empbp,           "Sales Employee Responsible
          / lv_stdardaddress.   "Standard Address

    lv_entity_add = lv_iterator_add->get_next( ).
  ENDWHILE.
  lv_entity = lv_iterator->get_next( ).
ENDWHILE.

BOL Porgramming - Query Objects


*Get the BOL Core instance
DATA: lr_core1 TYPE REF TO cl_crm_bol_core.
*Load the component set Or Component
lr_core1 = cl_crm_bol_core=>get_instance( ).
lr_core1->start_up( 'BP_APPL' ).

*Determine Query Services Available
DATA:lv_obj_model  TYPE REF TO if_genil_obj_model.
lv_obj_model = cl_crm_genil_model_service=>get_runtime_model( ).

DATA:lt_query_names TYPE crmt_ext_obj_name_tab.
CALL METHOD lv_obj_model->get_object_list
  EXPORTING
    iv_object_kind     = if_genil_obj_model=>query_object
*    iv_ws_enabled_only = ABAP_FALSE
  IMPORTING
    et_object_list     = lt_query_names.


*Select Perticular Query
DATA:lv_query_name TYPE crmt_ext_obj_name.
READ TABLE lt_query_names INTO lv_query_name INDEX 6. "'BuilContactPersonSearch'

*Create Query Service by passing the search object name
DATA:lv_query TYPE REF TO cl_crm_bol_query_service.
lv_query = cl_crm_bol_query_service=>get_instance(
                  iv_query_name = lv_query_name ).

*Set Search Criteria
lv_query->set_property( iv_attr_name = 'BP_NUMBER'
                        iv_value = '0000311966' ).

*Read Search Criteria
DATA:lv_city TYPE string.
lv_city = lv_query->get_property_as_string( 'BP_NUMBER' ).

*Executer Query and Receive Result
DATA:lv_result_tab TYPE REF TO if_bol_entity_col.  "To Capture Multiple Records
lv_result_tab = lv_query->get_query_result( ).