Quantcast
Channel: SCN : Discussion List - SAP Transportation Management (SAP TM)
Viewing all articles
Browse latest Browse all 331

Create new charge line on freight order in Z-prog - amount ignored

$
0
0

Hi all,

 

I need to create new charge lines in a freight order by means of a Z-program. I have tried to use method DO_ACTION of service manager for  /SCMTMS/IF_TOR_C=>SC_BO_KEY using  /SCMTMS/IF_TCC_TRNSP_CHRG_C=>SC_ACTION-CHARGEITEM-ADD_NEW_CHRG_EL_LINE, but failed so far. Actually the line is created but the amount is just ignored and remains blank.


I have then tried to modify the created line to kind of "add" the amount with method MODIFY but again it would not work. I debugged method /BOBF/IF_FRW_DETERMINATION~EXECUTE of class /SCMTMS/CL_TCC_CHRG_EL_D_AM and the strange thing is that method MODIFY_AMOUNT is called only for creation. I tried using both change modes but it does help. Also, these methods are private and called for determinations so I'm not sure I could manage to call them directly.


I have found an old thread (How do I create new Item charge element under c... | SCN) where people manage to do exaclty the contrary but still not working (and lacking some explanations about how to get all the keys). Here's the coding I used in case someone's done that already:



"----------------------------------"

"  Data

"----------------------------------"

data:

   lo_srv_mgr_tor type ref to /bobf/if_tra_service_manager,

   lo_tra_mgr     type ref to /bobf/if_tra_transaction_mgr.

 

data:

   lt_fo_root_key   type /bobf/t_frw_key,

   ls_fo_root_key   type /bobf/s_frw_key,

   lt_tcc_root_key  type /bobf/t_frw_key,

   lt_crg_itm_key   type /bobf/t_frw_key,

   ls_crg_itm_key   type /bobf/s_frw_key,

   lt_crg_itm_data  type /scmtms/t_tcc_chrgitem_k,

   ls_crg_itm_data  type /scmtms/s_tcc_chrgitem_k,

   lt_itm_elem_data type /scmtms/t_tcc_trchrg_element_k,

   ls_itm_elem_data type /scmtms/s_tcc_trchrg_element_k.

 

data:

   lv_chrg_it_node_key  type /bobf/obm_node_key,

   lv_chrg_it_assoc_key type /bobf/obm_assoc_key,

   lv_it_elem_node_key  type /bobf/obm_node_key,

   lv_it_elem_assoc_key type /bobf/obm_assoc_key.

 

data:

   lv_action     type /bobf/act_key,

   lt_action_key type /bobf/t_frw_key,

   ls_action_key type /bobf/s_frw_key,

   lr_params     type ref to /scmtms/s_tcc_a_add_chg_el_lin,

   lo_change     type ref to /bobf/if_tra_change,

   lo_message    type ref to /bobf/if_frw_message,

   lt_failed_key type /bobf/t_frw_key,

   lx_error      type ref to /bobf/cx_frw,

   lt_return     type bapiret2_tab,

   lv_rejected   type boole_d.

 

data:

   lr_amount  type ref to /scmtms/s_tcc_amt_with_role_k,

   lr_element type ref to /scmtms/s_tcc_trchrg_element_k,

   lt_fields  type /bobf/t_frw_name,

   lt_modify  type /bobf/t_frw_modification,

   ls_modify  type /bobf/s_frw_modification.

 

"----------------------------------"

"  Sel. screen

"----------------------------------"

parameters: p_tor_id type /scmtms/tor_id default '00000000000400003498'.

 

"----------------------------------"

"  Service Managers

"----------------------------------"

lo_srv_mgr_tor = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key ).

 

"----------------------------------"

"  Get FO key

"----------------------------------"

select single db_key

   from /scmtms/d_torrot

   into ls_fo_root_key-key

   where tor_id eq p_tor_id.

 

append ls_fo_root_key to lt_fo_root_key.

 

"----------------------------------"

"  Transportation Charges

"----------------------------------"

lo_srv_mgr_tor->retrieve_by_association(

   exporting

     iv_node_key     = /scmtms/if_tor_c=>sc_node-root

     it_key          = lt_fo_root_key

     iv_association  = /scmtms/if_tor_c=>sc_association-root-transportcharges

     iv_edit_mode    = /bobf/if_conf_c=>sc_edit_read_only

   importing

     et_target_key   = lt_tcc_root_key ).

 

