SAP TM- Get the document flow of Freight Order/Freight Unit/ FSD in Code


Introduction:

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.

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.

Conclusion:

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!