Monday 25 October 2021

Display Short Material Product Hierarchy Level Keys with ABAP CDS Views

Material Product Hierarchy displays long levels key based on T179 table, but users accustomed to see individual level short keys the ways they maintained in MM02 transaction. Take Material Product Hierarchy to a next level addressing user requirements.

Below is how users assign hierarchy levels are maintained in MM02 transaction

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

Users expect to see the same short Material Product Hierarchy level keys in ABAP CDS view queries. Unfortunately, it is not the case. Hierarchy level keys are displayed the way they are stored in T179 table

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

This blog explains how to display short Material Product Hierarchy level keys as shown below

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

All it takes is to make some minor changes to I_ProductHierarchyNode CDS view casting Product Hierarchy Node using custom ZPRODH data element

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

ZPRODH data element created on top of ZPRODH domain which is using ZPH conversion routine.

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

The trick is in ZPH conversion routine. What conversion routine is doing is removing preceding hierarchy levels during output.

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

ZPH conversion routine is defined with using two function modules CONVERSION_EXIT_ZPH_INPUT and CONVERSION_EXIT_ZPH_OUTPUT. Output routing is doing the trick

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

Input routing is not doing much

ABAP CDS Views, SAP ABAP Exam Prep, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Jobs

CONVERSION_EXIT_ZPH_OUTPUT can be downloaded from GitHub

Source: sap.com

No comments:

Post a Comment