CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
sumeet_gehlot
Contributor
This document is aimed at understanding bol programming CRUD operation concepts in CRM WebUI.

Sample Code for BOL Creation : Create a Activity Transaction
DATA : lr_core TYPE REF TO cl_crm_bol_core.
TRY.
lr_core = cl_crm_bol_core=>get_instance( ).
lr_core->load_component_set( 'BT' ) .
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 : ls_params , lt_params[].

*-->Build Create parameters Root Object 'BTOrder'
*--> Process Type
ls_params-name = 'PROCESS_TYPE'.
ls_params-value = 'ZACTIVITY'.
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_order TYPE REF TO cl_crm_bol_entity.

*-->Note Either use root_create or get_entity_factory to create.
*--> Obtain Factory of Root Object in Entity.
TRY.
lr_factory = lr_core->get_entity_factory( iv_entity_name = 'BTOrder' ).
lr_order = lr_factory->create( lt_params ).
CATCH cx_crm_unsupported_object.
ENDTRY.

DATA : lr_adminh TYPE REF TO cl_crm_bol_entity.
*--> Get Dependent Objects.
lr_adminh = lr_order->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
IF lr_adminh IS NOT BOUND.
TRY.
*-->Create Dependent Objects.
lr_adminh = lr_order->create_related_entity( iv_relation_name = 'BTOrderHeader').
CATCH cx_crm_genil_duplicate_rel cx_crm_genil_model_error.
ENDTRY.
ENDIF.

DATA : ls_admin TYPE crmst_adminh_btil.
lr_adminh->get_properties( IMPORTING es_attributes = ls_admin ).
ls_admin-description = 'Activity Creation'.
ls_admin-posting_date = '20140110'.
lr_adminh->set_properties( EXPORTING is_attributes = ls_admin ).

DATA: lr_activity TYPE REF TO cl_crm_bol_entity.
*--> Get Dependent Objects.
lr_activity = lr_adminh->get_related_entity( iv_relation_name = 'BTHeaderActivityExt' ).
IF lr_activity IS NOT BOUND.
TRY.
*-->Create Dependent Objects.
lr_activity = lr_adminh->create_related_entity( iv_relation_name = 'BTHeaderActivityExt' ).
CATCH cx_crm_genil_duplicate_rel cx_crm_genil_model_error.
ENDTRY.
ENDIF.

* -->set the attribute using set_property method.
DATA : ls_activity TYPE crmst_activityh_btil.

lr_activity->get_properties( IMPORTING es_attributes = ls_activity ).
ls_activity-category = '101'.
ls_activity-priority = '01'.
ls_activity-objective = '003' .
lr_activity->set_properties( EXPORTING is_attributes = ls_activity ).

* -->Submit Root Objects and Child Objects Which are created.
* -->Always call modify on bol core.
lr_core->modify( ).

*Save and Commit Changes Using Global Transaction Context
DATA: lr_transaction TYPE REF TO if_bol_transaction_context .
DATA: lv_success TYPE crmt_boolean.

lr_transaction = lr_core->get_transaction( ).
IF lr_transaction->check_save_needed( ) EQ abap_true
AND lr_transaction->check_save_possible( ) EQ abap_true.
lv_success = lr_transaction->save( ).

IF lv_success IS NOT INITIAL.
lr_transaction->commit( ).
ELSE.
lr_transaction->rollback( ).
ENDIF.
ENDIF.

 

 

Sample Code for BOL Search : Search a Activity Transaction

Use CL_CRM_BOL_QUERY_SERVICE or CL_CRM_BOL_DQUERY_SERVICE class objects to search data.
DATA : lr_core TYPE REF TO cl_crm_bol_core.
TRY.
lr_core = cl_crm_bol_core=>get_instance( ).
lr_core->load_component_set( 'BT' ) .
CATCH cx_crm_genil_general_error.
ENDTRY.

DATA: lr_qs TYPE REF TO cl_crm_bol_dquery_service,
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,
ls_param TYPE crmt_name_value_pair,
lt_param TYPE crmt_name_value_pair_tab.

*Get and prepare dynamic query service.
lr_qs ?= cl_crm_bol_dquery_service=>get_instance( 'BTQAct' ).

* Set Query Parameters.
ls_param-name = 'MAX_HITS'.
ls_param-value = '5'.
APPEND ls_param TO lt_param.
lr_qs->set_query_parameters( lt_param ).

