Real-Time Example of Using CDS View with Function Module in SAP ABAP - Sap 4 All

Latest

Please enter your email and get the updates in your inbox.

Wednesday, 19 July 2023

Real-Time Example of Using CDS View with Function Module in SAP ABAP

 Let's consider a real-time example where we want to create a CDS view that retrieves material data from an external system using an RFC-enabled function module. The function module receives a material number as input and returns the corresponding material description and quantity from the external system.

  1. Create an ABAP Function Module:

    • Create an ABAP function module named Z_GET_MATERIAL_DATA that accepts a material number as input and returns the material description and quantity from the external system.
  2. Register Function Module as RFC-enabled:

    • Ensure that the function module Z_GET_MATERIAL_DATA is registered as RFC-enabled by setting the corresponding attributes in the function module's properties.
  3. Create CDS View Consuming Function Module:

    • Create a CDS view named Z_Material_Data_View that consumes the data from the function module Z_GET_MATERIAL_DATA.
abap
@AbapCatalog.sqlViewName: 'Z_MATERIAL_DATA_VIEW' @AccessControl #CHECK define view Z_Material_Data_View as select from dummy as d left outer join @FunctionName: 'Z_GET_MATERIAL_DATA' @Environment.systemField: #CLIENT client, @DefaultLanguage: 'EN' @Search.defaultSearchElement: true material, materialDescription, quantity from dummy as d;

In this example, the CDS view Z_Material_Data_View uses an Open SQL expression with the @FunctionName annotation to call the RFC-enabled function module Z_GET_MATERIAL_DATA. The input parameter, material, will be passed from the CDS view to the function module. The result of the function module will be joined with the dummy table to form the output of the CDS view.

  1. Activate and Test the CDS View:
    • Activate the CDS view Z_Material_Data_View and test it by running a query against the CDS view in the ABAP Development Tools or SAP GUI.

When you run a query against the CDS view, it will internally call the function module Z_GET_MATERIAL_DATA with the specified material number as input, retrieve the material description and quantity from the external system, and present the result as output from the CDS view.

Please note that the exact implementation of the function module and CDS view may vary based on your specific business requirements and the data structure from the external system. Additionally, it's crucial to ensure that proper authorization and error handling mechanisms are in place while calling the RFC-enabled function module.

No comments:

Post a Comment