Supply Chain Management Blogs by SAP
Expand your SAP SCM knowledge and stay informed about supply chain management technology and solutions with blog posts by SAP. Follow and stay connected.
cancel
Showing results for 
Search instead for 
Did you mean: 
Pawan
Product and Topic Expert
Product and Topic Expert


As we all know that Dependent objects (DO) in SAP TM are used for reusable parts of Business object (BO) which doesn’t exist on their own. They only exist in the context of a main business object. We can access or update the dependent object’s data by fetching the runtime DO keys for various nodes involved. SAP provides various utility classes to obtain these runtime keys. Refer this blog post for further details.

Now, the following question arises –

1. Can Dependent object be present inside another Dependent object instead of main Business object directly?

Yes, there are scenarios in SAP TM where one Dependent object itself is contained inside another Dependent object. One such example which I’m going to discuss further in this blog is Dependent object Text Collection (ITEMCHRGELEMTEXTCOLLECTION) which is hosted inside Dependent Object TRANSPORTCHARGES which in turn, is part of main TOR object. The node elements present in the Text Collection node are Root, Text & Text Content as shown in Figure 2 below.


                                   Figure 1. BO - /SCMTMS/TCC_TRNSP_CHRG


                                    Figure 2. BO - /BOBF/TEXT_COLLECTION

2. Next, how do we obtain the runtime DO keys for various node elements involved in such scenario with respect to main BO?

SAP provides utility class method /SCMTMS/CL_TCC_DISPUTE_UTILITY=> GET_DO_NODE_BO_VIEW which help us to retrieve the corresponding runtime node keys for Dependent Objects which are hosted inside Transport Charges DO.
/scmtms/cl_tcc_dispute_utility=>get_do_node_bo_view(
EXPORTING
iv_node_key = /bobf/if_txc_c=>sc_node-root
iv_host_do_bo_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_bo_key
iv_host_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_root_node_key = /scmtms/if_tor_c=>sc_node-transportcharges
iv_do_root_node_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-itemchrgelemtextcollection
iv_content_cat = /bobf/if_conf_c=>sc_content_nod
RECEIVING
rv_do_key = DATA(v_txc_root_node_key) ).

iv_node_key – Node element key for Dependent object which needs to be retrieved (Text Collection nodes Root, Text, or Text Content as per our example)
iv_host_do_bo_key – BO key for the host Dependent object (TRANSPORTCHARGES) which holds the another DO.
iv_host_bo_key – BO key for the main Business Object (TOR in our example)
iv_host_do_root_node_key – Root node key for host Dependent object (TRANSPORTCHARGES in our example)
iv_do_root_node_key – Root node key for the Dependent Object (ITEMCHRGELEMTEXTCOLLECTION in our example).
iv_content_cat – Category to specify whether to obtain node key or association key.

Using the above method, we can obtain runtime node keys for root, text, or text content node elements of the DO Text Collection.

Next, we can make use of helper class method /SCMTMS/CL_COMMON_HELPER=> GET_DO_ENTITY_KEY provided by SAP to retrieve the corresponding runtime association key for Dependent Object.
/scmtms/cl_common_helper=>get_do_entity_key
EXPORTING
iv_host_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-transportcharges
iv_do_entity_cat = /bobf/if_conf_c=>sc_content_assc
iv_do_entity_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_association-itemchargeelement-
itemchrgelemtextcollection
RECEIVING
rv_entity_key = DATA(v_chel_txc_assoc_key).

iv_do_entity_key – Key of the DO’s entity which needs to be retrieved.

The association path for this entity key is directly available for root node of Text Collection object wrt DO TRANSPORTCHARGES but this path needs to be determined dynamically for node elements Text & Text content of Text Collection object wrt DO TRANSPORTCHARGES.

The helper class method /SCMTMS/CL_COMMON_HELPER=>GET_DO_KEYS_4_RBA determine this dynamic association path key which is then passed to method GET_DO_ENTITY_KEY to get the runtime association key for the node elements Text & Text Content of DO Text Collection.
/scmtms/cl_common_helper=>get_do_keys_4_rba
EXPORTING
iv_host_bo_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_bo_key
iv_host_do_node_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-itemchrgelemtextcollection
iv_do_node_key = /bobf/if_txc_c=>sc_node-text
iv_do_assoc_key = /bobf/if_txc_c=>sc_association-root-text
IMPORTING
ev_assoc_key = DATA(v_txc_root_text_assoc_key_temp).

