Working with Bills of Material in S/4HANA

Published by Tobias Hofmann on

8 min read

When you work with SAP changes are good that you come across Bills of Material sooner or later. A common task is to get the list of components that make up a product: you have a BOM and want to know what materials are part of it. It is common that a BOM has several levels and you want to display all items. A standard method to explode a BOM is CS_BOM_EXPL_MAT_V2. This method is available in SAP since R/3 and of course is still available in recent S/4HANA release.

Created 30 years ago, CS_BOM_EXPL_MAT_V2 is the go-to method for exloding a BOM. You might wonder if SAP developed a HANA optimized version of this method. And yes, SAP did: CS_BOM_EXPL_MAT_V2_HANA.

Do not expect too much of a performance boost from the HANA optimized version. SAP Note 2469718 explains why. You’ll benefit from a better performance when a BOM is exploded down several levels and thousands of items. As the note states: “The performance benefits from HANA should ideally be noticeable for complex BOMs and larger BOMs.

CS_BOM_EXPL_MAT_V2_HANA

It can make sense to use the HANA optimized version. Unfortunately, this is not a drop-in replacement. Replacing the “old” method name and add _HANA, without changing any parameter will result in errors. Take the old method call:

Adding _HANA to the function name results in an error. The parameter stb is unknown.

The error occurs because the method signature is not compatible. For CS_BOM_EXPL_MAT_V2 the definition for table stb looks like this:

For CS_BOM_EXPL_MAT_V2_HANA the table part is replaced with CHANGING and the parameter name is ct_stb, not stb.

Another difference is the result. Calling CS_BOM_EXPL_MAT_V2 to get BOM items of the top level using the following parameters:

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
  capid = 'BEST'
  datuv = sy-datum
  mtnrv = matnr
  mehrs = ''
  stlal = '01'
  stpst = '0'

Result:

The result table shows that these items are at the first level (Stufe) and there are ordered (Wegxx). Calling the HANA version using the same parameters.

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2_HANA'
EXPORTING
  capid = 'BEST'
  datuv = sy-datum
  mtnrv = matnr
  mehrs = ''
  stlal = '01'
  stpst = '0'

Nothing is returned. No result list, no items retrieved. The 0 in the second line indicates: no items in the table.

Adjusting the parameters to explode multi-level BOM (mehrs = X).

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2_HANA'
EXPORTING
  capid = 'BEST'
  datuv = sy-datum
  mtnrv = matnr
  mehrs = 'X'
  stlal = '01'
  stpst = '0'

This returns a list, but not the same as with the “old” method.

For level, the table lists entries up to level 3. The result is also not sorted (Wegxx). Limiting the level to the first one, just like with the old method:

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2_HANA'
EXPORTING
  capid = 'BEST'
  datuv = sy-datum
  mtnrv = l_bom_matnr
  mehrs = 'X'
  stlal = '01'
  stpst = '1'

Setting stpst to ‘1’ limits the level to the first one and the result is as with the old method, where the parameter was ‘0’.

The overall result does now match (Stufe 1), the description text is the same. Adjusting the parameters returns a result that matches the one from the old method CS_BOM_EXPL_MAT_V2. The only difference is now that the result is not sorted.

RAP BO

In recent S/4HANA versions there is a RAP BO available to work with BOM. How to find it? Looking at the properties of CS_BOM_EXPL_MAT_V2 reveals that this function is not released, but that there is a successor available: I_BILLOFMATERIALTP_2.

Opening the behavior definition shows that it comes with a Knowledge Transfer Document (KTD), explaining in detail how to use this RAP BO. Including examples.

Documentation for ExplodeBOM, including an example.

What is the RAP BO using to explode a BOM? Is it the HANA optimized version or something else? In the behavior definition I_BillOfMaterialTP_2 you can find the function ExplodeBOM.

define behavior for I_BillOfMaterialTP_2 alias BillOfMaterial

{

use create;

use update;

use delete;

use action AssignPlant;

use function ExplodeBOM;

use function GetWhereUsedMaterial;

[…]

use association _BillOfMaterialItem { create; }

}

The Base Behavior for ExplodeBOM looks like this and clicking on ExplodeBOM allows to navigate to its implementation.

function ExplodeBOM parameter D_BillOfMaterialExplodeBOMP result [0..*] D_BillOfMaterialExplodeBOMR external ‘BillOfMaterialExplodeBOMResult_Type’;

Implementation:

  • Class: CL_BIL_CS_MBOM_API
  • Method: read

When method read is called from the ExplodeBOM function, explode_bom from class CL_BIL_CS_MBIM is called. The read method “knows” that it is called for ExplodeBOM as this is the only way that it_explode_bom is not initial.

  • Class: CL_BIL_CS_MBIM
  • Method: explode_bom

In this method the method CS_BOM_EXPL_MAT_V2 is called to retrieve the values of the provided BOM.

The RAP BO is using method CS_BOM_EXPL_MAT_V2. It is not the HANA optimized version, but the original one.

Observations

A HANA optimized version to explode BOM is available in S/4HANA systems. It is not a drop-in replacement for CS_BOM_EXPL_MAT_V2. Parameters must be adjusted. The output differs and parameters must be changed to get the same result. The result is also not sorted as with the old method. Interestingly, even with not being fully compatible, the HANA version imitates the old version. It is not available as a class and offering BOM operations via methods. The exceptions are not class-based exceptions. It is in a function group and a classic ABAP function. A performance gain is only achieved when exploding a complex and large BOM.

Regarding the RAP BO, not the new HANA optimized version is used to explode a BOM. The benefit of CS_BOM_EXPL_MAT_V2_HANA for large and complex BOM is ignored. That’s interesting as there is a performance gain for those BOM. RAP in S/4HANA is using HANA as a database, so why not use it? At least when you must explode a complex BOM there is benefit in the HANA version, which you won’t benefit from using the RAP BO.

The RAP BO comes with a nice KTD documentation. It allows to understand better how to use it and – even more important – how to call it. What are the parameters, what is the result. Having ready to run sample apps shipped could help in code better apps.

Let the world know

Tobias Hofmann

Doing stuff with SAP since 1998. Open, web, UX, cloud. I am not a Basis guy, but very knowledgeable about Basis stuff, as it's the foundation of everything I do (DevOps). Performance is king, and unit tests is something I actually do. Developing HTML5 apps when HTML5 wasn't around. HCP/SCP user since 2012, NetWeaver since 2002, ABAP since 1998.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.