terça-feira, 11 de junho de 2019

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

Very
A long time ago I wrote the blog https://blogs.sap.com/2014/11/20/how-to-analyze-transaction-md04-in-debug/ 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
Source: https://blogs.sap.com/2019/06/07/s4hana-how-to-analyze-transaction-md04-in-debug/

Nenhum comentário:

Postar um comentário