How To Create Business Transaction Using BOL Programming

Here we share a simple code to illustrate how to create a business transaction using BOL programming

Variables to be used:

 DATA: lr_core        TYPE REF TO cl_crm_bol_core,
       lr_factory     TYPE REF TO cl_crm_bol_entity_factory,
       lr_order       TYPE REF TO cl_crm_bol_entity,
       lr_transaction TYPE REF TO if_bol_transaction_context,
       ls_params      TYPE crmt_name_value_pair,
       lt_params      TYPE crmt_name_value_pair_tab.

 

To be able to use any service of BOL, we need to start the model using core class

 lr_core = cl_crm_bol_core=>get_instance( ).

 

Now that we have the instance, we can load the component set. We will use ONEORDER for this example

TRY.
    lr_core->start_up( 'ONEORDER' ).

  CATCH cx_crm_genil_general_error.
ENDTRY.

 

Next we create the transaction context

lr_transaction = lr_core->begin_transaction( ).

 

And get factory for BTOrder

lr_factory = lr_core->get_entity_factory( 'BTOrder' ).

 

Set parameters of the transaction to be created

ls_params-name  = 'PROCESS_TYPE'.
ls_params-value = 'ZA01'.

APPEND ls_params TO lt_params.

 

Create BTOrder node with the parameters we provided

 lr_order = lr_factory->create( lt_params ).

 

Next we need to send the changes we made to BOL (Business Object Layer)

lr_core->modify( ).

 

Get transaction

lr_transaction = lr_core->get_transaction( ).

 

Lastly we save and commit our work

Always make sure to use CHECK_SAVE_POSSIBLE method before saving your transaction! 

IF lr_transaction->check_save_possible( ) EQ abap_true.
    IF lr_transaction->save( ) EQ abap_true.
        lr_transaction->commit( ).
    ENDIF.
ENDIF.

 

ABOUT Furkan Sönmez

www.linkedin.com/profile/view?id=122521475

RELATED POSTS

COMMENTS

comments powered by Disqus