SAP TM- Get the document flow of Freight Order/Freight Unit/ FSD in Code
A common requirement while coding in SAP TM can be to fetch the document flow of a Freight Order. The document flow tab in the Freight Order screen shows the documents related to a Freight Order, like the Freight Unit, Sales Order, Delivery, Invoice, Freight Settlement Document, etc.
While coding in ABAP, fetching the doc flow can be required to do some processing on the related documents. Though it can be brought via tables, an easier way would be to use the classes and methods given by SAP/used by SAP. This blog shows how you can access the Document Flow of a Freight Order.
This blog shows the flow of the Freight Order, but a similar code can be used to get the flow of the Freight Unit/ FSD / Forwarding order.
Let’s Dive In
SAP provides a class /SCMTMS/CL_DOC_FLOW_FACTORY which can be leveraged to get the flow of the type of document that is desired.
The class is based on the Factory Design Pattern and will return the instance of the appropriate doc flow class based on the BO key.
For example, If you want to retrieve the Freight Order flow then, the BO key for Freight order needs to be passed to the GET_INSTANCE method of the class.
Let’s code to get the Flow of the Freight Order/ Freight Unit.
- Get an instance of the flow class of the TOR business object /SCMTMS/TOR by passing the BO Key, (The standard constant interface /SCMTMS/IF_TOR_C contains the BO Key.
CALL METHOD /scmtms/cl_doc_flow_factory=>get_instance EXPORTING iv_bo_key = /scmtms/if_tor_c=>sc_bo_key RECEIVING ro_doc_flow = DATA(lo_doc_flow_ref).
- The object lo_doc_flow_ref now contains an instance of the flow class for the TOR business object.
- Call the GET_DOC_FLOW method of the class to get the document flow passing the direction, the node key, and the key values.
- Direction –
- A – Both directions are fetched, for example, if you pass a Freight Order, it will fetch the previous documents like Sales Order, Freight Unit, and further documents like Freight Settlement documents, etc.
- F– Forward only, for example, if you pass a Freight Order, it will fetch further documents like Freight Settlement documents, etc.
- B – Backward only, for example, if you pass a Freight Order, it will fetch the previous documents like Sales Order, Freight Unit
- Node Key –
- We want to fetch the root node values which contain the Freight Order Number for example. The root key is again available in the standard constant interface /SCMTMS/IF_TOR_C.
- Key Values –
- The NodeId/DBKey value of the Freight Order.
- Direction –
- The changing parameters ct_doc_flow and ct_doc_flow_relation will contain the document flow of the Freight Order.
CALL METHOD lo_doc_flow_ref->get_doc_flow EXPORTING iv_direction = 'A' iv_node_key = /scmtms/if_tor_c=>sc_node-root it_key = lt_fu_key CHANGING ct_doc_flow = lt_root_table ct_doc_flow_relation = lt_root_table_relation.
Full executable code is provided below:
PARAMETERS: p_key TYPE /bobf/conf_key. TYPES: BEGIN OF lty_s_doc_flow_relation, source_key TYPE /bobf/conf_key, "src key target_key TYPE /bobf/conf_key, "target key relshp TYPE /scmtms/doc_flow_relshp, "relationship END OF lty_s_doc_flow_relation, lty_ts_doc_flow_relation TYPE SORTED TABLE OF lty_s_doc_flow_relation WITH NON-UNIQUE KEY primary_key COMPONENTS source_key target_key WITH NON-UNIQUE SORTED KEY target_key COMPONENTS target_key. DATA: lt_fu_key TYPE /bobf/t_frw_key, "ru key lt_root_table_relation TYPE lty_ts_doc_flow_relation, lt_root_table TYPE /scmtms/t_doc_flow, lt_root_table_relation1 TYPE TABLE OF lty_s_doc_flow_relation. "doc flow lt_fu_key = VALUE #( ( key = p_key ) ). CALL METHOD /scmtms/cl_doc_flow_factory=>get_instance EXPORTING iv_bo_key = /scmtms/if_tor_c=>sc_bo_key RECEIVING ro_doc_flow = DATA(lo_doc_flow_ref). CALL METHOD lo_doc_flow_ref->get_doc_flow EXPORTING iv_direction = 'A' iv_node_key = /scmtms/if_tor_c=>sc_node-root it_key = lt_fu_key CHANGING ct_doc_flow = lt_root_table ct_doc_flow_relation = lt_root_table_relation.
The Freight Order flow was fetched. A similar approach can be used to fetch the flow of the Freight Unit, Freight Settlement Document, and Forwarding order by passing the appropriate BO Key to the Factory class.
Business Object For Freight Settlement Document – /SCMTMS/SUPPFREIGHTINVREQ
Business Object For Forwarding Order – /SCMTMS/TRQ
Thanks for reading the blog. Until next time. Adios!