cancel
Showing results for 
Search instead for 
Did you mean: 

Add FU to Frieght Booking in TM

0 Kudos
TRY.
          " Create blank freight order with  doc type
*          /scmtms/cl_tor_factory=>create_tor_tour(
          /scmtms/cl_tor_factory=>create_tor_bo(
                EXPORTING
                  iv_tor_type             = lv_fo_type " Custom DOC type
*                iv_create_initial_stage = abap_true
                  is_bo_info              = ls_bo_info
                  iv_creation_type        = /scmtms/if_tor_const=>sc_creation_type-manual
                IMPORTING
                  es_tor_root             = ls_root
                  et_tor_item             = lt_fo_item
                  et_tor_stop             = lt_stop
                  et_tor_stop_succ        = lt_succ
                CHANGING
                  co_message              = lo_message ).
        CATCH cx_root.
	lv_error = abap_true.
          CONTINUE.
      ENDTRY.


**Modify created FO with required details - Sy uname , Add FU .
      ls_root-created_by = sy-uname.
      INSERT ls_root INTO TABLE lt_tor_root.

      TRY .
          CALL METHOD /scmtms/cl_mod_helper=>mod_create_multi
            EXPORTING
              it_data = lt_tor_root
              iv_node = /scmtms/if_tor_c=>sc_node-root
            CHANGING
              ct_mod  = lt_mod.
        CATCH cx_root.
	lv_error = abap_true.
          CONTINUE.
      ENDTRY.


      TRY.
          /scmtms/cl_mod_helper=>mod_create_multi(
                EXPORTING
                  it_data        = lt_fo_item
                  iv_node        = /scmtms/if_tor_c=>sc_node-item_tr
                  iv_source_node = /scmtms/if_tor_c=>sc_node-root
                  iv_association = /scmtms/if_tor_c=>sc_association-root-item_tr
                CHANGING
                  ct_mod         = lt_mod ).
          /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key )->modify( lt_mod ).
        CATCH cx_root.
	  lv_error = abap_true.
          CONTINUE.
      ENDTRY.

/bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( )->save( IMPORTING eo_message = lo_message ) .
      CLEAR : ls_fo_key1.
      ls_fo_key1-key = ls_root-key.
      APPEND ls_fo_key1  TO lt_fo_key.


* added for Container
      CREATE DATA lr_param_cont.
      lr_param_cont->item_type = lc_cont. "CONT
      TRY.
          lo_srv_mgr->do_action(
          EXPORTING
          iv_act_key           = /scmtms/if_tor_c=>sc_action-root-add_container
          it_key               = lt_fo_key
          is_parameters        = lr_param_cont
          IMPORTING
          eo_change            = lo_change
          eo_message           = lo_message
          et_failed_key        = lt_failed_key ).

        CATCH cx_root.
	lv_error = abap_true.
          CONTINUE.
      ENDTRY.

      IF lt_failed_key IS NOT INITIAL.
        IF lo_message IS BOUND .
          /scmtms/cl_common_helper=>msg_convert_bopf_2_bapiret2(
          EXPORTING
          io_message  = lo_message
          CHANGING
          ct_bapiret2 = lt_return ).
          IF lt_return IS NOT INITIAL.
            LOOP AT lt_return INTO DATA(ls_return) .
              IF ls_return-type = 'E'.
                CONCATENATE ls_fail-error_desc lc_cm ls_return-message INTO ls_fail-error_desc.
              ENDIF.
            ENDLOOP.
          ENDIF.
        ENDIF.
        CONTINUE.
      ELSE.
        /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( )->save( IMPORTING eo_message = lo_message ) .
      ENDIF.


      TRY .
          /scmtms/cl_tor_helper_read=>get_tor_data(
              EXPORTING
                it_root_key  = lt_fo_key
              IMPORTING
                et_all_items = DATA(lt_item) ).
        CATCH cx_root.
	lv_error = abap_true.
          CONTINUE.
      ENDTRY.


      READ TABLE lt_item INTO DATA(ls_item1) WITH KEY item_type = lc_cont  item_cat = lc_tur.
      IF sy-subrc EQ 0.
        ls_cont_no = ls_item1.
        ls_cont_no-platenumber = ls_hu1-package.
        INSERT ls_cont_no INTO TABLE lt_cont_no.


        TRY .
            /scmtms/cl_mod_helper=>mod_create_multi(
                      EXPORTING
                        it_data        = lt_cont_no
                        iv_node        = /scmtms/if_tor_c=>sc_node-item_tr
                        iv_source_node = /scmtms/if_tor_c=>sc_node-root
                        iv_association = /scmtms/if_tor_c=>sc_association-root-item_tr
                      CHANGING
                        ct_mod         = lt_mod ).


            /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key )->modify( lt_mod ).


          CATCH cx_root.
	lv_error = abap_true.
            CONTINUE.
        ENDTRY.
      ENDIF.


      /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( )->save( IMPORTING eo_message = lo_message ) .


      CREATE DATA lr_param1.
      DATA(lt_hu_temp) = im_hu_t.
      DELETE lt_hu_temp WHERE labeltxt NE ls_likp-vbeln.
      LOOP AT lt_hu_temp INTO DATA(ls_hu1_n).
        DATA(lv_fu) = ls_hu1_n-tor_id.
        IF sy-tabix = 1.
          CONCATENATE lr_param1->string lv_fu INTO lr_param1->string.
        ELSE.
          CONCATENATE lr_param1->string lv_fu INTO lr_param1->string SEPARATED BY space.
        ENDIF.
        CLEAR: ls_hu1_n, lv_fu.
      ENDLOOP.


      LOOP AT lt_item INTO DATA(ls_item)." WHERE item_type = 'CONT'.
        CLEAR : ls_key.
        ls_key-key = ls_item-key.
        APPEND ls_key TO lt_item_key.
      ENDLOOP.


      lr_param1->target_item_keys = lt_item_key.
      TRY.
          lo_srv_mgr->do_action(
          EXPORTING
            iv_act_key           = /scmtms/if_tor_c=>sc_action-root-add_fu_by_fuid "item_tr-add_fu_by_fuid    "
            it_key               = lt_fo_key " rootkey
            is_parameters        = lr_param1
          IMPORTING
            eo_change            = lo_change
            eo_message           = lo_message
            et_failed_key        = lt_failed_key ).


        CATCH cx_root.
	lv_error = abap_true.
          CONTINUE.
      ENDTRY.

