quinta-feira, 9 de maio de 2019

S/4 HANA : MSEG or MATDOC Where is my data going?

       
In S/4 HANA, there is always a confusion about the tables MSEG and MATDOC. This blog is to explain where exactly your data is going and how to understand the link between MSEG and MATDOC tables.

For example, in the below case when you check the number of entries of MSEG in SE16N, it shows 55 entries.


Where as if you check the same in MATDOC, it shows the same 55 records. So which one is real?



Lets try a different approach. Lets try to check the correct entries through a database query using transaction DBACOCKPIT which directly queries the database. First check in MATDOC as below.

Perfect!. it shows 55 as expected when you run a straight forward select query from MATDOC at database level.
Lets try to run the same thing for MSEG now and I am sure you are expecting 55 here as well. Right?

Oops!. It shows 0. So it is clear that we don’t have any entries in MSEG in HANA database. It just simply points towards MATDOC internally when you run through SE16N. How is it doing & how do we know that?
This is an important screenshot taken from transaction SE11. Go to Extras menu for table MSEG and you will see these details.
SAP has introduced a concept called ‘Replacement Object’ where a CDS view name is mentioned. Earlier, this was called as Proxy object till 1709 version and it looks like SAP has renamed it as ‘Replacement Object’ to avoid any confusion because of the word ‘Proxy’.


For MSEG, NSDM_E_MSEG is shown as replacement object. So when you access MSEG either in SE16N or in your custom program, SAP routes the logic through this CDS view which gets the data from MATDOC. You can see the logic in the below screenshot.
Give CDS View NSDM_E_MSEG in view name in SE11. You will get the below details which gives the DDL definition name and the DDL SQL view name (NSDM_V_MSEG) also.

View NSDM_V_MSEG in SE11 clearly shows that it gets the data from MATDOC.
 
Last part in the DDL definition talks about any custom fields or appended fields and how this is handled in these replacement objects. You need to use Extend view and append the custom fields in Eclipse editor.

Please note that you don’t have the replacement object available for all replaced tables in S/4 HANA. This concept is different for each table and above explained steps are specific to MSEG/MATDOC. Replacement object/Proxy object concept was mainly introduced to avoid confusions/changes in custom programs which deals with MSEG. So if a custom program does a select from MSEG, it will still work similar to what we saw in SE16N screenshot above.
Hope this blog helped to clarify some of the doubts related to MSEG/MATDOC tables.


Source: https://blogs.sap.com/2019/05/09/s4-hana-mseg-or-matdoc-where-is-my-data-going/?

2 comentários: