Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
Caetano
Product and Topic Expert
Product and Topic Expert

Back in 2014 I wrote the blog How to analyze transaction MD04 in debug, which explained how we could analyze the execution of the Stock/Requirements List (transaction MD04) in debug mode, in order to understand which how is selected and resolve common issues that might affect the MRP elements displayed in MD04. 

In 2015, however, SAP S/4HANA was introduced and the logic to select the planning elements from the database in the Stock/Requirements List was redesigned for a better performance on the HANA database. While the old blog is still relevant for debugging transaction MD04 in SAP ECC, this new blog explains how to debug MD04 in an SAP S/4HANA system. 

We can use debugger to understand, for example, why a certain element exists in the database but it is not displayed in MD04, why an MRP element is not relevant for MRP or why it is displayed with a different quantity. 

The starting point to debug MD04 in an SAP S/4HANA system is still function module AUFBAUEN_MDPSX_ANZEIGEN; however, instead of calling different procedures where MRP elements are sequentially selected from the database and processed by an ABAP code, method GET_MAT_WERKS_S4H of class CL_PPH_MDPSX_SELECTION will be called, as shown in the figure below.

Caetano_0-1713480552536.pngFigure 1 - Method GET_MAT_WERKS_S4H being called in MD04

Inside this method, a HANA stored procedure will be called to read the all the MRP elements from the database at once, taking advantage of HANA internal parallelism. In the following figure we can see the details of the stored procedure that is called, however, we won’t be able to debug the AMDP execution in the ABAP debugger.

Caetano_1-1713480552558.pngFigure 2 - HANA procedure where data is read in MD04

After the execution of the AMDP procedure, system will collect the MRP elements read from the database and build the internal table ET_MDPS_OUT. This internal table will contain all the MRP elements that were selected from the database and that might be relevant to MRP. We can see in the figure below that 17 records were selected from the database. Here is the first point that we can check to determine if a planning element was originally selected from the database or not.

Caetano_2-1713480552569.pngFigure 3 - Contents of internal table ET_MDPS_OUT after the data selection

With the internal table populated with the MRP elements, system will call method FINALIZE_MDPSX_CDS of class CL_PPH_MDPSX_POSTPROCESSING, in order to determine if a planning element should be really displayed in MD04 and determine additional settings. In the following figure we can see the piece of code where system determines whether an MRP element is available for MRP and the firming indicator, for example (note that all comments are in English, so we can easily understand what is happening inside each call).

Caetano_3-1713480552583.pngFigure 4 - Additional checks after data selection

After the execution of this method, we will come back to the old function module AUFBAUEN_MDPSX_ANZEIGEN, and the old table MDPSX will be populated with the MRP elements. The following pictures show the contents of internal table MDPSX after the execution of function module AUFBAUEN_MDPSX_ANZEIGEN and the results displayed in transaction MD04, and as we can see in the pictures, both are very similar. 

Caetano_4-1713480552601.pngFigure 5 - Contents of internal table MDPSX

 

Caetano_5-1713480552614.pngFigure 6 - Results displayed in MD04

As we mentioned earlier, the logic to select the MRP elements from the database has been completely rewritten and the data selection has been pushed into the HANA layer. It means that old ABAP BAdIs that were previously called when reading the MRP elements from the database will no longer be called. This is the case, for example, of BAdI MD_CHANGE_MRP_DATA, which was commonly used in SAP ECC to manipulate the MRP elements in the Stock/Requirements List. As an alternative, we can use the ABAP BAdI MD_ADD_ELEMENTS, which can be for the same purpose. As of SAP S/4HANA 2022, we can also use the new AMDP BAdI PPH_SUPPLY_DEMAND_LIST, which is also called by MRP Live and the MRP Fiori Apps. This blog provides more details about this BAdI.

Finally, there are situations where we might still want to have the old logic ABAP triggered when troubleshooting an issue. This is the case, for example, if we think that there is a bug in the new logic and we want to compare it with the old one. We can force MD04 to use the old logic by typing HANA_OFF in the command field, and HANA_ON to make sure that the new logic is used. Note that this should only use used for troubleshooting, not as part of the daily usage of MD04. 

Caetano_6-1713480552616.pngFigure 7 - Command HANA_OFF in MD04

 After we finish reading the MRP elements from the database, we continue with the same flow that previously executed in SAP ECC. The following function modules, mentioned in the previous blog, are still relevant in SAP S/4HANA:

  • MD_GET_KUND: Read customer information for sales orders;
  • MD_GET_LIEF:  Read vendor information;
  • MDEZX_AUFBAUEN: Build the MRP elements texts, as they are displayed on the screen;
  • MDSUX_AUFBAUEN: Build the MD04 period totals;

Brought to you by the SAP S/4HANA RIG

 

1 Comment