i am trying to create Auto Fright booking from a SE38 report using /scmtms/cl_tor_factory=>create_tor_bo() method.

it is creating Freight booking but when i call ADD_FU_BY_FUID action FUs are not added to Fright booking. Action is not returning messages, not returning failed keys and not updating FUs also.

one more issue is.. not allowing to add FUs manually also for those Fright bookings which are created from this program.

can anyone help me with this issue.

Accepted Solutions (0)

Answers (2)

Answers (2)

petra_just
Active Participant
0 Kudos

Hi Vardan and Hari,

the reason why ADD_FU_BY_FUID is not working is often that the stages do not match.

It means the destination location of the FO does not exist in the FU. to avoid this, you can either use an action to insert the stage or use ADD_FU_WITH_PLANNING. the below coding does both:

  METHOD assign_fu_to_fo.

"This method can be called from the scanning dialog to assign the package unit to the freight order
"the packer has to scan the FU and the FO
"Convert the FU and FO ids to keys
"Check if the Fu is already planned. If not, issue a message
"Check if the project id is different. If yes, issue an info
"Check if the Fu has a different end location
"If not, assign the FU to the FO using the FU ID
"If yes, add a stage before assigning the FU

DATA:
lif_srv_tor TYPE REF TO /bobf/if_tra_service_manager,
lif_tra_tor TYPE REF TO /bobf/if_tra_transaction_mgr,
lt_fo_key TYPE /bobf/t_frw_key,
lt_fu_key TYPE /bobf/t_frw_key,
lv_fu_key TYPE /bopf/conf_key,
lr_add_fu_param TYPE REF TO /scmtms/s_tor_a_add_elements,
lv_rejected TYPE boole_d,
lt_root TYPE /scmtms/t_tor_root_k,
lr_root TYPE REF TO /scmtms/s_tor_root_k,
lt_stop TYPE /scmtms/t_tor_stop_k,
lt_fo_stop_keys TYPE /bobf/t_frw_key,
lv_fo_key TYPE /bobf/conf_key,
lt_stage_first_key TYPE /bobf/t_frw_key,
lv_stop_first_key TYPE /bobf/conf_key,
lv_fo_id TYPE /scmtms/tor_id,
lv_fu_id TYPE /scmtms/tor_id,
lt_return TYPE bapiret2_tab,
ls_return TYPE bapiret2,
lt_tor_keys TYPE /bobf/t_frw_key,
lv_fu_project_id TYPE zz_tm_project_nr,
lv_fo_project_id TYPE zz_tm_project_nr,
lv_fo_dest_stop_loc_id TYPE /scmtms/location_id,
lv_fu_last_stop_loc_id TYPE /scmtms/location_id,
lv_fu_last_stop_loc_key TYPE /bobf/conf_key,
lv_fo_dest_stop_key TYPE /bobf/conf_key,
lt_fu_stages TYPE /scmtms/t_tor_stop_succ_k,
lr_fu_w_planning TYPE REF TO /scmtms/s_tor_a_add_fu_pln,
lv_fu_stage_key TYPE /bopf/conf_key,
lt_fu_stage_key TYPE /bobf/t_frw_key,
lt_fo_assigned_fus TYPE /scmtms/t_tor_root_k,
lv_stage_removed TYPE flag,
lv_project_stage TYPE flag,
lv_stage_inserted TYPE flag,
lt_stop_first_key TYPE /bobf/t_frw_key,
lr_atf_root TYPE REF TO /bobf/s_atf_root_k,
ls_parameters TYPE /bobf/s_atf_a_create_file,
lr_action_par TYPE REF TO /bobf/s_atf_a_create_file,
lt_atf_key TYPE /bobf/t_frw_key,
lt_mod TYPE /bobf/t_frw_modification,
ls_mod TYPE /bobf/s_frw_modification,
lif_message TYPE REF TO /bobf/if_frw_message,
lt_failed_key TYPE /bobf/t_frw_key.


