Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9269

Re: Create a Freight Order with a Z program

$
0
0

The types of ls_location_id and lt_location_id are not suitable for that CONVERT_ALTERNATIVE_KEY call.

 

IT_KEY must be there always the data type that is maintained in BOPFmetamodel for the called alternative key. In case of location, it is /SCMTMS/T_LOC_ALT_ID - basically a table of CHAR20, so you can simply insert LV_SOURCE and LV_DEST into it.


Beware: the report posted by you does not create freight orders, but forwarding orders.


To create an empty FO, you should use the following method

 

  /scmtms/cl_tor_factory=>create_tor_tour(

    EXPORTING

      iv_tor_type             = iv_type

      iv_create_initial_stage = abap_true

      iv_creation_type        = /scmtms/if_tor_const=>sc_creation_type-manual

    IMPORTING

      es_tor_root             = ls_root

      et_tor_item             = lt_item

      et_tor_stop             = lt_stop

      et_tor_stop_succ        = lt_succ

    CHANGING

      co_message              = lo_message ).

 

which creates (1) the root node (2) the mandatory item corresponding to the vehicle, (4) two stops, one outbound STOP_CAT = 'O' and one inbound STOP_CAT = 'I', corresponding to the departure and destination respectively, and finally (4) one stage corresponding to the movement between these two stops.

 

Afterwards , you must put your location ids (and location keys, after doing the proper alternative key call) in these two STOP records (beware the stop category). The field PLAN_TRANS_TIME of this node should contain the departure time (for the outbound stop) and arrival time (for inbound stop).

Hint: you can provide the location keys and the timestamps for departure and arrival via importing parameter IS_FO_INFO - then the two stop nodes will be created with the correct data and you won't need to adjust LT_STOP anymore...

 

Then you should add the business partners (ID and keys) in the corresponding fields of the root structure.

 

Then you should add the items to LT_ITEM. Take care that all items must be "in" the vehicle, meaning that the field ITEM_PARENT_KEY must be filled with the value of the field KEY of the existing entry in this table. Also, the field MAIN_CARGO_ITEM must be set to X. The last two statements are valid for all items, if you don't have subitems; if there are subitems, like products under packages, then of course the statements are valid only for the highest level items (packages). Use method /bobf/cl_frw_factory=>get_new_key() to generate GUIDS for the new items (field KEY). The fields PARENT_KEY and ROOT_KEY must contain the key of the newly created root record.

 

After you're finished with inserting data into these tables, create modification entries, post them to BOPF engine, then save transaction:

 

    CLEAR lt_mod.

    INSERT ls_root INTO TABLE lt_tor_root.

 

    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.

 

    /scmtms/cl_mod_helper=>mod_create_multi(

      EXPORTING

        it_data        = lt_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 ).

 

    /scmtms/cl_mod_helper=>mod_create_multi(

      EXPORTING

        it_data        = lt_stop

        iv_node        = /scmtms/if_tor_c=>sc_node-stop

        iv_source_node = /scmtms/if_tor_c=>sc_node-root

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

      CHANGING

        ct_mod         = lt_mod ).

 

    /scmtms/cl_mod_helper=>mod_create_multi(

      EXPORTING

        it_data        = lt_succ

        iv_node        = /scmtms/if_tor_c=>sc_node-stop_successor

        iv_source_node = /scmtms/if_tor_c=>sc_node-stop

        iv_association = /scmtms/if_tor_c=>sc_association-stop-stop_successor

        iv_do_sorting  = abap_true

      CHANGING

        ct_mod         = lt_mod ).

 

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

    /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( )->save( ).

 

Regards,

Dragos


Viewing all articles
Browse latest Browse all 9269

Trending Articles