*Add selected parameters or criteria .
lr_qs->add_selection_param( iv_attr_name = 'EMPLOYEE_RESP' iv_sign = 'I'
iv_low = '*' iv_option = 'EQ' iv_high = ' ').

*Execute Query and retrieve result
lr_result = lr_qs->get_query_result( ).

CHECK lr_result IS BOUND.

*Use Iterator to access entities in query result
lr_iter ?= lr_result->get_iterator( ).

* Get the first record from Collection.
lr_entity ?= lr_iter->get_first( ).

DATA : lv_guid TYPE crmt_object_guid.
WHILE lr_entity IS BOUND.

*Access Attributes of Business object.
lv_object_id = lr_entity->get_property_as_string( 'OBJECT_ID' ).

"Perform Operations or Write
Write:/ lv_object_id.

lr_entity ?= lr_iter->get_next( ).
ENDWHILE.

Sample Code for BOL CHANGE OR UPDATE ENTITY

Scenario : To Modify or update a Business Object entities.

To update BOL entity , First we need to search using Search Object and get the entity object (Root object ) once we can the instance of Root object we can update the entity.

For Search : Use Above code as reference.
Data : lr_core type ref to cl_crm_bol_core.

lr_core = cl_crm_bol_core=>get_instance( ).
TRY.
lr_core->start_up( EXPORTING iv_appl_name = 'ONEORDER'
iv_display_mode_support = abap_true ).
CATCH cx_crm_genil_general_error. "#EC NO_HANDLER
ENDTRY.

DATA: lr_qs TYPE REF TO cl_crm_bol_query_service,
lr_iterator TYPE REF TO if_bol_entity_col_iterator,
lr_search_result_coll TYPE REF TO if_bol_entity_col,
lr_btorder TYPE REF TO cl_crm_bol_entity,
lr_btorder_h TYPE REF TO cl_crm_bol_entity.

* Start BT Appl
lr_qs = cl_crm_bol_query_service=>get_instance( 'BTQuery1O' ). "#EC NOTEXT

* set search parameters
CALL METHOD lr_qs->set_property
EXPORTING
iv_attr_name = 'OBJECT_ID'
iv_value = lv_object_id.

* set search parameters, Bus Object type 'LEAD'
CALL METHOD lr_qs->set_property
EXPORTING
iv_attr_name = ' OBJECT_TYPE'
iv_value = 'BUS2000108'.

lr_search_result_coll = lr_qs->get_query_result( ).

IF lr_search_result_coll IS BOUND.
lr_iterator = lr_search_result_coll->get_iterator( ).

IF lr_iterator IS BOUND.
lr_btorder = lr_iterator->get_first( ).

*Get the Entity of Activity Object
CALL METHOD lr_btorder->get_related_entity
EXPORTING
iv_relation_name = 'BTOrderHeader'
RECEIVING
rv_result = lr_order_h.
CATCH cx_crm_genil_model_error .
ENDTRY.

lr_order_h->switch_to_change_mode( ).

*Locks are always set on root object.
IF lr_order_h->lock( ) = 'X'.
IF lr_order_h->is_changeable( ) = 'X'.

*Set property also locks the object entity if lock has not been set.
lr_order_h->if_bol_bo_property_access~set_property( iv_attr_name = 'DESCRIPTION'
iv_value = 'Melbourne' ).
*Modify BOL layer
lr_core->modify( ).

lr_transaction = lr_core->get_transaction( ).
lv_success = lr_transaction->save( ).
IF lv_success eq abap_true. lr_transaction->commit( ).
ENDIF.
ENDIF.ENDIF.ENDIF.ENDIF.


Sample Code for BOL Delete   

* Use Above code for Entity Object

lr_entity ?= lr_result->get_first( ).
*
*Lock and modify the property
IF lr_entity->lock( ) = if_genil_boolean=>true.
lr_entity->delete( ).
*Modify the Core Object
lr_core->modify( ).
ENDIF.
* Then Again Use save and commit using transaction contexxt.

UI Development Codes
Saving Object into Database EH_ONSAVE

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

Edit Objects EH_ONEDIT

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.

Config Use of DO_CONFIG_DETERMINATION method to change the screen layout.








*For Each Object type and Subobject type combination, there is 1 view configuration
lv_object_type = 'ZOBJTYP'.
lv_subobject_type = 'ZSUBTYP'.

* Set the config keys to fetch relevant configuration.
me->set_config_keys( iv_object_type = lv_object_type
iv_object_sub_type = lv_subobject_type
iv_propagate_2_children = abap_true ).



