SAP Help Trigger BOBF action within ABAP custom code









ABAP code to trigger BOBF action within your custom program object




see @@create-enhancement-determination


One of the benefits of BOPF functionality is that most functionality is already built and available, you just need to learn an entirly new ABAP skill set to be able to access it:-).

I guess the theory is lots of it can be configured in the front end, the only problem comes if you want to move away from the NWBC frontend. Creating a simple standard SAP
GUI tocde to do a specific peice of functioanlity. i.e. in the SCM TMS BO update a TOR object as Arrived/unloaded stage 1.

This is when you need to start thinking a bit differently and embracing the Business object framework, instead of debugging the NWBC web dynpros trying to find
methods and function modules to do what you want to do, you actually need to return the Business object via the BOBX tcode and search for an action that does
what you want. You can also create your own as an enhancement and then trigger that.

Step 1 - Find business object Action


First execute tcode BOBX and within the business objects section find the one you are working with. For this example it will be the /SCMTMS/TOR BO
trigger bopf action step 1




Note you can also see any enhancements made for this BO. You can click on the enhancement name or the main name
trigger bopf action step 2



On the next screen expand the elements node
trigger bopf action step 3



each element has its own actions, for example see the ROOT node
trigger bopf action step 4



or the item node
trigger bopf action step 5



but we are going to trigger an actiion that sits in the STOP node, the SET_HANDLING_EXECUTION action to be precise.
trigger bopf action step 6




How you find an action that does what you want is a bit of trial and error based on the description or implementing a quick ABAP example. You can also add
a break point into the class method to see if it is call whe you perform the action in the actual application.

Step 2 - ABAP code to trigger business object Action


The first thing you need to get the action details from BOBX including name and the Importing parameter structure.
So for this action the structure is /scmtms/s_tor_a_set_handl_exec
trigger bopf action step 7




This strcuture needs to be declared and populated as part of the ABAP code to execute it. See full code below

DATA lo_svc_mngr TYPE REF TO /bobf/if_tra_service_manager.
DATA lo_txn_mngr TYPE REF TO /bobf/if_tra_transaction_mgr.
FIELD-SYMBOLS: TYPE /scmtms/s_tor_item_tr_k.
DATA: lt_mod TYPE /bobf/t_frw_modification,
ls_mod TYPE /bobf/s_frw_modification,
lo_chg TYPE REF TO /bobf/if_tra_change,
lo_message TYPE REF TO /bobf/if_frw_message,
lv_rejected TYPE abap_bool,
lt_rej_bo_key TYPE /bobf/t_frw_key2.


CALL METHOD /bobf/cl_tra_serv_mgr_factory=>get_service_manager
EXPORTING
iv_bo_key = /scmtms/if_tor_c=>sc_bo_key " Business Object
* iv_create_sync_notifications = ABAP_FALSE " Switch on/off sync notifications
* iv_create_assoc_notifications = ABAP_FALSE " Switch on/off association change notifications
* iv_create_prop_notifications = ABAP_FALSE " Switch on/off property change notifications
RECEIVING
eo_service_manager = lo_svc_mngr. " Interface for (Proxy) Service Manager


CALL METHOD /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager
RECEIVING
eo_transaction_manager = lo_txn_mngr. " Standalone Transaction Manager Instance

DATA: it_key TYPE /bobf/t_frw_key,
lv_key TYPE /bobf/s_frw_key.

DATA: wa_upd_status LIKE LINE OF it_upd_status.

data: ld_text type string.


****trigger action to set update all stages to unloaded(i.e. arrived and unloaded)
LOOP AT it_stages INTO ls_stages.
REFRESH it_key.
lv_key-key = ls_stages-source_stop_key. "stage stop key
APPEND lv_key TO it_key.

DATA: lr_action_param TYPE REF TO /scmtms/s_tor_a_set_handl_exec.
CREATE DATA lr_action_param.
lr_action_param->handling_exec_stop = '12'. "unloaded (i.e. arrived and unloaded)

"20 departed
"06 arrived
"04 not arrived
"18 loaded
"12 unloaded

lo_svc_mngr->do_action(
EXPORTING
iv_act_key = /scmtms/if_tor_c=>sc_action-stop-set_handling_execution" item_tr-update_quantities " Action executioninformation-process_exec_info "
it_key = it_key " Key Table
is_parameters = lr_action_param " Action
* IMPORTING
* eo_change = " Interface of Change Object
* eo_message = " Interface of Message Object
* et_failed_key = " Key Table
* et_failed_action_key = " Key Table
* et_data =
).


** Call the SAVE method of the transaction manager
lo_txn_mngr->save(
IMPORTING
ev_rejected = lv_rejected
eo_change = lo_chg
eo_message = lo_message
et_rejecting_bo_key = lt_rej_bo_key
).

write/ 'Execution status updated to', wa_upd_status-exec_status.

ENDLOOP.


Step 3 - Full executable ABAP code to trigger business object Action








See Coding examples