Skip to Content
Technical Articles

BOL Programming(WebUI)

The primary purpose of this blog is to present a basic idea of bol programming.

Refer : How To Guide Business Object Layer Programming

Sample Code for BOL Creation :

Scenario : Create a Lead , Campaign , Business Partner or One Order transaction using Reports or use in methods of BAdis to get the instance of object.
Below is the code Creation of Activity – One Order Object in CRM system.

DATA : lr_core TYPE REF TO cl_crm_bol_core.
     lr_core = cl_crm_bol_core=>get_instance( ).
     lr_core->load_component_set( 'BT' )      .
   CATCH cx_crm_genil_general_error.

*-->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.
     lr_factory = lr_core->get_entity_factory( iv_entity_name = 'BTOrder' ).
     lr_order = lr_factory->create( lt_params ).
   CATCH cx_crm_unsupported_object.

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.
*-->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.

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.
*-->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.

* -->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( ).
     lr_transaction->rollback( ).

Sample Code for BOL SEARCH

Scenario : Retrieving the data of Business Partner , One Order transaction , Lead ,
Activity or any other business objects this can be done via


DATA : lr_core TYPE REF TO cl_crm_bol_core.
     lr_core = cl_crm_bol_core=>get_instance( ).
     lr_core->load_component_set( 'BT' )      .
   CATCH cx_crm_genil_general_error.
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( '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.
DATA : lv_object_id TYPE crmt_object_id_db.
DATA : lr_parent TYPE REF TO cl_crm_bol_entity.
WHILE lr_entity IS BOUND.
*Access Attributes of Business object.
   lv_guid = lr_entity->get_property_as_string( 'GUID' ).
   WRITE lv_guid.
   lr_entity ?= lr_iter->get_next( ).


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( ).
         lr_core->start_up( EXPORTING iv_appl_name = 'ONEORDER'
                                      iv_display_mode_support = abap_true ).
       CATCH cx_crm_genil_general_error.                 "#EC NO_HANDLER
         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
       iv_attr_name = 'OBJECT_ID'
       iv_value     =  lv_object_id.
* set search parameters, Bus Object type 'LEAD'
   CALL METHOD lr_qs->set_property
       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
     iv_relation_name = 'BTOrderHeader'
     rv_result        = lr_order_h.
CATCH cx_crm_genil_model_error .

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

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( ).
* 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( ).
   IF lr_tx IS BOUND.
     IF lr_tx->check_save_possible( ) = abap_true.
       CHECK lr_tx->save( ) = abap_true.
       lr_tc->commit( ).
   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( ).
     me->view_group_context->set_all_editable( ).

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

              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
     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_org.                                 " 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 colleciton
       CREATE OBJECT lr_valuenode
           iv_data_ref = lr_tabline.

*     Set current line data
       lr_valuenode->set_properties( ls_str ).
*     Add current line to collection
           iv_entity    =  lr_valuenode    " Access Interface for BO Attributes
     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' ).

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.

       rr_outer_rep_view = me->outer_rep_view.

*Call in an view imple class or context node to fetch parent 
Data : lr_parentview  TYPE REF TO cl_bsp_wd_rep_view.
        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.

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.

You must be Logged on to comment or reply to a post.
    • Hi Christian ,

      I was not aware of this doc...

      I am trying to put as many as sample codes in a single blog and more code samples yet to upload related to navigations pop ups dropdows on click actions that if required it can be used by all.

      if there is still any issue related to posing this doc , let me know so that i will delete



      • Hi Sumeet,

        i think the examples related to pop ups and drop downs could be interesting.

        With respect to the BOL examples I think you should link to the BOL How To Guide as it is IMHO a very good and complete document.



  • Hello, Sumeet.

    Thank you for bringing my attention to this post.

    In case of any doubts how to classify this or that content on SCN I personally always refer to The Difference between a Discussion, Blog Post, Document and Wiki document.

    To my mind this particular content had to be put as a Wiki. Or at least a document. Because a blog is intended to express your own opinion or experience.

    I think it's too late to convert to either a wiki or a document now. Quite many people have already bookmarked, rated or liked it. Could you please put at least a reference to the BOL programming guide mentioned by Christian Drumm in your blog post itself? And please use a mentioned post to classify your content in the future. Thank you.

  • HI christian

    Thank's for the post on BOL , it was very helpful.could you please refer me any video links for BOLprogramming.



  • Hi Sumeet,

    Nice post. I have a dew question about updating a bol layer. I already get a bol header from search method. But it seems doesn't work when I updating the bol layer, after I debug it, the entity is not changeable. I already used the display mode support and switch to change mode. I copied your code in my work, but it still doesn't change to change mode. Does you have some advise about this case?

    Thanks for your share in this blog. It's very helpful.

    • Hi Alexander,

      If your header entity is locked, then it wont switch to change mode or in a changeable mode.

      Check the entity might have been locked (already in edit mode) from the front end or gui transaction.



      • Hi Sumeet,

        Thanks for your reply. So, that's mean I can change it directly, since it already in edit mode? or I set it to display mode and then start to lock it again to change the properties values?


        • Hi,

          once entity is locked from front end u will be not able to change by code also, try setting it to display mode and then start to lock it again to change the properties values...



    • Hi Rohan,

      you can get the messages from the message container. I'm currently unsure if the BP messages end up in the global message container (via bol_core->get_global_message_cont( )) or in the message container of the entity (

      bol_core->get_message_cont_manager( )->get_message_cont()). In one of those message containers you should be able to read the error messages.

      The following document describes the different message handling approaches in more detail:…


      • Dear Christian,

        I have already tried this but I am not able to get messages from lr_core->get_global_message_cont->if_genil_message_container~get_messages

        or lr_core->get_message_cont_manager->get_message_cont->get_messages

        We have to modify the core then get messages from lr_entity->get_message_container to get error messages.

        Thanks & Regards,


        • Dear Christian,

          Due to this my number range skips if there exists any error and if I roll backed the transaction.

          Is there exist any other solution.

          Thanks Regards,


          • Hi Rohan,

            what do you mean with "my number range skips?".

            Whenever a number is requested from a number range object the number range is increased. For example, if you try to create a BP a new BP number is requested from the number range object. If an error occurs the transaction is rolled back an the BP is not created. If you try to create a new BP again the next number from the number range is requested. The number used in the failed transaction is "lost" and won't be reused.

            If this is the problem you are talking about, there is no solution for it. It is the core functionality of the number range objects that can't be changed.


          • Dear Christian,

            You are right but there should be some method to check data before requesting number from number range object.

            I have used BOL it is quiet simple and requires less coding but I am not able to figure out how errors are calculated. Number is requested when I write below statement:

            lr_entity = lr_factory->create( lt_params )

            I have got errors only after below code:

            lr_core->modify( )

            lr_msg_cont = lr_entity->get_message_container( ) "Root Entity

            Using this method if central data contains error number always goes for nothing.

            I tried using BAPI also it requires some extra efforts in coding but atleast checks for errors and if central data contains error it does not generate a number.

            Thanks & Regards,


  • Hi Sumeet,

    Having experience with BOL programming already, but 2 years ago, I had to jump into it again, with no time for nice and easy recap (as usually). Your blog, however, contained just about everything one needs for such a lightning fast (re)start.

    Thanks for this!


  • Hi Sumeet,

    Firstly thanks for sharing a nice document.. it is very helpful to create business transaction using BOL Proramming.

    I have followed this document. When i am modifying our transaction i am getting interface changed at runtime.

    While run this line lr_core->modify( ) then i am getting dump.

    Can you please help me out to this issue.


    Puneet Mittal