SAP CRM WebUI: A Short Introduction to BOL Programming

SAP CRM WebUI BOL Programming

SAP CRM is not a cutting-edge cloud solution, but rather a stable and mature on-premise CRM system. The purpose of this article is to provide a structured and comprehensive overview of Business Object Layer (BOL) programming within SAP CRM WebUI.

Inspired by an article from Furkan Sönmez, this guide outlines the fundamental classes, core concepts, and practical implementation patterns — ranging from initializing the BOL core and executing queries to working with entities and managing transactions.

Business Object Layer Programming provides various advantages such as simple and easy use due to Object Oriented structure and faster applications due to built-in buffer.

Let us start with the most commonly used classes of BOL programming

  • CL_CRM_BOL_QUERY_SERVICE: Query class to select Business Objects
  • IF_BOL_TRANSACTION_CONTEXT: For access to transaction context
  • CL_CRM_BOL_ENTITY: Representing entities as BO segments
  • IF_BOL_BO_COL: Providing access to collections holding entities

Starting an instance of BOL

In order to start an instance of the business object layer, we need to call the factory method of the core class

DATA: lr_bol_core TYPE REF TO cl_crm_bol_core.

lr_bol_core = cl_crm_bol_core=>get_instance( ).
lr_bol_core->start_up( ‘COMPONENT_SET’ ).

We need to pass the name of the Generic Interaction Layer (GenIL) component set that we want to start to the START_UP method of the core class.

Each component set includes a set of GenIL components. Each GenIL component provides a specific business object and with dependant objects and related queries.

To find out which business objects, attributes and relations are provided by a component, you can you can use the Model Browser under the transaction GENIL_MODEL_BROWSER or CRM_ISU_BOL_BROWSER (the advanced version of the model browser ;-).

Advanced Query

To perform a query, we start by creating our dynamic query object

DATA: lr_query TYPE REF TO cl_crm_bol_dquery_service.

lr_query = cl_crm_bol_dquery_service=>get_instance( 'BTQKNOART' ).

Set query parameter for maximum number of hits

lr_query->set_property( iv_attr_name = 'MAX_HITS'
                        iv_value     = '10' ).

Add selection criteria(s)

lr_query->add_selection_param( iv_attr_name = 'POSTING_DATE'
                               iv_sign 	    = 'I'
                               iv_option    = 'EQ'
                               iv_low 	    = sy-datum
                               iv_high 	    = '' ).

Execute the query and get result

DATA: lr_result TYPE REF TO if_bol_entity_col.

lr_result = lr_query->get_query_result( ).

Access to BOL Entities of a Collection

In order to access entities in a collection, we are going to use iterator

DATA: lr_iterator   TYPE REF TO if_bol_entity_col_iterator, 
      lr_entity 	  TYPE REF TO cl_crm_bol_entity,
      ls_attributes TYPE crms_query_r_knoart_btil.

lr_iterator = lr_result->get_iterator( ).

lr_entity = lr_iterator->get_first( ).

WHILE lr_entity IS BOUND.
  lr_entity->get_properties( 
    IMPORTING es_attributes = ls_attributes 
  ).

  lr_entity = lr_iterator->get_next( ).
ENDWHILE.

Here the structure ls_attributes has the dictionary structure of the result object of our query, which can be found in the model browser.

Access to Properties of Entity

If you don’t want to access to all attributes of the entity, there are three ways to access to an attribute of an entity.

  • GET_PROPERTY Method, returns a pointer to the attribute value
  • GET_PROPERTY_AS_VALUE method, provides the value of the attribute
  • GET_PROPERTY_AS_STRING method, provides the value converted to string
DATA: lv_proc_type	TYPE REF TO crmt_process_type,
      lv_status 	  TYPE crm_j_status,
      lv_object_id 	TYPE string.

lv_proc_type ?= lr_entity->get_property( ‘PROCESS_TYPE’ ).

lr_entity->get_property_as_value( 
  EXPORTING iv_attr_name = ‘STATUS’
  IMPORTING ev_result    = lv_status 
).

lv_object_id = lr_entity->get_property_as_string( ‘OBJECT_ID’ ).

In order to access to a related entity, we can get_related_entity method

DATA: lr_order TYPE REF TO cl_crm_bol_entity.

lr_order = lr_entity->get_related_entity( ‘BTADVSKNOART’ ).

In order to get a list of related entities, we use the metod get_related_entities

DATA: lr_texts_all TYPE REF TO if_bol_entity_col.

lr_texts_all = lr_text_set->get_related_entities( 
  iv_relation_name = 'BTTextHAll' 
).

Create BOL Entities

We can create root and related entities using the methods below

DATA: lr_factory TYPE REF TO cl_crm_bol_entity_factory,
      lr_order   TYPE REF TO cl_crm_bol_entity,
      lr_header  TYPE REF TO cl_crm_bol_entity,
      lt_params  TYPE crmt_name_value_pair_tab,
      ls_params  TYPE crmt_name_value_pair.

ls_params-name = ‘PROCESS_TYPE’.
ls_params-value = ‘ZA01’.
APPEND ls_params TO lt_params.

* Get factory for business object
lr_factory = lr_bol_core->get_entity_factory( ‘BTOrder’ ).

* Create root entity
lr_order = lr_factory->create( lt_params ).

* Create child object
lr_header = lr_order ->create_related_entity( ‘BTOrderHeader’ ).

Lock BOL Entity

lock method is used to lock entities

lv_entity->lock( ).

Modify Properties of BOL Entity

In order to modify entity attributes, you can use set_property method

IF lr_adminh->lock( ) EQ abap_true.
  lr_adminh ->set_property( iv_attr_name = ‘ARCHIVING_FLAG’
                            iv_value     = ‘X’ ).
ENDIF.

Save and Commit of BOL Entity

Always use methods CHECK_SAVE_NEEDED and CHECK_SAVE_POSSIBLE before saving. Once saving has failed there is no way back. Once the transaction has been saved it has to be finished with methods COMMIT or ROLLBACK

* send all changes to BO layer
lr_bol_core->modify( ).

* 3. get transaction
DATA: lr_transaction TYPE REF TO if_bol_transaction_context.

lr_transaction = lr_bol_core->get_transaction( ).

* save and commit changes
IF lr_transaction->check_save_possible( ) EQ abap_true.
  IF lr_transaction->save( ) EQ abap_true.
    lr_transaction->commit( ).
  ELSE.
    Lr_transaction->rollback( ).
  ENDIF.
ENDIF.

BOL: Delete Entity

And lastly deleting entities, which is also quite simple

lr_partner_single->delete( ).

Summary: Basics in SAP CRM WebUI Development

In conclusion, Business Object Layer (BOL) programming in SAP CRM WebUI provides a powerful and consistent framework for interacting with business objects in an object-oriented manner. By leveraging core classes, query services, and transaction handling mechanisms, developers can efficiently read, create, modify, and persist data within the CRM application.

Although SAP CRM is a mature on-premise solution, its BOL/GenIL architecture remains highly relevant for building robust and maintainable enhancements. A solid understanding of these concepts enables developers to navigate existing implementations more effectively and to deliver clean, scalable solutions within the SAP CRM environment.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top