on 12-18-2014 5:52 PM
Hi, Experts!
I need help!
I need to create a freight order with a z program.
The process is as follows: The user selects in a grid, a line with the data necessary for creating the freight order and clicks on a "Create Freight Order" button. From this point on the program will create the freight order automatically.
But I do not know how... I imagined using BAPI, but I realized that this is not right in the TM. Someone can show me the correct way, please ?!
Thanks!!!!
Hi Renato.
I'm just curious... why you need to create a FO via z program? What is the business case?
Best regards
Eduardo Chagas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Eduardo!
For some cases the user needs to see a simulation of values before to decide about the creation of freight order.
I need to show a Z Screen with the simulation of values (there are some Z tables with parameters for this simulation). So, if the user to decide to create the FO, should have a button in the same screen. In this button I need create the Freight Order.
If you have some tips to help me, i will be very thankful!
Best regards
Renato Depicoli
(Sorry by my English)
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 BOPF metamodel 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
Hi Renato,
This is excerpts from the program i wrote to create Forwarding order from the data entered in an Excel sheet. You can create a freight order in line with this.
DATA : lo_trsmgr TYPE REF TO /bobf/if_tra_transaction_mgr,
lo_srvmgr TYPE REF TO /bobf/if_tra_service_manager,
lo_location TYPE REF TO /bobf/if_tra_service_manager,
lo_root TYPE REF TO /scmtms/s_trq_root_k,
lt_mod TYPE /bobf/t_frw_modification,
lo_item TYPE REF TO /scmtms/s_trq_item_k,
lo_party TYPE REF TO /scmtms/s_trq_party_k,
FIELD-SYMBOLS:<ls_mod> LIKE LINE OF lt_mod.
CREATE DATA lo_root.
lo_root->key = /bobf/cl_frw_factory=>get_new_key( ).
lo_root->trq_cat = '03'. " Category
lo_root->order_date = sy-datum. " Order Date
lo_root->transsrvlvl_code = '01'. " Service Level
lo_root->movem_type = '01'. " Movement Type
lo_root->shipping_type = '17'. " Shipping Type
lo_root->traffic_direct = '2'. " Traffic Direction
lo_root->pic_ear_req = lv_pick_date. " Pickup date
lo_root->del_lat_req = lv_dely_date. " Delivery Date
ls_location_id = lv_source. " Source Location
INSERT ls_location_id INTO TABLE lt_location_id.
ls_location_id = lv_dest. " Destination Location
INSERT ls_location_id INTO TABLE lt_location_id.
CLEAR : lo_location.
lo_location = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_location_c=>sc_bo_key ).
lo_location->convert_altern_key(
EXPORTING
iv_node_key = /scmtms/if_location_c=>sc_node-root
iv_altkey_key = /scmtms/if_location_c=>sc_alternative_key-root-location_id
it_key = lt_location_id
IMPORTING
et_result = lt_key_index " Key table with explicit index
et_key = lt_key ).
DELETE lt_key WHERE key IS INITIAL.
READ TABLE lt_key INDEX 1 INTO ls_key.
lo_root->src_loc_id = lv_source. " Source Location
lo_root->src_loc_key = ls_key-key.
READ TABLE lt_key INDEX 2 INTO ls_key.
lo_root->des_loc_id = lv_dest." Destination Location
lo_root->des_loc_key = ls_key-key.
CLEAR : lo_buspartner.
lo_buspartner = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /bofu/if_bupa_constants=>sc_bo_key ).
ls_buspartner = ls_head-ord_p.
INSERT ls_buspartner INTO TABLE lt_buspartner.
ls_buspartner = ls_head-shipr.
INSERT ls_buspartner INTO TABLE lt_buspartner.
ls_buspartner = ls_head-consg.
INSERT ls_buspartner INTO TABLE lt_buspartner.
lo_buspartner->convert_altern_key(
EXPORTING
iv_node_key = /bofu/if_bupa_constants=>sc_node-root
iv_altkey_key = /bofu/if_bupa_constants=>sc_alternative_key-root-partner
it_key = lt_buspartner
IMPORTING
et_result = lt_key_bpdata
et_key = lt_key_bp ).
IF NOT ls_head-ord_p IS INITIAL.
READ TABLE lt_key_bp INDEX 1 INTO ls_key.
lo_root->order_party_key = ls_key-key.
lo_root->order_party_id = ls_head-ord_p.
ENDIF.
IF NOT ls_head-shipr IS INITIAL.
READ TABLE lt_key_bp INDEX 2 INTO ls_key.
lo_root->shipper_key = ls_key-key.
lo_root->shipper_id = ls_head-shipr.
ENDIF.
IF NOT ls_head-consg IS INITIAL.
READ TABLE lt_key_bp INDEX 3 INTO ls_key.
lo_root->consignee_key = ls_key-key.
lo_root->consignee_id = ls_head-consg.
ENDIF.
APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.
<ls_mod>-node = /scmtms/if_trq_c=>sc_node-root.
<ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.
<ls_mod>-source_key = lo_root->key.
<ls_mod>-root_key = lo_root->key.
<ls_mod>-key = lo_root->key.
<ls_mod>-data = lo_root.
CLEAR lo_item.
CREATE DATA lo_item.
lo_item->key = /bobf/cl_frw_factory=>get_new_key( ).
lo_item->prd_key = /bobf/cl_frw_factory=>get_new_key( ).
lo_item->item_id = lv_item_id.
lo_item->item_type = lc_it_typ.
lo_item->item_cat = lc_it_cat.
lo_item->qua_pcs_val = ls_item-qty.
lo_item->qua_pcs_uni = ls_item-qty_uom.
lo_item->gro_wei_val = ls_item-gro_wt.
lo_item->gro_wei_uni = ls_item-gro_wt_uom.
lo_item->product_id = ls_item-pro_id.
lo_item->del_sel_time = lv_dely_date.
lo_item->del_lat_req = lv_dely_date.
APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.
<ls_mod>-node = /scmtms/if_trq_c=>sc_node-item.
<ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.
<ls_mod>-source_node = /scmtms/if_trq_c=>sc_node-root.
<ls_mod>-source_key = lo_root->key.
<ls_mod>-root_key = lo_root->key.
<ls_mod>-key = lo_item->key.
<ls_mod>-data = lo_item.
<ls_mod>-association = /scmtms/if_trq_c=>sc_association-root-item.
* Create the Forwarding Order record:
CALL METHOD lo_srvmgr->modify
EXPORTING
it_modification = lt_mod
IMPORTING
eo_change = lo_change
CALL METHOD lo_trsmgr->save.
eo_message = lo_message.
Thanks,
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Michael, thank you for answering too!
First Sorry for my lack of familiarity, but i'm trying to learn it. One day I'll get it, I'm sure.
These excerpts of your program are helping me so much.
But, I'm having problems debugging it, because I don't know if I declared the variables and
objects correctly or if it is generating Dump because I don't know how enter the correct data.
Thanks!
Hi, Bharath!
Thanks for contact.
I'm new in WD, BOPF and TM... so sorry, but my question might be stupid.
I took the the code and completed it just to activate. Now I have 2 problems... how to fill the values and to know if the objects and variables are correctly defined.
------------------------------------------------------------------------------------------
METHOD onactiongerar_fo .
TYPES:
BEGIN OF y_item,
qty TYPE /scmtms/qua_pcs_val,
qty_uom TYPE /scmtms/qua_pcs_uni,
gro_wt TYPE /scmtms/qua_gro_wei_val,
gro_wt_uom TYPE /scmtms/qua_gro_wei_uni,
pro_id TYPE /scmtms/product_id,
END OF y_item.
DATA:
lo_root TYPE REF TO /scmtms/s_trq_root_k,
lo_trsmgr TYPE REF TO /bobf/if_tra_transaction_mgr,
lo_srvmgr TYPE REF TO /bobf/if_tra_service_manager,
lo_location TYPE REF TO /bobf/if_tra_service_manager,
lt_mod TYPE /bobf/t_frw_modification,
lo_item TYPE REF TO /scmtms/s_trq_item_k,
lo_party TYPE REF TO /scmtms/s_trq_party_k,
lo_buspartner TYPE REF TO /bobf/if_tra_service_manager,
lo_change TYPE REF TO /bobf/if_tra_change,
lo_message TYPE REF TO /bobf/if_frw_message.
DATA:
lv_pick_date TYPE /scmtms/pic_ear_req_datetime,
lv_dely_date TYPE /scmtms/pic_lat_req_datetime.
DATA:
ls_item TYPE y_item,
lt_key_lc TYPE /bobf/t_frw_key,
ls_key_lc TYPE /bobf/s_frw_key,
lt_key_lc_index TYPE /bobf/t_frw_keyindex,
lt_location_id TYPE /bobf/t_frw_key,
ls_location_id TYPE /bobf/s_frw_key,
lv_source TYPE /bobf/s_frw_key,
lv_dest TYPE /bobf/s_frw_key,
lv_source_c TYPE char20,
lv_dest_c TYPE char20,
lt_key_bp TYPE /bobf/t_frw_key,
ls_key_bp TYPE /bobf/s_frw_key,
lt_key_bp_index TYPE /bobf/t_frw_keyindex,
lt_buspartner TYPE /bobf/t_frw_key,
ls_buspartner TYPE /bobf/s_frw_key,
lv_head_ord_p TYPE /bobf/s_frw_key,
lv_head_shipr TYPE /bobf/s_frw_key,
lv_head_consg TYPE /bobf/s_frw_key,
lv_head_ord_p_c TYPE char10,
lv_head_shipr_c TYPE char10,
lv_head_consg_c TYPE char10,
lv_item_id TYPE /scmtms/item_id,
lv_it_typ TYPE /scmtms/trq_item_type,
lv_it_cat TYPE /scmtms/item_category.
FIELD-SYMBOLS:
<ls_mod> LIKE LINE OF lt_mod.
lv_pick_date = sy-datum.
lv_dely_date = sy-datum + 1.
CREATE DATA lo_root.
lo_root->key = /bobf/cl_frw_factory=>get_new_key( ).
lo_root->trq_cat = '03'. " Category
lo_root->order_date = sy-datum. " Order Date
lo_root->transsrvlvl_code = '01'. " Service Level
lo_root->movem_type = '01'. " Movement Type
lo_root->shipping_type = '17'. " Shipping Type
lo_root->traffic_direct = '2'. " Traffic Direction
lo_root->pic_ear_req = lv_pick_date. " Pickup date
lo_root->del_lat_req = lv_dely_date. " Delivery Date
*### LOCATION
CLEAR : lo_location.
lo_location = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_location_c=>sc_bo_key ).
ls_location_id = lv_source.
INSERT ls_location_id INTO TABLE lt_location_id.
ls_location_id = lv_dest.
INSERT ls_location_id INTO TABLE lt_location_id.
lo_location->convert_altern_key(
EXPORTING
iv_node_key = /scmtms/if_location_c=>sc_node-root
iv_altkey_key = /scmtms/if_location_c=>sc_alternative_key-root-location_id
it_key = lt_location_id
IMPORTING
et_result = lt_key_lc_index " Key table with explicit index
et_key = lt_key_lc ).
DELETE lt_key_lc WHERE key IS INITIAL.
* lv_source_c = lv_source.
CALL FUNCTION 'RS_SCRP_HEADER_RAW_TO_CHAR'
EXPORTING
header_int = lv_source
IMPORTING
header_char = lv_source_c.
READ TABLE lt_key_lc INDEX 1 INTO ls_key_lc.
lo_root->src_loc_id = lv_source_c. " Source Location
lo_root->src_loc_key = ls_key_lc-key.
* lv_dest_c = lv_dest.
CALL FUNCTION 'RS_SCRP_HEADER_RAW_TO_CHAR'
EXPORTING
header_int = lv_dest
IMPORTING
header_char = lv_dest_c.
READ TABLE lt_key_lc INDEX 2 INTO ls_key_lc.
lo_root->des_loc_id = lv_dest_c. " Destination Location
lo_root->des_loc_key = ls_key_lc-key.
*### BUSPARTNER
CLEAR : lo_buspartner.
lo_buspartner = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /bofu/if_bupa_constants=>sc_bo_key ).
ls_buspartner = lv_head_ord_p.
INSERT ls_buspartner INTO TABLE lt_buspartner.
ls_buspartner = lv_head_shipr.
INSERT ls_buspartner INTO TABLE lt_buspartner.
ls_buspartner = lv_head_consg.
INSERT ls_buspartner INTO TABLE lt_buspartner.
lo_buspartner->convert_altern_key(
EXPORTING
iv_node_key = /bofu/if_bupa_constants=>sc_node-root
iv_altkey_key = /bofu/if_bupa_constants=>sc_alternative_key-root-partner
it_key = lt_buspartner
IMPORTING
et_result = lt_key_bp_index "lt_key_bpdata
et_key = lt_key_bp ).
IF NOT lv_head_ord_p IS INITIAL.
* lv_head_ord_p_c = lv_head_ord_p.
CALL FUNCTION 'RS_SCRP_HEADER_RAW_TO_CHAR'
EXPORTING
header_int = lv_head_ord_p
IMPORTING
header_char = lv_head_ord_p_c.
READ TABLE lt_key_bp INDEX 1 INTO ls_key_bp.
lo_root->order_party_key = ls_key_bp-key.
lo_root->order_party_id = lv_head_ord_p_c.
ENDIF.
IF NOT lv_head_shipr IS INITIAL.
* lv_head_shipr_c = lv_head_shipr.
CALL FUNCTION 'RS_SCRP_HEADER_RAW_TO_CHAR'
EXPORTING
header_int = lv_head_shipr
IMPORTING
header_char = lv_head_shipr_c.
READ TABLE lt_key_bp INDEX 2 INTO ls_key_bp.
lo_root->shipper_key = ls_key_bp-key.
lo_root->shipper_id = lv_head_shipr_c.
ENDIF.
IF NOT lv_head_consg IS INITIAL.
* lv_head_consg_c = lv_head_consg.
CALL FUNCTION 'RS_SCRP_HEADER_RAW_TO_CHAR'
EXPORTING
header_int = lv_head_consg
IMPORTING
header_char = lv_head_consg_c.
READ TABLE lt_key_bp INDEX 3 INTO ls_key_bp.
lo_root->consignee_key = ls_key_bp-key.
lo_root->consignee_id = lv_head_consg_c.
ENDIF.
APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.
<ls_mod>-node = /scmtms/if_trq_c=>sc_node-root.
<ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.
<ls_mod>-source_key = lo_root->key.
<ls_mod>-root_key = lo_root->key.
<ls_mod>-key = lo_root->key.
<ls_mod>-data = lo_root.
CLEAR lo_item.
CREATE DATA lo_item.
lo_item->key = /bobf/cl_frw_factory=>get_new_key( ).
lo_item->prd_key = /bobf/cl_frw_factory=>get_new_key( ).
lo_item->item_id = lv_item_id.
lo_item->item_type = lv_it_typ.
lo_item->item_cat = lv_it_cat.
lo_item->qua_pcs_val = ls_item-qty.
lo_item->qua_pcs_uni = ls_item-qty_uom.
lo_item->gro_wei_val = ls_item-gro_wt.
lo_item->gro_wei_uni = ls_item-gro_wt_uom.
lo_item->product_id = ls_item-pro_id.
lo_item->del_sel_time = lv_dely_date.
lo_item->del_lat_req = lv_dely_date.
APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.
<ls_mod>-node = /scmtms/if_trq_c=>sc_node-item.
<ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.
<ls_mod>-source_node = /scmtms/if_trq_c=>sc_node-root.
<ls_mod>-source_key = lo_root->key.
<ls_mod>-root_key = lo_root->key.
<ls_mod>-key = lo_item->key.
<ls_mod>-data = lo_item.
<ls_mod>-association = /scmtms/if_trq_c=>sc_association-root-item.
* Create the Forwarding Order record:
CALL METHOD lo_srvmgr->modify
EXPORTING
it_modification = lt_mod
IMPORTING
eo_change = lo_change.
CALL METHOD lo_trsmgr->save
IMPORTING
eo_message = lo_message.
ENDMETHOD.
------------------------------------------------------------------------------------------
The dump occurs in the following point of code (break point).
I believe this is because I was not passing data to the method.
But do not know what / how to pass.
Follow the dump...
If you have some idea to help me, i will be very thankful!
Thanks in advance.
Renato Depicoli
Hi everybody,
I have a problem with this code. When I created the Freight Order with one or two Freight Units, the development is apparently "correct", however when I open the NWBC, the Freight Order is not linked with any Freight Units. How can I create the Freight Order that will link with the Freight Units correctly?
I already filled in the LT_ITEM with the Freight Unit details.
Thanks a lot.
Wellington Oliveira.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Connecting the freight units to the freight order is not done via ITEMs, as strange as it may look.
Instead, the STOP instances of the freight units point to the corresponding STOP instances of the freight order. The internal logic of the underlying business object TOR takes care of copying the items from FU to FO.
There are two options you might want to pursue, both of them possible after creating the FUs and the (empty) FO:
1. use the TOR ROOT action ADD_FU_BY_FUID of the freight order. In the action parameters, component STRING, you need to specify the FU IDs separated by newline, whereas in the TARGET_ITEM_KEYS you need to specify the key of the vehicle item of the FO.
2. Use the TOR STOP action ASSIGN_STOP_TO_CAPA_EA of the freight units. In the action parameters, you need to fill the links between the FU stops and the FO stops, something like:
CREATE DATA lr_asgn_param.
LOOP AT lt_k_fu_stop_out ASSIGNING <key>.
ls_stop_assg-req_stop = <key>-key.
ls_stop_assg-capa_stop = lv_fo_outb_key. "outbound stop key = the departure location in FO
ls_stop_assg-capa_item = lv_fo_item. "key of the vehicle item in FO
INSERT ls_stop_assg INTO TABLE lr_asgn_param->assgn_data.
ENDLOOP.
LOOP AT lt_k_fu_stop_inb ASSIGNING <key>.
ls_stop_assg-req_stop = <key>-key.
ls_stop_assg-capa_stop = lv_fo_inb_key . "inbound stop key = the arrival location in FO
ls_stop_assg-capa_item = lv_fo_item. "key of the vehicle item in FO
INSERT ls_stop_assg INTO TABLE lr_asgn_param->assgn_data.
ENDLOOP.
lt_k_stop = lt_k_fu_stop_out.
INSERT LINES OF lt_k_fu_stop_inb INTO TABLE lt_k_stop.
io_modify->do_action(
EXPORTING
iv_act_key = /scmtms/if_tor_c=>sc_action-stop-assign_stop_to_capa_ea
it_key = lt_k_stop
is_parameters = lr_asgn_param ).
Regards,
Dragos
Hello Renato,
Check the TOR actions in /BOBF/TEST_UI transaction.
Best Regards, Marcelo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
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.