cancel
Showing results for 
Search instead for 
Did you mean: 

Create Freight Order with Zprogram

Former Member
0 Kudos

Hi All,

I got a requirement to create the Freight Order in a Z program .

I tried to create FO using  methods mentioned below by taking the reference from link https://scn.sap.com/thread/3670872


But FO is neither created nor raised any errors .


-/scmtms/cl_tor_factory=>create_tor_tour

-/scmtms/cl_tor_factory=>CREATE_TOR_FO

Please suggest.

Thanks,

Arun

Accepted Solutions (1)

Accepted Solutions (1)

petra_just
Active Participant
0 Kudos

hi Arun,

the below program creates an FO. The FO type is determined by a BRF+condition. You have to create this condition with type /SCMTMS/TOR_TYPE. You can also call the condition that is already used for the other FOs. to find out which one that is, use the following select:

  data:
       lo_message       type ref to /bobf/if_frw_message.

  data:
       lt_cond_id       type /scmtms/t_condition_id,
       lt_cond_key      type /bobf/t_frw_key,
       ls_cond_key      type /bobf/s_frw_key,
       ls_tor_type_rule type /scmtms/s_tor_type_det_rule,
       ls_tor_info      type /scmtms/s_tor_fo_info,
       ls_tor_root      type /scmtms/s_tor_root_k,
       ls_fo_key        type /bobf/s_frw_key,
       lt_failed_key    type /bobf/t_frw_key.


   data:
      lv_cond_id        type /scmtms/condition_id.

     clear et_fo_key.

     lv_cond_id = 'ZFO_TYPE_DETERMINATION'.
     insert lv_cond_id into table lt_cond_id.
     lt_cond_key = /scmtms/cl_cond_ol=>condid_get_condkey( it_cond_it = lt_cond_id ).

     read table lt_cond_key into ls_cond_key index 1.
     if sy-subrc = 0.
       clear ls_tor_type_rule.
       ls_tor_type_rule-det_rule       /scmtms/if_pln_const=>sc_tor_type_det-cond_based.
       ls_tor_type_rule-torty_det_cond = ls_cond_key-key.
     endif.
    

* this structure is used to pass data to the FO. In this program, the bopf key of the start and end location and the FO start date is filled. If your spec gives u a rule for the start and end location, use *this. If you want to try out with some start and end location bopf keys, use table /scmtms/d_shloc *to find some sample locations in field LOCUUID. maybe, you want to use locations from an existing FO. In this case, you use table /scmtms/D_TORROT to get an FO number


     clear ls_tor_info.
     ls_tor_info-loc_src_key       = ms_tor_info-src_key. "source location bopf key
     ls_tor_info-loc_dst_key       = ms_tor_info-dst_key. "destination location bopf key
     ls_tor_info-pickup_start_date = ms_tor_info-pickup_start. "FO start date


*this does the FO creation, you pass the creation type and the Tor type det rule
     /scmtms/cl_tor_factory=>create_tor_fo(
       exporting
         iv_do_modify      = abap_true
         iv_creation_type  = /scmtms/if_tor_const=>sc_creation_type-manual
         is_tor_type_rules = ls_tor_type_rule
         is_fo_info        = ls_tor_info
       importing
         es_tor_root       = ls_tor_root
         et_failed_key     = lt_failed_key
       changing
         co_message        = lo_message ).


ls_tor_root will have the FO number if it worked.

Hope it helps

Petra

Former Member
0 Kudos

Hi Petra,

I tried the above steps but it is not creating the FO and not showing any errors .

Thanks,

Venkat

petra_just
Active Participant
0 Kudos

Venkat,

you have to check if failed key table has entries. If it does, there was a problem.

Please paste the table entries of failed key table as a picture.

Petra

Former Member
0 Kudos

Hi Petra,

Failed key having empty records and Is_tor_root table is filled but not creating the FO in data base table.

  /scmtms/cl_tor_factory=>create_tor_fo(
exporting
iv_do_modify      = abap_true
iv_creation_type  = /scmtms/if_tor_const=>sc_creation_type-manual
is_tor_type_rules = ls_tor_type_rule
is_fo_info        = ls_tor_info
importing
es_tor_root       = ls_tor_root
et_failed_key     = lt_failed_key
changing
co_message        = lo_message ).


