Saturday, 27 April 2019

Fiori elements utilizing CDS with Virtual Elements

This Blog is about utilizing the CDS’s virtual elements feature which as exposed as ODATA Via SADL (direct in SEGW / with ODATA Publish true annotations). This ODATA can be further consumed by Fiori Elements based application.

Also following SAP standard documents are helpful for understanding of CDS with Virtual elements.

Business Scenario


Standard Consumption CDS is generating the Fiori elements application. There might be business requirement for field which required custom ABAP Logic for the calculation.

So good news is that we can use the CDS with virtual element and can write the complex custom Logic utilizing the ABAP Resource for the calculation.

Virtual elements can be implemented with Calculated value of Fields, Filtering of calculated values, Sorting of the Calculated value.

Technical Explanation


◈ Create the consumption CDS with UI and Virtual elements annotations.

◈ Give the Place holder for the Virtual elements, data type of the virtual elements must be defined.

◈ Create the normal ABAP class which implement the interface IF_SADL_EXIT_CALC_ELEMENT_READ.

◈ Implement both the methods GET_CALCULATE_INFO and CALCULATE.

◈ CDS can be exposed as ODATA or SEGW reference data source.

◈ Generate the Fiori elements-based application which show the calculated columns.

SAP ABAP Certifications, SAP ABAP Tutorials and Materials, SAP ABAP Guides, SAP ABAP Learning

Detailed explanation

Let’s implement ABAP Code exit for Virtual elements.

Example – concatenate Material, Plant, Storage location separate by ‘-‘.

(This is just for demo purpose we can implement with CDS concat functions also)

◈ Create the CDS with Virtual element and with virtual elements specific annotations below

SAP ABAP Certifications, SAP ABAP Tutorials and Materials, SAP ABAP Guides, SAP ABAP Learning

◈ We have given Place holder for the virtual element ‘TestExit’ with data type as abap.char(40)

◈ Create the class with implementing interface IF_SADL_EXIT_CALC_ELEMENT_READ.

SAP ABAP Certifications, SAP ABAP Tutorials and Materials, SAP ABAP Guides, SAP ABAP Learning

◈ Implement the below method

1. Method GET_CALCULATION_INFO is used to provide the list of fields which is required for the calculation.
2. Method CALCULATE is actual method where we implement the custom logic.

SAP ABAP Certifications, SAP ABAP Tutorials and Materials, SAP ABAP Guides, SAP ABAP Learning

◈ For the demo purpose, GET_CALCULATION_INFO is with blank implementation.

◈ Implement the CALCULATE method utilizing ABAP resource (i.e. Function Module etc)

SAP ABAP Certifications, SAP ABAP Tutorials and Materials, SAP ABAP Guides, SAP ABAP Learning

◈ Register the Gateway Service generated by CDS and check the output in the Gateway Client

◈ We can see the calculated field in the response

SAP ABAP Certifications, SAP ABAP Tutorials and Materials, SAP ABAP Guides, SAP ABAP Learning

◈ We can utilize the same CDS in Fiori Elements based application and Field with virtual element will be populated.

◈ Develop the Fiori Elements based List Report.

Output

SAP ABAP Certifications, SAP ABAP Tutorials and Materials, SAP ABAP Guides, SAP ABAP Learning

No comments:

Post a Comment