4

Create parametrized custom entity select from dynamic table in S/4 HANA ABAP

 1 year ago
source link: https://blogs.sap.com/2023/04/06/create-parametrized-custom-entity-select-from-dynamic-table-in-s-4-hana-abap/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
April 6, 2023 1 minute read

Create parametrized custom entity select from dynamic table in S/4 HANA ABAP

Introduction:

During ABAP coding in many occasion we need to create dynamic table. Similar situation can be handled during creation of custom entity by using annotation @ObjectModel.dynamic

Use case:

In SAP S/4HANA create a custom entity that selects data from a dynamic table based on a parameter using the ABAP CDS framework

Steps:

  • Define a data type for the dynamic table using the ABAP CDS TABLE OF statement.
  • Use the @ObjectModel.dynamic annotation to specify that the table is dynamic.
  • Define the necessary fields for the dynamic table using the ABAP CDS LIKE statement.
  • In the custom entity data model, define a parameter that specifies the name of the dynamic table.
  • In the custom entity data model, define a field using the data type for the dynamic table, and use the @ObjectModel.readOnly annotation to indicate that the field is read-only.

Below Coding technique can be followed ,

@EndUserText.label: 'Test Custom Entity'

define root view entity ZCustomEntity

with parameters p_dynamic_table : abap.dynpalpha

as select from (p_dynamic_table)

{

key  key_field : abap.int,

dynamic_table : @ObjectModel.dynamic TABLE OF ZDynamicType

@ObjectModel.readOnly

}

define type ZDynamicType {

field1 : abap.string,

field2 : abap.int,

}

Summary :

In the example above, the p_dynamic_table parameter specifies the name of the dynamic table to select data from. The custom entity data model includes a field named dynamic_table, which is defined as a dynamic internal table of ZDynamicType. The @ObjectModel.readOnly annotation indicates that the field is read-only, meaning that it cannot be modified through the custom entity.

Hopefully this blog post will help you. I look forward to your comments and feedback.

Thanks for reading this article !

Regards,

Subhamoy Bhaumik


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK