Skip to Content

So as you experts know that Transportation Charges is a Dependent BOPF Node in SAP Transportation Management System.

I would not go too deep in explaining how do Dependent Nodes work and how they are placed in BOPF framework as there are already lot of posts around this.

Today we will focus only on the Charges Dependent Object and how do we use modification operations on Charges Dependent Node.

So lets start on accessing the Charges DO(Dependent Object) for a Freight Booking Object.

 

 

So Everyone here understands that TRANSPORTCHARGES in TOR Object is a dependent entity and can be accessed only by DO Keys.

SAP Standard has provided some methods to get these keys for you to make things easier for us.

 

So Assuming we need to get the Charges for a Freight Booking and then modify them using some external Program below would be the steps.(Code Extracts are from Embedded TM 1709, Please ignore naming convention in case they don’t appeal you  )

Get Service Manager for TOR using Service Manager   /bobf/cl_tra_serv_mgr_factory=>get_service_manager.

Get TRANSPORTCHARGES node data using Retrieve by Association on TOR Object and get the keys for TRANSPORTCHARGES .

Now the Fun Starts.

Now we need to fetch the runtime DO Keys for various nodes/subnodes/dependent nodes involved.

First we fetch the runtime Dependent Node key and Association Key for relation between TOR and TRANSPORTCHARGES. This utility method provided by SAP Standard to ease our work.

using /scmtms/cl_tcc_calc_utility=>get_bo_do_assoc(
EXPORTING
iv_bo_key        = /scmtms/if_tor_c=>sc_bo_key  ” Business Object
iv_node_key      = /scmtms/if_tor_c=>sc_node–root   ” Node
iv_do_key        = /scmtms/if_tcc_trnsp_chrg_c=>sc_bo_key
*          iv_calc_ctx      = iv_calc_ctx    ” Calculation Context
IMPORTING
ev_root_node_key = DATA(lv_do_key)    ” NodeID
ev_assoc_key     = DATA(lv_bo_do_assoc_key)    ” Node
).

We get lv_do_key(Runtime Node key for TRANSPORTATIONCHARGES for TOR Object) and lv_bo_do_assoc_key(Runtime Association key between TOR and TRANSPORTCHARGES)

Now comes another method to get the runtime node keys and association keys for dependent nodes.SAP provides another method   /scmtms/cl_common_helper=>get_do_entity_key.

This method has parameters like below.

DATA(lv_root_node_key) = /scmtms/cl_common_helper=>get_do_entity_key(
iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = lv_do_key
iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_nod
iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_node–root
).

iv_host_key is main Business Object BO Key to which the Dependent node is attached.

iv_host_do_node_key is the runtime node key for TRANSPORTCHARGE we fetched in step 5a.

iv_do_entity_cat specifies whether we want to fetch association or node key.

  •                      /bobf/if_conf_c=>sc_content_nod for Node Key
  •                     /bobf/if_conf_c=>sc_content_assoc for Association Key

iv_do_entity_key is node which you want to fetch. For eg. in this case its /SCMTMS/TCC_TRNSP_CHRG.

Now we fetch Node Keys and Association Keys for Charge Items and Charge Elements.

DATA(lv_root_node_key) = /scmtms/cl_common_helper=>get_do_entity_key(
iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = lv_do_key
iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_nod
iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_node–root
).    ” This is runtime node key for Charges Root

DATA(lv_it_chrg_it_node_key) = /scmtms/cl_common_helper=>get_do_entity_key(
iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = lv_do_key
iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_nod
iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_node–chargeitem
). ” This is runtime node key for Charges Items

DATA(lv_it_chrg_el_node_key) = /scmtms/cl_common_helper=>get_do_entity_key(
iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = lv_do_key
iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_nod
iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_node–itemchargeelement
).  ” This is runtime node key for Charges Elements

DATA(lv_chrg_chargit_assoc_key) = /scmtms/cl_common_helper=>get_do_entity_key(
iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = lv_do_key
iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_assoc
iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_association–root–chargeitem
) . ” This is runtime association key for Charges root to Charge Items
DATA(lv_chrgit_itchrgel_assoc_key) = /scmtms/cl_common_helper=>get_do_entity_key(
iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
iv_host_do_node_key = lv_do_key
iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_assoc
iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_association–chargeitem–           itemchargeelement
). “ This is runtime association key for Charges Item to Elements

 

