SAP TM – Access the Transportation Charge Delegated Node in TOR BO and Update the Delegated Node.
Working with BOPF in SAP TM is tricky and many times the developers struggle to find help online.
This blog is just an effort to reduce the burden by providing an easier way to traverse the delegated node for Transportation Charge From the Freight Order Root and how the update the Delegated Node fields.
Hoping that the reader has an idea about basic terms like Business Object, Node, Association etc, I move forward with the explanation.
Access the Delegated Node
The task here is to query and find out the Transportation Charges for a particular freight order.
The Transportation Charge is a delegated node in the BO /SCMTMS/TOR as seen in pics below. Also the delegated node is associated with BO /SCMTMS/TCC_TRNSP_CHRG.
If you open the BO /SCMTMS/TCC_TRNSP_CHRG , we need to fetch the highlighted node from this.
A delegated node can’t be accessed directly by creating a service manager. ( don’t do it as it dumps).
To access the delegated node we can make use of helper method ET_DO_KEYS_4_RBA of class /SCMTMS/CL_COMMON_HELPER as given in the TM Enhancement guide. This is a tedious process and involves making many calls to the helper method to prepare the keys in runtime.
An easier way that I figured out is to use the helper methods for Delegated Nodes. I read in forums that the DO developers provide helper methods in order to traverse through them easily.
The solution to the problem here is the method /scmtms/cl_tcc_do_helper=>retrive_do_nodes .
Call the method by providing the importing parameters
ls_ctx-host_bo_key = /scmtms/if_tor_c=>sc_bo_key. " HOST BO KEY , in this case TOR as TOR is hosting "the DO (Delegated Node). ls_ctx-host_root_node_key = /scmtms/if_tor_c=>sc_node-root. "TOR ROOT Key as the DO is inside the "ROOT NODE ls_ctx-host_node_key = /scmtms/if_tor_c=>sc_node-transportcharges. "HOST Node , here host is the DO "TRANSPORTCHARGES "Also Provide the Parameter IT_ROOT_KEY with the TOR Keys, in this case, the Freight Order keys.
See the below example call where I want the Charge Item, Charge Element, and the Charge Root from the Delegated Node.
TRY. "use transportation charge helper class to get the charge details. /scmtms/cl_tcc_do_helper=>retrive_do_nodes( EXPORTING is_ctx = ls_ctx it_root_key = lt_tor_root_key " Key Table IMPORTING et_charge_item = DATA(lt_item) " Charge Item et_charge_element = DATA(lt_charge_ele) " Charge Element et_do_root = lt_do_root " Root ). CATCH /bobf/cx_frw_contrct_violation ##NO_HANDLER. " Caller violates a BOPF contract ENDTRY.
Update the Delegated Node
I have added a new field into the delegated BO root /SCMTMS/TCC_TRNSP_CHRG and I want to update the same.
In that case, I would have to build the Modification table and call the Service Manager Modify Method of my host BO, in this case, TOR BO .
Code excerpt to build the modification table to update the root node of the Delegated Node.
io_serv_manager = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key ). CREATE DATA ls_mod-data TYPE /scmtms/s_tcc_root_k. "Create reference of root structure of DO ASSIGN ls_mod-data->* TO <fs_root>. CHECK <fs_root> IS ASSIGNED. <fs_root> = is_do_root. <fs_root>-zcustfield = abap_true. "add changed field. APPEND 'ZCUSTFIELD' TO ls_mod-changed_fields. ls_mod-key = is_do_root-key. "Root Key of Delegated Node , can be fetched using the Helper "shown above ls_mod-source_node = /scmtms/if_tor_c=>sc_node-root. "Source is the TOR ROOT ls_mod-source_key = it_key[ 1 ]-key. "Key is the TOR key, in this case the Freight order "key ls_mod-root_key = it_key[ 1 ]-key. "Key is the same as TOR key, in this case the Freight order "key ls_mod-node = /scmtms/if_tor_c=>sc_node-transportcharges. "Node is the node to update , in "this case the DO Node in TOR transportcharges ls_mod-association = /scmtms/if_tor_c=>sc_association-root-transportcharges. "Association to " the DO node from the TOR root node ls_mod-change_mode = /bobf/if_frw_c=>sc_modify_update. "Indicator to Update APPEND ls_mod TO lt_mod. "io_serv_manager is the for the TOR BO node / HOST BO Node io_serv_manager->modify( EXPORTING it_modification = lt_mod " Changes IMPORTING * eo_change = " Interface of Change Object eo_message = lo_message " Interface of Message Object ). " Finally call the transaction manager to save the data lo_txn_mngr = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ). lo_txn_mngr->save( IMPORTING ev_rejected = DATA(lv_reject) " Data ).
I hope the blog/code excerpts help you achieve this functionality which is a common requirement.
https://blogs.sap.com/2017/12/15/bopf-working-on-delegated-nodes/ : Thanks for showing how the Delegated node works.