"Declare service manager + transaction manager
lif_srv_tor = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key )."Srv Manager TOR object
lif_tra_tor = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( )."Transaction Manager
CLEAR lv_project_stage.

"Get as input scanned key (can be a warehouse order or a freight unit key)
lv_fu_id = iv_freight_unit_id.


"fill freight unit id
lv_fu_key = /scmtms/cl_tor_helper_root=>return_key_for_torid( iv_torid = lv_fu_id ).

"Transfer fu key to table
IF lv_fu_key IS NOT INITIAL.
INSERT VALUE #( key = lv_fu_key ) INTO TABLE lt_fu_key.
INSERT VALUE #( key = lv_fu_key ) INTO TABLE lt_tor_keys.
ELSE.
MESSAGE ID 'ZTM' TYPE 'E' NUMBER '017' RAISING tor_does_not_exist.
ENDIF.

"Convert FO id to freight order key
lv_fo_id = iv_freight_order_id.
lv_fo_key = /scmtms/cl_tor_helper_root=>return_key_for_torid( iv_torid = iv_freight_order_id ).
IF lv_fo_key IS NOT INITIAL.
INSERT VALUE #( key = lv_fo_key ) INTO TABLE lt_fo_key.
INSERT VALUE #( key = lv_fo_key ) INTO TABLE lt_tor_keys.
ELSE.
MESSAGE ID 'ZTM' TYPE 'E' NUMBER '017' RAISING tor_does_not_exist.
ENDIF.

"Read root header for both keys
lif_srv_tor->retrieve(
EXPORTING
iv_node_key = /scmtms/if_tor_c=>sc_node-root
it_key = lt_tor_keys
iv_fill_data = abap_true
iv_edit_mode = /bobf/if_conf_c=>sc_edit_read_only
IMPORTING
eo_message = lif_message
et_data = lt_root
et_failed_key = lt_failed_key
).

CHECK lt_root IS NOT INITIAL.

"Check if fu is planned
READ TABLE lt_root REFERENCE INTO lr_root WITH KEY key = lv_fu_key.

IF lr_root->plan_status_root = '03'.
MESSAGE ID 'ZTM' TYPE 'E' NUMBER '001' RAISING fu_already_planned.
ELSEIF lr_root->tor_cat <> 'FU'.
MESSAGE ID 'ZTM' TYPE 'E' NUMBER '034' RAISING fu_not_a_fu.
ELSE.

READ TABLE lt_root REFERENCE INTO lr_root WITH KEY key = lv_fo_key.

"check if Freight order number provided is a freight order
IF lr_root->tor_cat <> 'TO'.
MESSAGE ID 'ZTM' TYPE 'E' NUMBER '030' RAISING fo_not_an_fo.
ENDIF.


"Read the last stops of both fu and FO to check if they are different
lif_srv_tor->retrieve_by_association(
EXPORTING
iv_node_key = /scmtms/if_tor_c=>sc_node-root
it_key = lt_tor_keys
iv_fill_data = abap_true
iv_association = /scmtms/if_tor_c=>sc_association-root-stop

IMPORTING
eo_message = lif_message
et_data = lt_stop
et_failed_key = lt_failed_key
).


"Determine fus last stop
READ TABLE lt_stop ASSIGNING FIELD-SYMBOL(<stop>) WITH KEY parent_key = lv_fu_key
stop_cat = 'I'
stop_seq_pos = 'L'.
IF sy-subrc = 0.
lv_fu_last_stop_loc_id = <stop>-log_locid.
lv_fu_last_stop_loc_key = <stop>-log_loc_uuid.