Now Time to fetch existing Charge Items and Charge Elements using these runtime keys.

  1. This is fetching Charge Item Keys: lr_srvmgr->retrieve_by_association(
    EXPORTING
    iv_node_key             = lv_do_key“/scmtms/if_tor_c=>sc_node-transportcharges    ” Node
    it_key                  = lt_tcc_keys    ” Key Table
    iv_association          = ev_chrg_chargit_assoc_key“lv_txt_assoc    ” Association
    IMPORTING
    et_target_key           =  DATA(lt_chitemkeys)    ” Key Table for Charge Items
    ).
  2. This is fetching CHarge Elements :  lr_srvmgr->retrieve_by_association(
    EXPORTING
    iv_node_key             = ev_it_chrg_it_node_key“lv_do_key   ” Node
    it_key                  = lt_chitemkeys    ” Key Table
    iv_association          = ev_chrgit_itchrgel_assoc_key    ” Association
    iv_fill_data            = abap_true    ” Data element for domain BOOLE: TRUE (=’X’) and FALSE (=’ ‘)
    IMPORTING
    et_data                 = lt_chrel   ” Table for Charge Elements for Charge Items pushed in lt_chitemkeys
    et_target_key           =  DATA(lt_chelm)    ” Key Table for Charge Elements
    ).

Till here it was fetching , now its time to modify charge elements

  1. Assuming we want to add a new charge Element ,Prepare the Data table lt_chrel_new for Charge elements.This would be of the same Table Type as lt_chrel.Update your data in a similar table type of lt_chrel . Create data reference for lt_chrel_new.
  2. Create lt_modification.
  3. Below would be the LT_MODIFICATION Table.
  4. ls_chrel-key = /bobf/cl_frw_factory=>get_new_key( ) .. Make sure this is the same key in data table STEP 1.
  5. ls_mod–key          = ls_chrel–key.   ”  This is Charge Element Key
    ls_mod–source_key   = ls_chrel–parent_key.  ” This would be the source key for Charge Elements.In this case it would be Charge Items Key.
    ls_mod–source_node  = lv_it_chrg_it_node_key. ” This is the runtime node key for Charge Items 
    ls_mod–root_key     = ls_chrel–root_key.“This is the Root Key of the /SCMTMS/TCC_TRNSP/CHRG root.
    ls_mod–node         = ev_it_chrg_el_node_key.  “This is the runtime node key for Charge Elements 
    ls_mod–association  = ev_chrgit_itchrgel_assoc_key.This is the runtime association key for charge items to Charge Elements 
    ls_mod–change_mode  = /bobf/if_frw_c=>sc_modify_create. ” Operation Create, update, Delete
    ls_mod–data         = lr_chrel_new.

APPEND ls_mod TO lt_mod.

  1. Now from here call the Service manager Modify method and Transaction Manager Save Method to update the Charge Elements.

 

IF lr_srvmgr IS NOT BOUND.
    CALL METHOD /bobf/cl_tra_serv_mgr_factory=>get_service_manager
      EXPORTING
        iv_bo_key          = /scmtms/if_tor_c=>sc_bo_key
      RECEIVING
        eo_service_manager = lr_srvmgr.
  ENDIF.


  MOVE '00163E77B0961EE8BA96B910A4F81F35' TO ls_fo_key-key.   " Sample Key for Freight Booking

  APPEND ls_fo_key TO lt_fo_key.

  lr_srvmgr->retrieve_by_association(
     EXPORTING
       iv_node_key             =  /scmtms/if_tor_c=>sc_node-root   " Node
       it_key                  =   lt_fo_key  " Key Table
       iv_association          =  /scmtms/if_tor_c=>sc_association-root-transportcharges   " Association
       iv_fill_data            = abap_true    " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
     IMPORTING
       et_data                 = lt_tcc
       et_target_key           =  DATA(lt_tcc_keys)   " Key Table
   ).

/scmtms/cl_tcc_calc_utility=>get_bo_do_assoc(
        EXPORTING
          iv_bo_key        = /scmtms/if_tor_c=>sc_bo_key  " Business Object
          iv_node_key      = /scmtms/if_tor_c=>sc_node-root   " Node
          iv_do_key        = /scmtms/if_tcc_trnsp_chrg_c=>sc_bo_key
*          iv_calc_ctx      = iv_calc_ctx    " Calculation Context
        IMPORTING
          ev_root_node_key = DATA(lv_do_key)    " NodeID
          ev_assoc_key     = DATA(lv_bo_do_assoc_key)    " Node
      ).

