Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Subhamoy
Explorer
3,077
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
2 Comments
Labels in this area