/scmtms/cl_common_helper=>get_do_entity_key
EXPORTING
iv_host_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-transportcharges
iv_do_entity_cat = /bobf/if_conf_c=>sc_content_assc
iv_do_entity_key = v_txc_root_text_assoc_key_temp
RECEIVING
rv_entity_key = DATA(v_txc_root_text_assoc_key).

 

The runtime keys(node & association) obtained above are then used to retrieve the existing text collection data of the charge element or used while preparing the modification table for inserting new text collection data to the respective charge element based on the business requirement. The detailed code to insert a text note to the charge element is provided below –
** Get Service Manager for the TOR.
DATA(o_srvmgr_tor) = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key ).

** Get Runtime node keys for ChargeItem & ItemChargeelement with respect to main BO(TOR).
/scmtms/cl_tcc_utilities=>get_do_keys(
EXPORTING
iv_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_bo_node_key = /scmtms/if_tor_c=>sc_node-root
IMPORTING
ev_root_node_key = DATA(v_root_node_key)
ev_chrgit_node_key = DATA(v_chrgit_node_key)
ev_it_chrg_el_node_key = DATA(v_chrgel_node_key)
ev_root_chrgit_assoc_key = DATA(v_root_chrgit_assoc_key)
ev_chrgit_itchrgel_assoc_key = DATA(v_chrgit_chrgel_assoc_key) ).

** Get runtime Node key for root node of DO ChargeElementTextCollection.
/scmtms/cl_tcc_dispute_utility=>get_do_node_bo_view(
EXPORTING
iv_node_key = /bobf/if_txc_c=>sc_node-root
iv_host_do_bo_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_bo_key
iv_host_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_root_node_key = /scmtms/if_tor_c=>sc_node-transportcharges
iv_do_root_node_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-itemchrgelemtextcollection
iv_content_cat = /bobf/if_conf_c=>sc_content_nod
RECEIVING
rv_do_key = DATA(v_txc_root_node_key) ).

** Get runtime Association key for DO’s root node element with respect to Item Charge element.
/scmtms/cl_common_helper=>get_do_entity_key
EXPORTING
iv_host_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-transportcharges
iv_do_entity_cat = /bobf/if_conf_c=>sc_content_assc
iv_do_entity_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_association-itemchargeelement-itemchrgelemtextcollection " DO Node Key
RECEIVING
rv_entity_key = DATA(v_chel_txc_assoc_key).

** Get runtime Node key for the text node of DO.
/scmtms/cl_tcc_dispute_utility=>get_do_node_bo_view(
EXPORTING
iv_node_key = /bobf/if_txc_c=>sc_node-text
iv_host_do_bo_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_bo_key
iv_host_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_root_node_key = /scmtms/if_tor_c=>sc_node-transportcharges
iv_do_root_node_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-itemchrgelemtextcollection
iv_content_cat = /bobf/if_conf_c=>sc_content_nod
RECEIVING
rv_do_key = DATA(v_txc_text_node_key)
).

** Get runtime association key for DO’s Text Node element with respect to the Root Node.
/scmtms/cl_common_helper=>get_do_keys_4_rba
EXPORTING
iv_host_bo_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_bo_key
iv_host_do_node_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-itemchrgelemtextcollection
iv_do_node_key = /bobf/if_txc_c=>sc_node-text
iv_do_assoc_key = /bobf/if_txc_c=>sc_association-root-text
IMPORTING
ev_assoc_key = DATA(v_txc_root_text_assoc_key_temp).

/scmtms/cl_common_helper=>get_do_entity_key
EXPORTING
iv_host_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-transportcharges
iv_do_entity_cat = /bobf/if_conf_c=>sc_content_assc
iv_do_entity_key = v_txc_root_text_assoc_key_temp
RECEIVING
rv_entity_key = DATA(v_txc_root_text_assoc_key).

** Get runtime Node key for text content node of DO.
/scmtms/cl_tcc_dispute_utility=>get_do_node_bo_view(
EXPORTING
iv_node_key = /bobf/if_txc_c=>sc_node-text_content
iv_host_do_bo_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_bo_key
iv_host_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_root_node_key = /scmtms/if_tor_c=>sc_node-transportcharges
iv_do_root_node_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-itemchrgelemtextcollection
iv_content_cat = /bobf/if_conf_c=>sc_content_nod
RECEIVING
rv_do_key = DATA(v_txc_cont_node_key) ).