"----------------------------------"

"  Charge Items

"----------------------------------"

/scmtms/cl_common_helper=>get_do_keys_4_rba(

     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_node_key      = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-chargeitem

       iv_do_assoc_key     = /scmtms/if_tcc_trnsp_chrg_c=>sc_association-root-chargeitem

     importing

       ev_node_key         = lv_chrg_it_node_key

       ev_assoc_key        = lv_chrg_it_assoc_key ).

 

lo_srv_mgr_tor->retrieve_by_association(

   exporting

     iv_node_key    = /scmtms/if_tor_c=>sc_node-transportcharges

     it_key         = lt_tcc_root_key

     iv_association = lv_chrg_it_assoc_key

     iv_fill_data   = abap_true

     iv_edit_mode   = /bobf/if_conf_c=>sc_edit_read_only

   importing

     et_data        = lt_crg_itm_data

     et_target_key  = lt_crg_itm_key ).


"----------------------------------"

"  Item Charge Elements

"----------------------------------"

/scmtms/cl_common_helper=>get_do_keys_4_rba(

     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_node_key      = /scmtms/if_tcc_trnsp_chrg_c=>sc_node-itemchargeelement

       iv_do_assoc_key     = /scmtms/if_tcc_trnsp_chrg_c=>sc_association-chargeitem-itemchargeelement

     importing

       ev_node_key         = lv_it_elem_node_key

       ev_assoc_key        = lv_it_elem_assoc_key ).

 

lo_srv_mgr_tor->retrieve_by_association(

   exporting

     iv_node_key    = lv_chrg_it_node_key

     it_key         = lt_crg_itm_key

     iv_association = lv_it_elem_assoc_key

     iv_fill_data   = abap_true

     iv_edit_mode   = /bobf/if_conf_c=>sc_edit_read_only

   importing

     et_data        = lt_itm_elem_data ).



Then either this to create:


"----------------------------------"

"  Create new line

"----------------------------------"

/scmtms/cl_common_helper=>get_do_keys_4_action(

   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_action_key    = /scmtms/if_tcc_trnsp_chrg_c=>sc_action-chargeitem-add_new_chrg_el_line

   importing

     ev_action_key       = lv_action ).

 

create data lr_params.

lr_params->tcet084     = 'Z-RD-SALE'.

lr_params->amount      = '0.03'.

lr_params->currcode016 = 'NOK'.

 

try.

     lo_srv_mgr_tor->do_action(

           exporting

             iv_act_key    = lv_action

             it_key        = lt_crg_itm_key

             is_parameters = lr_params

           importing

             eo_change     = lo_change

             eo_message    = lo_message

             et_failed_key = lt_failed_key

         ).

 

   catch /bobf/cx_frw into lx_error.

endtry.



Or


"----------------------------------"

"  Update Amount

"----------------------------------"

append 'TCET084' to lt_fields.

append 'AMOUNT' to lt_fields.

append 'CURRCODE016' to lt_fields.

 

ls_modify-node = lv_it_elem_node_key.

ls_modify-change_mode = /bobf/if_frw_c=>sc_modify_update.

ls_modify-key = ls_itm_elem_data-key.

ls_modify-changed_fields = lt_fields.

ls_modify-association = lv_it_elem_assoc_key.

ls_modify-source_node = lv_chrg_it_node_key.

ls_modify-source_key = ls_itm_elem_data-parent_key.

ls_modify-root_key = ls_itm_elem_data-root_key.

 

create data lr_element.

lr_element->key = ls_itm_elem_data-key.

lr_element->tcet084 = 'Z-RD-SALE'.

lr_element->rate_amount = '0.03'.

lr_element->currcode016 = 'NOK'.

ls_modify-data = lr_element.

 

append ls_modify to lt_modify.

 

lo_srv_mgr_tor->modify(

   exporting

     it_modification = lt_modify

   importing

     eo_change       = lo_change

     eo_message      = lo_message

   ).


And then save changes with the transaction manager (not posting coding).


Thanks to anyone who's got an idea


Sincerely,

Stephane


Viewing all articles
Browse latest Browse all 331

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>