Set or Populate valuenodes with value using CL_BSP_WD_VALUE_NODE











TYPES: BEGIN OF str,
status TYPE char20,
END OF str.

* Structure of status context node.
DATA lr_struct_ref TYPE REF TO str.

* Structure of your context node
DATA ls_struct TYPE str.

DATA lr_value_node TYPE REF TO cl_bsp_wd_value_node.

CREATE DATA lr_struct_ref.
CREATE OBJECT lr_value_node
EXPORTING
iv_data_ref = lr_struct_ref.
ls_struct-status = 'Your Value'.
lr_value_node->if_bol_bo_property_access~set_properties( ls_struct ).

*Add Value Node to a collection
typed_context->testnode->collection_wrapper->add( lr_value_node ).

Get a model node from Mixed node using CL_BSP_WD_MIXED_NODE
DATA: lr_mixednode TYPE REF TO cl_bsp_wd_mixed_node,
lr_access TYPE REF TO if_bol_bo_property_access.
*
*Get the current entity from your mixed node
lr_mixednode ?= me->typed_context->contexnodename->collection_wrapper->get_current( ).
lr_access ?= lr_mixednode->if_bsp_wd_ext_property_access~get_model_node( ).



Display Custom Internal Table on UI  on a Table View Context Node.

DATA : lr_valuenode TYPE REF TO cl_bsp_wd_value_node "Collection to fill node
DATA : lr_tabline TYPE REF TO ty_str. "Type Structure
DATA : lr_ent_col TYPE REF TO if_bol_bo_col.
DATA : lr_coll_wrapp TYPE REF TO cl_bsp_wd_collection_wrapper. "Collection Wrapper

CREATE DATA lr_tabline.

CREATE OBJECT lr_ent_col TYPE cl_crm_bol_bo_col.
LOOP AT lt_table INTO ls_str.
* Create value object with current line for collection
CREATE OBJECT lr_valuenode
EXPORTING
iv_data_ref = lr_tabline.

* Set current line data
lr_valuenode->set_properties( ls_str ).
* Add current line to collection
lr_ent_col->add(
EXPORTING
iv_entity = lr_valuenode ). " Access Interface for BO Attributes

ENDLOOP.
typed_context->context_node->collection_wrapper->clear_collection( ).
CREATE OBJECT lr_coll_wrapp.
lr_coll_wrapp->set_collection( lr_ent_col ).
typed_context->salesorg->set_collection_wrapper( lr_coll_wrapp ).
typed_context->context_node->build_table( ).

Access or Read a Context Node of another Component using Controllers if they are linked with each other.
data : lr_object type ref to  cl_bsp_wd_view_controller.
IF lr_object IS NOT BOUND.
lr_object = me->get_subcontroller_by_viewname( iv_viewname = 'ComponentName/MainWindow' ).
IF lr_object IS BOUND.
lr_object = lr_object->get_subcontroller_by_viewname( iv_viewname = 'ComponentName/ViewSet' ).
IF lr_object IS BOUND.
lr_object = lr_object>get_subcontroller_by_viewname( iv_viewname = 'ComponentName/ViewName' ).
ENDIF.
ENDIF.
ENDIF.

Get parent component at run time from embedded component view implentation class

In window impl class - create a method  GET_OUTER_REP_VIEW parameter as RR_OUTER_REP_VIEW Returning Type Ref To CL_BSP_WD_REP_VIEW.
 method GET_OUTER_REP_VIEW.
rr_outer_rep_view = me->outer_rep_view.
endmethod.

*Call in an view imple class or context node to fetch parent
Data : lr_parentview TYPE REF TO cl_bsp_wd_rep_view.
TRY.
lr_contr ?= me->view_manager->get_window_controller( ).
lr_parentview = lr_contr->get_outer_rep_view( )->get_parent( ).
lv_parent_name = lr_parentview->get_name( ).
CATCH cx_sy_move_cast_error cx_sy_ref_is_initial.
RETURN.
ENDTRY.

Accessing component controller in CN00 methods. Go to _CN class -Create attribute -  ZOWNER Instance Attribute Public Type Ref To view_imple_class. - open IF_BSP_MODEL~INIT put as zowner ?= owner.
lr_view    ?= zowner.
lr_window ?= lr_view->get_window( ).
lr_comp ?= lr_window->m_parent.


 
27 Comments
Top kudoed authors