** Get runtime association key for DO’s Text Content Node with respect to the Text Node.
/scmtms/cl_common_helper=>get_do_keys_4_rba
EXPORTING
iv_host_bo_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_bo_key
iv_host_do_node_key = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-itemchrgelemtextcollection
iv_do_node_key = /bobf/if_txc_c=>sc_node-text_content
iv_do_assoc_key = /bobf/if_txc_c=>sc_association-text-text_content
IMPORTING
ev_assoc_key = DATA(v_txc_text_cont_assoc_key_temp).

/scmtms/cl_common_helper=>get_do_entity_key
EXPORTING
iv_host_bo_key = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-transportcharges
iv_do_entity_cat = /bobf/if_conf_c=>sc_content_assc
iv_do_entity_key = v_txc_text_cont_assoc_key_temp
RECEIVING
rv_entity_key = DATA(v_txc_text_cont_assoc_key).

** Retrieve the Charge elements data
o_srvmgr_tor->retrieve_by_association(
EXPORTING
iv_node_key = v_chrgit_node_key
it_key = t_chitemkeys
iv_association = v_chrgit_chrgel_assoc_key
iv_fill_data = abap_true
IMPORTING
et_data = t_chelements
).

**Read the relevant charge element entry from internal table t_chelements based on your **requirement to which Text Note needs to be inserted.

** Prepare data for Text collection root node -

DATA(v_txc_key) = /bobf/cl_frw_factory=>get_new_key( ).
o_txc->key = v_txc_key.
o_txc->parent_key = s_chelements-key.
o_txc->root_key = s_chelements-root_key.
o_txc->text_schema_id = “As per the business requirement
o_txc->text_exists_ind = ‘X’.

** Prepare data for Modification table.
CLEAR s_modification.
s_modification-key = v_txc_key.
s_modification-node = v_txc_root_node_key.
s_modification-change_mode = /bobf/if_frw_c=>sc_modify_create.
s_modification-data = o_txc.
s_modification-association = v_chel_txc_assoc_key.
s_modification-source_node = v_chrgel_node_key.
s_modification-source_key = s_chelements-key.
s_modification-root_key = s_chelements-root_key.

APPEND s_modification TO t_modification.

** Prepare data for Text Node -
DATA(v_txt_key) = /bobf/cl_frw_factory=>get_new_key( ).
o_text->key = v_txt_key.
o_text->parent_key = v_txc_key.
o_text->root_key = s_chelements-root_key.
o_text->text_type = “As per the business requirement
o_text->eew_txc_text = ‘X’.
o_text->language_code = ‘E’.

** Prepare data for Modification table.
CLEAR s_modification.
s_modification-key = v_txt_key.
s_modification-source_key = v_txc_key.
s_modification-source_node = v_txc_root_node_key.
s_modification-root_key = s_chelements-root_key.
s_modification-node = v_txc_text_node_key.
s_modification-association = v_txc_root_text_assoc_key.
s_modification-change_mode = /bobf/if_frw_c=>sc_modify_create.
s_modification-data = o_text.

APPEND s_modification TO t_modification.

** Prepare data for Text Content Node -
DATA(v_txtcon_key) = /bobf/cl_frw_factory=>get_new_key( ).
o_text_content->key = v_txtcon_key.
o_text_content->parent_key = v_txt_key.
o_text_content->root_key = s_chelements-root_key.
o_text_content->text = “Pass the Text note which needs to be inserted here.

** Prepare data for Modification table.
CLEAR s_modification.
s_modification-key = v_txtcon_key.
s_modification-source_key = v_txt_key.
s_modification-source_node = v_txc_text_node_key.
s_modification-root_key = s_chelements-root_key.
s_modification-node = v_txc_cont_node_key.
s_modification-association = v_txc_text_cont_assoc_key.
s_modification-change_mode = /bobf/if_frw_c=>sc_modify_create.
s_modification-data = o_text_content.

APPEND s_modification TO t_modification.

** Call the modify method
o_srvmgr_tor->modify(
EXPORTING
it_modification = t_modification
IMPORTING
eo_message = DATA(o_message)
eo_change = DATA(o_change)
).

** Transaction manager object
DATA(o_trans_mgr) = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ).

** Call Save method of the Transaction manager to commit the changes to DB.
o_trans_mgr->save(
IMPORTING
ev_rejected = DATA(v_rejected)
eo_message = DATA(o_message)
).

 

Summary

With this, I conclude my blog post and hope that it will help you to understand the working of Dependent objects which are hosted inside another Dependent object instead of main business object in SAP TM.

Please do feel free to share your thoughts/feedback in the comments section below. Thank you!