Skip to Content
Technical Articles
Author's profile photo Caetano Almeida

S/4HANA: How to analyze transaction MD04 in debug


A long time ago I wrote the blog explaining how to analyze the Stock/Requirements List (transaction MD04) in debug. I wrote this blog because I have seen many threads in SCN asking why a specific planning element is not appearing in MD04 or why an element appears with a different quantity than expected. Considering that debugging MD04 was pretty straightforward, even a functional person with minimal ABAP knowledge would be able to do it.

This blog was published in 2014 and one year later SAP announced SAP S/4HANA, which changed a little bit the design behind the Stock/Requirements List, in order to improve the performance when reading the planning elements. If previously the planning elements were read one by one from the database and processed individually by an ABAP code, now a single HANA stored procedure reads everything from the database and they are all processed together by an ABAP code.

Besides those changes, the code logic behind MD04, is still the same: The same function module AUFBAUEN_MDPSX_ANZEIGEN is called to read the planning elements from the database and the planning elements relevant for MRP will fill the internal table MDPSX.

The difference starts within function module AUFBAEN_MDPSX_ANZEIGEN. Here, there is a new piece of code which checks if system should use the classic logic or if should trigger the new selection built specifically for the HANA database.

When the new logic is selected, method GET_MAT_WERKS_S4H of class CL_PPH_MDPSX_SELECTION will be triggered, and here is where the magic will happen. Firstly, method EXECUTE_PROCEDURES_S4H will be executed, where the whole database selection will be triggered.

This data selection logic happens in HANA and we would have to access HANA Studio to be able to debug this step, so we cannot see the actual selection in the ABAP debugger. We can see, however, that the database selection results will be stored in the internal table LT_MDPS, so if there if a planning element is already missing here, it means it was not selected from the database and the problem is most likely related to the database selection in the HANA stored procedure.

After that, method FINALIZE_MDPSX_CDS from class CL_PPH_MDPSX_POSTPROCESSING will be called. Here is where the MRP elements selected from the database will be postprocessed and MRP will filter out certain MRP elements based on the settings or it will calculate the quantities, for example.

Within this method, we will basically have a loop in table LT_MDPSX_ENH, which will contain the MRP elements selected from the database and we will have specific checks for each kind of MRP element. In the following picture we can see where this loop starts and we can also see a piece of code with checks that are executed for the MRP elements consistency and also for stock transfer storage locations. Each check is executed separately and the best part is that we now have comments in English!!!

One point to be considered is that, with this new logic, the ABAP BAdI MD_CHANGE_MRP_DATA, which was traditionally called to change an MRP element is no longer called. However, BAdI MD_ADD_ELEMENTS is called after this loop and it can still be used for the same purpose.

Besides those changes when reading the MRP elements, the overall logic is the same and the additional function modules mentioned on my previous blog are still beins used:

  • 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 – Buld the MD04 period totals;


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Phil Cooley
      Phil Cooley

      Nice blog Caetano Almeida and definitely a key transaction to know more detail about. Are you able to include more detail on how this is run from a Front-end point of view (FLP) for those that are not that familiar with how this is run in the new world. Would also be good to know which versions this applies to or is this the method for all S4 versions?

      Thanks again for sharing!

      Phil Cooley

      Author's profile photo Naga Seerla
      Naga Seerla

      Hello Caetano Almeida

      I hope you can help me with the following issue in MD04 in SPA ECC 6.0:

      We have implemented the method: CHANGE_MDPSX_MDLA in BADI: MD_CHANGE_MRP_DATA to show one line per inbound delivery instead of multiple lines for individual batch split.

      Before the change, each batch added in the inbound delivery under ‘batch split’ are being displayed as a single line per batch and in the method, we added code to sum the total open quantity of the inbound delivery to show on the first line and if the inbound delivery# matches for MD04 element, we have the set the following flags to not show rest of the lines pertaining to the same inbound delivery but for a different batch.

      ch_exit ‘X’.

      ch_changed ‘X’.


      However, what we noticed is that, when we open MD04 for the first time, we are seeing more than one line per inbound delivery and they pertain to different batches and when we click on refresh the enhancement gets triggered and the additional duplicate lines are getting removed. (Image attached)


      I could not find a note/similar issue in forums, I am guessing MD04 is not getting initialized right the first time MD04 is executed. Could you please share your thoughts.