The BOL API consists of various interfaces and classes that you can use to access business
data:
- CL_CRM_BOL_CORE
You can use this class to access directly with Business object implementations.
Also said as Heart of Root objects , only single instance can exists per session.
- CL_CRM_BOL_QUERY_SERVICE
You use this class for a simple search to select a business objects.
Also called as Query service provider.
- CL_CRM_BOL_DQUERY_SERVICE
You use this class for a dynamic search to select a business objects.
- CL_CRM_BOL_ENTITY
You use this class for implementing business objects.
Also called as Entity Service Provider , represents unique object instance.
- CL_CRM_BOL_ENTITY_MANAGER
Holds the refrences of all the BOL entities in a table attribute (ENTITY_TAB).
- IF_BOL_TRANSACTION_CONTEXT
You use this interface to control transaction behavior.
- IF_BOL_BO_COL
You use this interface to provide collections to hold business objects.
- IF_BOL_BO_PROPERTY_ACCESS
You can use this interface to access the property of an attribute of entity class.
Sample Code :
Loading a BOL object using CL_CRM_BOL_CORE
data : lr_core type ref to cl_crm_bol_core.
try.
lr_core = cl_crm_bol_core=>get_instance( ).
lr_core->start_up('BOL object name').
Catch cx_crm_genil_general_error.
Endtry.
Build Create Parameters of Root Object.
DATA: ls_params TYPE crmt_name_value_pair.
DATA: lt_params TYPE crmt_name_value_pair_tab.
CLEAR lt_params[].
* Build create parameters for Root Object
* Status Profile
ls_params-name = 'STSMA'.
ls_params-value = 'ABC'.
APPEND ls_params TO lt_params..
* Objective
ls_params-name = 'OBJECTIVE'.
ls_params-value = ls_data-objective.
APPEND ls_params TO lt_params.
Create Root Instance or Entity Factory.
DATA : lr_factory TYPE REF TO cl_crm_bol_entity_factory.
DATA : lr_entity TYPE REF TO cl_crm_bol_entity.
* Create Root Instance in a Collection.
TRY.
CALL METHOD lr_core->root_create
EXPORTING
iv_object_name = lc_entity
iv_create_param = lt_params
iv_number = 1
RECEIVING
rv_result = lr_col.
* Obtain Factory of Root Object in Entity.
lr_factory = lr_core->get_entity_factory( iv_entity_name = lc_entity ).
lr_entity = lr_factory->create( lt_params ).
CATCH cx_crm_unsupported_object.
Retrieving the data (Query object or dynamic query objects)
data: lr_qs type ref to cl_crm_bol_dquery_service.
ls_param type crmt_name_value_pair.
lt_param type crmt_name_value_pair_tab.
lr_result type ref to if_bol_entity_col.
lr_iter type ref to if_bol_entity_col_iterator.
Lr_entity type ref to cl_crm_bol_entity.
“Get and prepare dynamic query service
lr_qs ?= cl_crm_bol_dquery_service=>get_instance('SearchObjectName').
ls_param-Name = 'MAX_HITS'.
ls_param-Value = '5'.
append ls_param to lt_param.
lr_qs->set_query_parameters( lt_param ).
lr_qs->add_selection_param( iv_attr_name = 'Attr_id'
iv_sign = 'I'
iv_low = 'VALUE'
iv_high = ' ').
lr_result = lr_qs->get_dquery_result.
Retrieving data from BOL entities.
lr_result = lr_qs->get_query_result.
Lr_iter = lr_result->get_iterator( ).
Lr_entity = lr_iter->get_first( ).
While lr_entity is bound.
Lv_name = lr_entity->get_property_as_string( ‘name’ ).
Lv_id = lr_entity->get_property_as_string( ‘id’ ).
Write :
Lr_entity = lr_iter->get_next( ).
End while.
Saving Objects
data lr_tx TYPE REF TO if_bol_transaction_context.
data lr_entity TYPE REF TO cl_crm_bol_entity.
data lr_core TYPE REF TO cl_crm_bol_core.
lr_entity ?= me->typed_context->object_name->collection_wrapper->get_current( ).
lr_tx = lr_entity->get_transaction( ).
if lr_tx is not BOUND.
lr_core = cl_crm_bol_core=>get_instance( ).
lr_tx = lr_core->begin_transaction( ).
endif.
if lr_tx is bound.
if lr_tx->check_save_possible( ) = abap_true.
check lr_tx->save( ) = abap_true.
lr_tc->commit( ).
endif.
endif.
me->view_group_context->reset( ).
Cancel Changes or Reset Objects
method EH_ONCANCEL.
DATA lr_entity TYPE REF TO cl_crm_bol_entity.
data lr_tx TYPE REF TO if_bol_transaction_context.
lr_entity ?= me->typed_context->node->collection_wrapper->get_current( ).
lr_tx = lr_entity->get_transaction( ).
lr_tx->revert( iv_suppress_buffer_sync = abap_true ).
me->view_group_context->reset( ).
endmethod.
Edit Objects
data: lr_entity type REF TO cl_crm_bol_entity.
lr_entity ?= me->typed_context->node->collection_wrapper->get_current( ).
check lr_entity is BOUND.
CHECK lr_entity->is_change_allowed( ) = abap_true.
lr_entity->lock( ).
if lr_entity->is_locked( ) = abap_false.
me->view_group_context->reset( ).
else.
me->view_group_context->set_all_editable( ).
endif.
endmethod.
Some Methods of Iterators to fetch the entity using IF_BOL_BO_COL_ITERATOR
lr_item ?= lr_iterator->get_current( ). |
lr_item ?= lr_iterator->get_first( ). |
lr_item ?= lr_iterator->get_last( ). |
lv_tab_size = lr_iterator->size( ). " Get no of entities |
Some methods of Property access using IF_BOL_BO_PROPERTY_ACCESS
CALL METHOD lr_item->get_property_as_value
( EXPORTING iv_attr_name = lc_amount
IMPORTING ev_result = lv_amount ).
More to update.....
Regards,
Sumeet Gehlot
SAP CRM Practice