IF lo_msg IS BOUND .
/scmtms/cl_common_helper=>msg_convert_bopf_2_bapiret2(
EXPORTING
io_message  = lo_message
CHANGING
ct_bapiret2 = lt_return[] ).
ENDIF.


CALL METHOD lr_srvmgr->modify
EXPORTING
it_modification = lt_mod
IMPORTING
eo_message      = lo_msg.



IF lo_msg IS BOUND .
/scmtms/cl_common_helper=>msg_convert_bopf_2_bapiret2(
EXPORTING
io_message  = lo_msg
CHANGING
ct_bapiret2 = lt_return[] ).

lo_msg->get_messages(
EXPORTING
iv_severity             'E'
IMPORTING
et_message              = lt_message ).
ENDIF.
CLEAR lo_msg.
DATA: lv_rejected TYPE c,
lo_txn      TYPE REF TO /bobf/if_tra_transaction_mgr.


lo_txn = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ).

lo_txn->save(
EXPORTING
iv_transaction_pattern = /bobf/if_tra_c=>gc_tp_save_and_continue
  IMPORTING
eo_message  = lo_msg
eo_change   = lo_change
ev_rejected = lv_rejected ).

IF lo_msg IS BOUND .
/scmtms/cl_common_helper=>msg_convert_bopf_2_bapiret2(
EXPORTING
io_message  = lo_msg
CHANGING
ct_bapiret2 = lt_return[] ).

lo_msg->get_messages(
EXPORTING
iv_severity             'E'
IMPORTING
et_message              = lt_message ).
ENDIF.

Thanks,

Venkat

Former Member
0 Kudos

HI Petra ,

I am able to create the FO now but I got an issue with assigning  FU to FO.

I used '/scmtms/if_tor_c=>sc_action-root-add_fu_by_fuid

' action to update.

*------------------------------------------------------------------
*               adding FU's to new FO
*------------------------------------------------------------------
DATA: lt_fo_key       TYPE /bobf/t_frw_key,                          " Key Table
lwa_fo_key      TYPE /bobf/s_frw_key,
lt_fo_root      TYPE /scmtms/t_tor_root_k,
lt_fu_root      TYPE /scmtms/t_tor_root_k,
lwa_fu_root     TYPE /scmtms/s_tor_root_k,
lr_s_parameters TYPE REF TO data,
ls_parameters   TYPE /scmtms/s_tor_a_add_elements,
lv_string       TYPE /scmtms/tor_id.

lwa_fo_key-key = ls_tor_root-key.
APPEND lwa_fo_key TO lt_fo_key.


IF lt_fu_root IS NOT INITIAL.

READ TABLE lt_fu_root INTO lwa_fu_root INDEX 1.
IF sy-subrc = 0.
lv_string = lwa_fu_root-tor_id.
ENDIF.

  1. ENDIF.


    ls_parameters-string = lv_string.
    ls_parameters-target_item_keys = lt_key_fu.
    GET REFERENCE OF ls_parameters INTO lr_s_parameters.


CALL METHOD lo_srv_mgr->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_s_parameters
IMPORTING
eo_change     = lo_change
eo_message    = lo_msg
*       et_failed_key =
*       et_failed_action_key =
.

IF lo_msg IS BOUND .
/scmtms/cl_common_helper=>msg_convert_bopf_2_bapiret2(
EXPORTING
io_message  = lo_msg
CHANGING
ct_bapiret2 = lt_return[] ).
ENDIF.


lr_srvmgr = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key ).
CALL METHOD lr_srvmgr->modify
EXPORTING
it_modification = lt_mod
IMPORTING
eo_message      = lo_msg.



IF lo_msg IS BOUND .
/scmtms/cl_common_helper=>msg_convert_bopf_2_bapiret2(
EXPORTING
io_message  = lo_msg
CHANGING
ct_bapiret2 = lt_return[] ).

endif.

Please correct me where I made the mistake.

Thanks,

Venkat

Answers (1)

Answers (1)

petra_just
Active Participant

hi,

please find below the coding to add an fu to an FO which works : It will first add the fu based on the fu id. In some cases, the required stage might not be there in the FO which is the reason why you cannot assign the fu to this FO. In this case, you can try again with adding the fu to the FO like you would do it in the cockpit. then, the stage is inserted into the FO. Hope you find it useful. If yes, revert back it, so that the answer can be marked as correct and the community can use it.

        "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
            lo_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           = lo_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
               lo_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              = lo_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
              lo_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           = lo_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.