"IF the fu has no stages, skip the location check
IF lv_fu_last_stop_loc_id IS INITIAL.
CLEAR iv_location_different.
MESSAGE ID 'ZTM' TYPE 'E' NUMBER '021' RAISING fu_is_empty.
EXIT.
ELSE.

"check if any of the stages has the same location
LOOP AT lt_stop ASSIGNING <stop> WHERE parent_key = lv_fo_key
AND stop_cat = 'I'.

lv_fo_dest_stop_loc_id = <stop>-log_locid.
lv_fo_dest_stop_key = <stop>-key.
IF lv_fo_dest_stop_loc_id = lv_fo_project_id.
lv_project_stage = 'X'.
ENDIF.

"If any of the destination locations is the same
IF lv_fu_last_stop_loc_id = lv_fo_dest_stop_loc_id OR lv_fu_last_stop_loc_key = lv_fo_dest_stop_key.
CLEAR iv_location_different.
EXIT.
ELSE.
iv_location_different = 'X'.
ENDIF.
ENDLOOP.
ENDIF.

"If the destination location is different
IF iv_location_different = 'X'.

CALL METHOD me->insert_stage
EXPORTING
iv_freight_order_id = iv_freight_order_id
iv_locid = lv_fu_last_stop_loc_id
CHANGING
iv_stage_inserted = lv_stage_inserted.


IF lv_stage_inserted = 'X'.
iv_stage_inserted = 'X'.
ELSE.
CLEAR lv_stage_inserted.
ENDIF.
ENDIF.

"Fill parameters for adding fu to FO
CREATE DATA lr_add_fu_param.
lr_add_fu_param->string = lv_fu_id.
lr_add_fu_param->target_item_keys = lt_fu_key.
lr_add_fu_param->abort_when_error = 'X'.

"Call action Add fu ID to FO without stage changes
lif_srv_tor->do_action(
EXPORTING
iv_act_key = /scmtms/if_tor_c=>sc_action-root-add_fu_by_fuid
it_key = lt_fo_key
is_parameters = lr_add_fu_param
IMPORTING
eo_change = DATA(lo_change)
eo_message = lif_message
et_failed_key = lt_failed_key
et_failed_action_key = DATA(lt_failed_action_key) ).
ENDIF.

IF lt_failed_action_key IS INITIAL.
iv_fu_assigned = 'X'.
ELSE.

"try again
"Find fu stage
READ TABLE lt_stop ASSIGNING <stop> WITH KEY parent_key = lv_fu_key
stop_cat = 'O'
stop_seq_pos = 'F'.
IF sy-subrc = 0.

"use the first stop of the Fu to find the related stage key
lv_stop_first_key = <stop>-key.
APPEND VALUE #( key = lv_stop_first_key ) TO lt_stop_first_key.

"Select the first stage
lif_srv_tor->retrieve_by_association(
EXPORTING
iv_node_key = /scmtms/if_tor_c=>sc_node-stop
it_key = lt_stop_first_key
iv_fill_data = abap_false
iv_association = /scmtms/if_tor_c=>sc_association-stop-stop_successor

IMPORTING
eo_message = lif_message
et_target_key = lt_stage_first_key
et_failed_key = lt_failed_key ).

CREATE DATA lr_fu_w_planning.
lr_fu_w_planning->stop_succ_keys = lt_stage_first_key.

"add an pu and a new stage
lif_srv_tor->do_action(
EXPORTING
iv_act_key = /scmtms/if_tor_c=>sc_action-root-add_fustage_with_planning
it_key = lt_fo_key
is_parameters = lr_fu_w_planning
IMPORTING
eo_change = lo_change
eo_message = lif_message
et_failed_key = lt_failed_key
et_failed_action_key = lt_failed_action_key ).

IF lt_failed_key IS INITIAL.
iv_fu_assigned = 'X'.
ELSE.
CLEAR iv_fu_assigned.
ENDIF.
ENDIF.
ENDIF.

"Persist the changes
CALL METHOD lif_tra_tor->save(
IMPORTING
ev_rejected = lv_rejected
eo_change = lo_change
eo_message = lif_message ).
vardan_goyal
Explorer
0 Kudos

Hi, I am also trying to do the same where I need to link already Created FUs from Order integration to independetly create Freight order.

I am trying to use Action ADD_FU_BY_FUID by passing Freight unit IDs to string paramter along with FO key to link but it's not linking in freight order. Even No error message also coming. Can you please let me know if you found the solution to this?

It would be great help.

Thanks,

Vardan