on 2022 Nov 09 8:31 AM
Hello,
I am using the `TransportationOrderGenericRequest_In` service to create Fright Orders. Then, inside the enchanted method `/scmtms/tor_if_se_tor_gn_req~change_modification`, I am trying to do some modifications to the Freight Units which I am later assigning to the Freight Order created.
As the Freight Order created can have different carrier declared than the Freight Units, when trying to assign them using the `/scmtms/if_tor_c=>sc_action-root-add_fu_by_fuid` action, it would return an error. Because of that, I am trying to modify the Freight Units on the fly and change their carriers to the one from the Freight Order.
The problem is that, even if the modification itself helps with the assignment and it goes without any issues (and without the modifications it wouldn't), the Freight Units are not modified in the database table, nor when displayed using front-end. But the timestamp and username for the last change of the Freight Unit updates to the moment of the code execution.
Why the data is not getting updated, but the assignment goes fine and the change timestamp updates? Can you help me to find the issue and make those modification save properly?
DATA ls_changed_data TYPE /scmtms/s_tor_root_k.
DATA lt_changed_fields TYPE /bobf/t_frw_name.
DATA lv_partner TYPE bu_partner.
DATA lv_partner_guid TYPE bu_partner_guid.
DATA lo_srv_tor TYPE REF TO /bobf/if_tra_service_manager.
DATA lt_mod_fu TYPE /bobf/t_frw_modification.
lo_srv_tor = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key ).
lv_partner = CONV bu_partner( is_input-transportation_order-carrier_party-internal_id-content ).
CALL FUNCTION 'BUPA_NUMBERS_GET'
EXPORTING
iv_partner = lv_partner
IMPORTING
ev_partner = lv_partner
ev_partner_guid = lv_partner_guid.
IF lv_partner IS NOT INITIAL AND lv_partner_guid IS NOT INITIAL.
ls_changed_data-tsp = lv_partner_guid.
ls_changed_data-tspid = lv_partner.
INSERT /scmtms/if_tor_c=>sc_node_attribute-root-tsp INTO TABLE lt_changed_fields.
INSERT /scmtms/if_tor_c=>sc_node_attribute-root-tspid INTO TABLE lt_changed_fields.
ENDIF.
LOOP AT is_input-transportation_order-btd_reference INTO DATA(ls_btd_ref).
lv_fu_key = /scmtms/cl_tor_helper_root=>return_key_for_torid( iv_torid = ls_btd_ref-btd_ref-id-content ).
IF ls_changed_data IS NOT INITIAL.
INSERT VALUE /bobf/s_frw_modification(
node = /scmtms/if_tor_c=>sc_node-root
key = lv_fu_key
change_mode = /bobf/if_frw_c=>sc_modify_update
data = REF #( ls_changed_data )
changed_fields = lt_changed_fields
) INTO TABLE lt_mod_fu.
ENDIF.
ENDLOOP.
IF lt_mod_fu IS NOT INITIAL.
lo_srv_tor->modify(
EXPORTING
it_modification = lt_mod_fu
IMPORTING
eo_change = lo_change
eo_message = lo_message ).
ENDIF.
" Here happens the FU assignment and after the modifications it goes without any issues!
I've also tried the solution with saving the data using the Transaction Manager, but it is not suitable in this situation, as then, even if some errors occur later, the Freight Order will be saved and it shouldn't.
Thanks in advance.
Request clarification before answering.
Hello Norbert,
Why would you assign a carrier on the Freight Unit? I'm not sure I understand that part. Assuming that's a requirement, instead of passing the TSP ID as a modification, maybe you can try using the BOPF action ASSIGN_TSP available at the TOR ROOT node.
Let me know if this works.
Thanks,
Rohan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello szelbi
I think you need to save freight units carrier changes to the database before assigning them to a freight order. On the other hand you mustn't do that from within the BAdI implementation as you are going to mess up transactional processing of the TransportationOrderGenericRequest_In service.
Therefore you would need to post carrier changes and subsequent FUs assignments to the FO in a separate LUW (logical unit of work).
I would suggest the following course of actions:
1. Encapsulate all the code that changes FU carrier and assigns FU to FO in a separate function module. The function interface could just receive FO number and FUs numbers.
2. Test if the function works for an already existing freight order.
3. Call the function from within the BAdI implementation using bgRFC as follows
DATA(lo_dest) = cl_bgrfc_destination_inbound=>create( /scmtms/cl_trig_helper=>return_trigger_rfc_dest( ) ).
DATA(lo_unit) = lo_dest->create_trfc_unit( ).
CALL FUNCTION 'your function'
IN BACKGROUND UNIT lo_unit
EXPORTING [...]
Best regards
Dominik Tylczynski
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And how would you see changing the Freight Units back when some error occurs later in the Freight Order creation process?
When there is some action executed by me, e.g. the FUs assignment, there is not problem as I can detect it and set the FUs carriers to the previous values. But what if the error occurs in some more generic SAP code?
User | Count |
---|---|
3 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.