DATA(lv_root_node_key) = /scmtms/cl_common_helper=>get_do_entity_key(
          iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
          iv_host_do_node_key = lv_do_key
           iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_nod
          iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-root
             ).

DATA(lv_it_chrg_it_node_key) = /scmtms/cl_common_helper=>get_do_entity_key(
          iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
          iv_host_do_node_key = lv_do_key
          iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_nod
          iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-chargeitem
             ).

DATA(lv_it_chrg_el_node_key) = /scmtms/cl_common_helper=>get_do_entity_key(
          iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
          iv_host_do_node_key = lv_do_key
          iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_nod
          iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-itemchargeelement
             ).

DATA(lv_chrg_chargit_assoc_key) = /scmtms/cl_common_helper=>get_do_entity_key(
          iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
          iv_host_do_node_key = lv_do_key
          iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_assoc
          iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_association-root-chargeitem
             ).

DATA(lv_chrgit_itchrgel_assoc_key) = /scmtms/cl_common_helper=>get_do_entity_key(
          iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
          iv_host_do_node_key = lv_do_key
          iv_do_entity_cat    = /bobf/if_conf_c=>sc_content_assoc
          iv_do_entity_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_association-chargeitem-itemchargeelement
             ).

  DATA: lt_chitem TYPE /scmtms/t_tcc_chrgitem_k.

  lr_srvmgr->retrieve_by_association(
    EXPORTING
      iv_node_key             = lv_do_key"/scmtms/if_tor_c=>sc_node-transportcharges    " Node
      it_key                  = lt_tcc_keys    " Key Table
      iv_association          = lv_chrg_chargit_assoc_key"    " Association
    IMPORTING
      et_target_key           =  DATA(lt_chitemkeys)    " Key Table
  ).

  lr_srvmgr->retrieve_by_association(
    EXPORTING
      iv_node_key             = lv_it_chrg_it_node_key "Node
      it_key                  = lt_chitemkeys    " Key Table
      iv_association          = lv_chrgit_itchrgel_assoc_key " Association
      iv_fill_data            = abap_true    
    IMPORTING
      et_data                 = lt_chrel
      et_target_key           =  DATA(lt_chelm)    " Key Table
  ).

Prepare your Data Table for Charge Elements Here.  
clear ls_chrel.
  ls_chrel-key = /bobf/cl_frw_factory=>get_new_key( ).
  ls_chrel-tcet084 = 'FB00'.
  ls_chrel-linenr = ls_chrel-linenr + 5.
  ls_chrel-amount = 40.
  ls_chrel-manual_entry = abap_true.
  

GET REFERENCE OF ls_chrel into DATA(lr_chrel).

  DATA : lt_mod TYPE /bobf/t_frw_modification,
         ls_mod TYPE /bobf/s_frw_modification.

READ TABLE lt_tcc_keys into DATA(ls_tcc_keys) index 1.

ls_mod-key          = ls_chrel-key.
ls_mod-source_key   = ls_chrel-parent_key.
ls_mod-source_node  = lv_it_chrg_it_node_key. " Charge Item Key
ls_mod-root_key     = ls_chrel-root_key."ls_tcc_keys-key. " Key for Charge DO
ls_mod-node         = lv_it_chrg_el_node_key.	" Node Key
ls_mod-association  = lv_chrgit_itchrgel_assoc_key.
ls_mod-change_mode  = /bobf/if_frw_c=>sc_modify_create.
ls_mod-data         = lr_chrel.

  APPEND ls_mod TO lt_mod.

"Call Service Manager
   lr_srvmgr->modify(
      EXPORTING
        it_modification = lt_mod
      IMPORTING
        eo_message      = lref_message
        eo_change       = lr_change ).

  CALL METHOD /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager
    RECEIVING
      eo_transaction_manager = lref_trans.

  CALL METHOD lref_trans->save
    IMPORTING
      eo_change   = lr_change
      eo_message  = lref_message.

 

 

Hope this will be able to resolve your queries on Charge Depenedent Object. Same behavior would be for any Dependent Objects like TEXT_COLLECTIONS , ATTACHMENTS etc.

 

Cheers!!

 

 

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Rajiv Kanoria
    Post author

    Hi Folks,

     

    In the Blog and code you will find   /bobf/if_conf_c=>sc_content_assoc  which is modified from /bobf/if_conf_c=>sc_content_ass which the blog did not allow me to write due to some words not allowed in blog. Please make sure you update this to  /bobf/if_conf_c=>sc_content_ass before using.

    (0) 

Leave a Reply