Introducción al desarrollo de CDS de SAP Hana
- 1. Introducción a los CDS
- 2. Plantilla de creación de CDS VIEW
-
- 1. Defina una vista simple de una única fuente de datos.
- 2. Defina la vista JOIN de dos fuentes de datos.
- 3. Definir vistas con relaciones asociadas.
- 4. Definir la vista de la relación de asociación de la clase principal.
- 5. Defina la vista de un único parámetro de entrada.
- 6. Defina una entidad de vista de proyección simple
- 7. Definir vistas heredadas
- 8. Definir funciones de tabla con parámetros de entrada.
- 9. Definir entidades abstractas con parámetros de entrada.
- 10. Definir la vista jerárquica entre padres e hijos.
- 11. Defina una entidad de cliente de entrada única
- 3. Plantilla de creación de CDS VIEW ENTITY
1. Introducción a los CDS
Para aprovechar SAP HANA para el desarrollo de aplicaciones, SAP ha introducido un nuevo modelado de datos subyacente llamado Core Data Services (CDS). Con CDS, el modelo de datos se define y utiliza en el servidor de la base de datos, no en el servidor de aplicaciones. CDS también proporciona capacidades más allá de las herramientas tradicionales de modelado de datos, incluido el soporte para modelado conceptual y definiciones de relaciones, funciones integradas y extensiones.
Inicialmente, CDS solo está disponible en los entornos de tiempo de diseño y de ejecución de SAP HANA. Ahora, el concepto CDS también está completamente implementado en SAP NetWeaver para ABAP, lo que permite a los desarrolladores utilizar herramientas de desarrollo ABAP para trabajar en la capa ABAP mientras llevan la ejecución del código a la base de datos.
CDS simplifica y unifica la forma de definir y utilizar los modelos de datos, independientemente de la tecnología de consumo que esté utilizando. Técnicamente, es una mejora de SQL que le proporciona un lenguaje de definición de datos (DDL) para definir tablas/vistas de bases de datos semánticamente ricas (entidades CDS) y tipos definidos por el usuario en su base de datos.
incluir:
- Expresiones utilizadas en cálculos y consultas en el modelo de datos.
- Asociaciones a nivel conceptual, usando expresiones de ruta simples en lugar de uniones en consultas
- Enriquezca las anotaciones del modelo de datos con metadatos adicionales (específicos del dominio). [Los metadatos son "datos que describen datos". Los metadatos pueden describir los elementos o atributos de los datos (nombre, tamaño, tipo de datos, etc.), o su estructura (longitud, campos, columnas de datos), o sus datos relacionados (dónde se encuentra, cómo contactarlos, quién es el propietario). ). ]
Historial de cambios de versión de CDS:
2. Plantilla de creación de CDS VIEW
1. Defina una vista simple de una única fuente de datos.
plantilla:
/*
template 1: Define View
Defines a simple CDS view with one data source.
*/
@AbapCatalog.sqlViewName: '${sql_view_name}'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '${ddl_source_description}'
define view ${ddl_source_name_editable} as select from ${data_source_name} {
${
cursor}
}
Ejemplo (método de escritura estándar CDS):
@AbapCatalog.sqlViewName: 'YV_DEMO01_SCARR'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO01_SCARR'
define view YCDS_DEMO01_SCARR as
select from scarr
{
--key mandt, -- CDS会自动添加
key carrid,
carrname,
url
};
O (escritura SQL tradicional):
@AbapCatalog.sqlViewName: 'YV_DEMO01_SCARR'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO01_SCARR'
define view YCDS_DEMO01_SCARR as
select
--key mandt, -- CDS会自动添加
key carrid,
carrname,
url
from scarr;
Llamada al programa ABAP (Open SQL):
REPORT yz_cds_demo.
SELECT *
FROM ycds_demo01_scarr
INTO TABLE @DATA(itab).
cl_demo_output=>display( itab ).
Convocatoria del programa ABAP (SALV IDA):
REPORT YZ_IDA_DEMO.
CL_SALV_GUI_TABLE_IDA=>CREATE_FOR_CDS_VIEW( iv_cds_view_name = 'YCDS_DEMO01_SCARR' )->FULLSCREEN( )->DISPLAY( ).
Ejemplo (definir alias de campo):
@AbapCatalog.sqlViewName: 'YV_DEMO01_SCARR2'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO01_SCARR2'
define view YCDS_DEMO02_SCARR
(id, name, url) --field alias
as
select from scarr
{
--key mandt,
key carrid as id, --alias
carrname,
url
};
2. Defina la vista JOIN de dos fuentes de datos.
plantilla:
/*
template 2: Define View with Join
Defines a CDS view which combines two data sources using a left outer join.
The join conditions are specified in the on clause.
*/
@AbapCatalog.sqlViewName: '${sql_view_name}'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '${ddl_source_description}'
define view ${ddl_source_name_editable} as select from ${data_source_name}
left outer join ${joined_data_source_name}
on ${data_source_name}.${element_name} = ${joined_data_source_name}.${joined_element_name} {
${
cursor}
}
Ejemplo:
@AbapCatalog.sqlViewName: 'YV_DEMO02_JOIN'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO02_JOIN'
define view YCDS_DEMO02_JOIN as
select from spfli
left outer join scarr
on scarr.carrid = spfli.carrid
{
key spfli.carrid,
key spfli.connid,
scarr.carrname
};
Llamante ABAP:
REPORT yz_cds_demo.
SELECT *
FROM ycds_demo02_join
INTO TABLE @DATA(itab).
cl_demo_output=>display( itab ).
3. Definir vistas con relaciones asociadas.
plantilla:
/*
template 3: Define View with Association
Defines a CDS view with a public association to another data source.
The association can be used in the select list as well as by other CDS views which use this CDS view as a data source.
*/
@AbapCatalog.sqlViewName: '${sql_view_name}'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '${ddl_source_description}'
define view ${ddl_source_name_editable} as select from ${data_source_name}
association [${
1}] to ${target_data_source_name} as ${_association_name}
on $$projection.${element_name} = ${_association_name}.${target_element_name} {
${
cursor}
${_association_name} // Make association public
}
Ejemplo:
@AbapCatalog.sqlViewName: 'YV_DEMO03_ASSOCI'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO03_ASSOCIATION'
define view YCDS_DEMO03_ASSOCIATION as
select from spfli
association to scarr as _scarr
on $projection.carrid = _scarr.carrid
{
key spfli.carrid,
key spfli.connid,
--_scarr.carrname,
_scarr // Make association public, joined on demand
}
Vista previa de datos en HanaStudio:
datos de acceso a HANA:
select * from YV_DEMO03_ASSOCI; -- 未访问关联
Datos de acceso ABAP:
REPORT yz_cds_demo.
PARAMETERS: p_carrid TYPE scarr-carrid.
SELECT carrid, connid, \_scarr-carrname AS flightname "访问关联
FROM YCDS_DEMO03_ASSOCIATION
where carrid = @p_carrid
INTO TABLE @DATA(itab).
cl_demo_output=>display( itab ).
4. Definir la vista de la relación de asociación de la clase principal.
plantilla:
/*
template 4: Define View with To-Parent Association
Defines a CDS view with a specialized association to its parent CDS entity.
Compositions and to-parent associations are used to define the structure of a business object which can be used in the ABAP RESTful Programming Model.
*/
@AbapCatalog.sqlViewName: '${sql_view_name}'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '${ddl_source_description}'
define view ${ddl_source_name_editable} as select from ${data_source_name}
association to parent ${target_data_source_name} as ${_association_name}
on $$projection.${element_name} = ${_association_name}.${target_element_name} {
${
cursor}
${_association_name} // Make association public
}
Ejemplo:
@AbapCatalog.sqlViewName: 'YV_DEMO04_TOPARE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO04_TOPARENT'
define view YCDS_DEMO04_TOPARENT as
select from spfli
association to parent YCDS_DEMO01_SCARR as _scarr
on $projection.carrid = _scarr.id {
key spfli.carrid,
key spfli.connid,
_scarr.id, // Make association public
_scarr
}
5. Defina la vista de un único parámetro de entrada.
plantilla:
/*
template 5: Define View with Parameters
Defines a CDS view with a single input parameter.
The input parameter can be used as an element in the select list
or as an operand in conditional or arithmetic expressions.
*/
@AbapCatalog.sqlViewName: '${sql_view_name}'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '${ddl_source_description}'
define view ${ddl_source_name_editable}
with parameters ${parameter_name} : ${parameter_type}
as select from ${data_source_name} {
${
cursor}
}
Ejemplo:
@AbapCatalog.sqlViewName: 'YV_DEMO05_PARAM'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO05_PARAMETERS'
define view YCDS_DEMO05_PARAMETERS
with parameters p_carrid : s_carr_id
as select from spfli {
key connid,
cityfrom,
cityto
}
where carrid = $parameters.p_carrid;
Diagrama SE11 (no admite la visualización de datos de la tabla):
Diagrama SE16N (se puede ejecutar, es necesario ingresar parámetros):
llamada al programa ABAP:
REPORT yz_cds_demo.
PARAMETERS: p_carrid TYPE scarr-carrid.
SELECT *
FROM ycds_demo05_parameters( p_carrid = @p_carrid )
INTO TABLE @DATA(itab).
cl_demo_output=>display( itab ).
Datos de consulta de HANA:
select * from YV_DEMO05_PARAM('AA') where mandt = 200;
--或者
select * from YV_DEMO05_PARAM( p_carrid => 'AA' ) where mandt = 200;
6. Defina una entidad de vista de proyección simple
Plantilla: utilizada para blindar algunos campos (generalmente utilizada para proteger datos).
/*
template 6: Define Projection View
Defines a simple CDS projection view.
*/
@EndUserText.label: '${ddl_source_description}'
@AccessControl.authorizationCheck: #CHECK
define view entity ${ddl_source_name_editable} as projection on ${data_source_name} {
${
cursor}
}
Ejemplo:
@EndUserText.label: 'CDS_DEMO06_PROJECTION'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity YCDS_DEMO06_PROJECTION
as projection on YCDS_DEMO04_TOPARENT {
key carrid,
key connid
}
7. Definir vistas heredadas
/*
template 7: Extend View
Extends an existing CDS view by adding the specified elements
to the select list of the CDS view using a view enhancement.
*/
@AbapCatalog.sqlViewAppendName: '${sql_view_append_name}'
@EndUserText.label: '${ddl_source_description}'
extend view ${view_name} with ${ddl_source_name_editable} {
${data_source_name}.${element_name}
}
Ejemplo:
@AbapCatalog.sqlViewAppendName: 'YV_DEMO07_EXTEND'
@EndUserText.label: 'CDS_DEMO07_EXTEND'
extend view YCDS_DEMO02_JOIN //原CDS,有三个字段
with YCDS_DEMO07_EXTEND //新CDS,追加一个字段
{
scarr.currcode
}
8. Definir funciones de tabla con parámetros de entrada.
Plantilla: implementación de la FUNCIÓN AMDP.
/*
template 8: Define Table Function with Parameters
Defines the type signature of a client dependent CDS table function with importing parameters.
The CDS table function is implemented in the specified ABAP method.
The CDS table function can be used in Open SQL and as a data source
in other CDS view definitions.
*/
@EndUserText.label: '${ddl_source_description}'
define table function ${ddl_source_name_editable}
with parameters ${parameter_name} : ${parameter_type}
returns {
${client_element_name} : abap.clnt;
${element_name} : ${element_type};
${
cursor}
}
implemented by method ${class_name}=>${method_name};
Ejemplo:
@EndUserText.label: 'ADMP_DEMO_SCARR'
define table function YCDS_ADMP_DEMO_SCARR
with parameters
@Environment.systemField: #CLIENT
p_clnt : abap.clnt
returns {
mandt : abap.clnt;
carrid : s_carr_id;
carrname : s_carrname;
url : s_carrurl;
}
implemented by method ycl_amdp_hdb_demo=>get_scarr_for_cds;
Referencia específica: X-File: Introducción y método de implementación de AMDP en SAP ABAP
9. Definir entidades abstractas con parámetros de entrada.
Plantilla: una entidad CDS que solo describe propiedades de tipo y no crea instancias de ningún objeto de base de datos.
/*
template 9: Define Abastract Entity with Parameters
Defines an abstract CDS entity with a single input parameter.
*/
@EndUserText.label: '${ddl_source_description}'
define abstract entity ${ddl_source_name_editable}
with parameters ${parameter_name} : ${parameter_type} {
${element_name} : ${element_type};
${
cursor}
}
Ejemplo:
@EndUserText.label: 'CDS_DEMO09_ABSTRACT'
define abstract entity YCDS_DEMO09_ABSTRACT
with parameters p_carrid : s_carr_id
{
connid : s_conn_id;
cityfrom : s_from_cit;
cityto : s_to_city;
}
10. Definir la vista jerárquica entre padres e hijos.
plantilla:
/*
template 10: Define Parent Child Hierarchy
Defines a simple CDS parent child hierarchy.
*/
define hierarchy ${ddl_source_name_editable}
as parent child hierarchy (
source ${data_source_name}
child to parent association ${_association_name}
start where ${element_name} = ${
value}
siblings order by ${order_by_element_name}
)
{
${element_name}
${
cursor}
}
Definir tabla jerárquica padre-hijo: YTB_DEMO_HIER
insertar datos:
CREATE COLUMN TABLE "SAPHANADB"."YTB_DEMO_HIER"
(
"MANDT" NVARCHAR(3) DEFAULT '000' NOT NULL ,
"ID" INTEGER CS_INT DEFAULT 0 NOT NULL ,
"PID" INTEGER CS_INT DEFAULT 0 NOT NULL ,
"NAME" NVARCHAR(20) DEFAULT '' NOT NULL ,
CONSTRAINT "YTB_DEMO_HIER~0" PRIMARY KEY ("MANDT","ID")
);
insert into YTB_DEMO_HIER values('200', 1, 0, '图书');
insert into YTB_DEMO_HIER values('200', 2, 1, '教材类');
insert into YTB_DEMO_HIER values('200', 3, 1, '计算机类');
insert into YTB_DEMO_HIER values('200', 4, 3, 'Java');
insert into YTB_DEMO_HIER values('200', 5, 3, '.Net');
insert into YTB_DEMO_HIER values('200', 6, 3, 'SAP');
insert into YTB_DEMO_HIER values('200', 7, 1, '文学类');
insert into YTB_DEMO_HIER values('200', 8, 1, '科幻类');
insert into YTB_DEMO_HIER values('200', 9, 8, '三体');
insert into YTB_DEMO_HIER values('200', 10, 8, '流浪地球');
Definir fuente de datos jerárquica padre-hijo: Vista CDS
@AbapCatalog.sqlViewName: 'YTB_DEMO_HIER_S'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO10_HIERARCHY_SOURCE'
define view YCDS_DEMO10_HIERARCHY_SOURCE
as select from ytb_demo_hier
association[1..1] to YCDS_DEMO10_HIERARCHY_SOURCE as _tree
on $projection.parent= _tree.id
{
_tree,
key id,
pid as parent,
name
}
O: CDS Ver entidad
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO10_HIERARCHY_VIEW'
define view entity YCDS_DEMO10_HIERARCHY_VIEW
as select from ytb_demo_hier
association[1..1] to YCDS_DEMO10_HIERARCHY_VIEW as _tree
on $projection.parent= _tree.id
{
_tree,
key id,
pid as parent,
name
}
Defina la vista de relación jerárquica padre-hijo:
define hierarchy YCDS_DEMO10_HIERARCHY
with parameters
p_id : abap.int4
as parent child hierarchy (
source
--YCDS_DEMO10_HIERARCHY_SOURCE --两者都可以
YCDS_DEMO10_HIERARCHY_VIEW --两者都可以
child to parent association _tree
start where
id = :p_id
siblings order by
id ascending
)
{
id,
parent,
name
}
Vista previa de datos en Hana:
Consulta de datos en Hana SQL:
select * from YTB_DEMO_HIER_S; --sql view,可以访问,有数据
select * from YCDS_DEMO10_HIERARCHY_SOURCE; --cds view,无法访问
select * from YCDS_DEMO10_HIERARCHY_VIEW; --cds view entity,可以访问,没有数据
select * from YCDS_DEMO10_HIERARCHY( p_id => 3 ); --可以访问,没有数据
Acceso en ABAP:
REPORT YZ_CDS_DEMO.
PARAMETERS: p_id type YCDS_DEMO10_HIERARCHY_VIEW-id.
SELECT FROM YCDS_DEMO10_HIERARCHY( p_id = @p_id )
FIELDS id,
parent,
name,
hierarchy_rank,
hierarchy_tree_size,
hierarchy_parent_rank,
hierarchy_level,
hierarchy_is_cycle,
hierarchy_is_orphan,
node_id,
parent_id
INTO TABLE @DATA( cds_result ).
cl_demo_output=>display( cds_result ).
11. Defina una entidad de cliente de entrada única
plantilla:
/*
template 11: Define Custom Entity with Parameters
Defines a custom CDS entity with a single input parameter.
*/
@EndUserText.label: '${ddl_source_description}'
define custom entity ${ddl_source_name_editable}
with parameters ${parameter_name} : ${parameter_type} {
key ${key_element_name} : ${key_element_type};
${element_name} : ${element_type};
${
cursor}
}
Ejemplo:
(1) Definir entidad de cliente de CDS: YCDS_DEMO11_CUSTOM_ENTITY
@ObjectModel.query.implementedBy : 'ABAP:YCL_CUSTOM_ENTITY'
@EndUserText.label: 'CDS_DEMO11_CUSTOM_ENTITY'
define custom entity YCDS_DEMO11_CUSTOM_ENTITY
with parameters p_id : abap.char(3)
{
key carrid : abap.char(3); // Returning fields are mentioned between {} just like ordinary CDS
carrname : abap.char(20); // Returning field set must contain a key or key combination
url : abap.char(255);
}
(2) Definir la clase de implementación ABAP: YCL_CUSTOM_ENTITY
class YCL_CUSTOM_ENTITY definition
public
final
create public .
public section.
interfaces IF_RAP_QUERY_PROVIDER .
protected section.
private section.
ENDCLASS.
CLASS YCL_CUSTOM_ENTITY IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method YCL_CUSTOM_ENTITY->IF_RAP_QUERY_PROVIDER~SELECT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_REQUEST TYPE REF TO IF_RAP_QUERY_REQUEST
* | [--->] IO_RESPONSE TYPE REF TO IF_RAP_QUERY_RESPONSE
* | [!CX!] CX_RAP_QUERY_PROV_NOT_IMPL
* | [!CX!] CX_RAP_QUERY_PROVIDER
* +--------------------------------------------------------------------------------------</SIGNATURE>
method IF_RAP_QUERY_PROVIDER~SELECT.
data:IT_RESULT type table of YCDS_DEMO11_CUSTOM_ENTITY. "Internal table to be returned , easier to handle return if internal table is as same type of our data definition
data: LV_PARAM type STRING."Local variable to fetch and save parameter value
try.
try.
if IO_REQUEST->IS_DATA_REQUESTED( ). "Fetching incoming data
IO_REQUEST->GET_PAGING( ).
data(LT_FILTER_COND) = IO_REQUEST->GET_PARAMETERS( ). "Setting the filter condition, fetching parameter names from data definition
LV_PARAM = value #( LT_FILTER_COND[ PARAMETER_NAME = 'p_id' ]-VALUE optional ). "Fetching the parameter value
"Using the parameter we could do whatever we want , like selecting from a table , doing certain calculations etc
select * from scarr where carrID = @LV_PARAM into CORRESPONDING FIELDS OF TABLE @IT_RESULT.
IO_RESPONSE->SET_TOTAL_NUMBER_OF_RECORDS( LINES( IT_RESULT ) ). "setting the total number of records which will be sent
IO_RESPONSE->SET_DATA( IT_RESULT ). "returning the data as internal table
endif.
catch CX_RAP_QUERY_PROVIDER into data(LX_EXC). "CX_A4C_RAP_QUERY_PROVIDER is now deprecated so use CX_RAP_QUERY_PROVIDER
endtry.
catch CX_RFC_DEST_PROVIDER_ERROR into data(LX_DEST).
endtry.
endmethod.
ENDCLASS.
(3) Definir servicios:
@EndUserText.label: 'SVS_EXPOSE_CUSTOM_ENTITY'
define service YSVS_EXPOSE_CUSTOM_ENTITY {
expose YCDS_DEMO11_CUSTOM_ENTITY;
}
(4) Cómo utilizar el servicio (aún no estudiado)
3. Plantilla de creación de CDS VIEW ENTITY
Notas:
Introducido en NW 7.55 y superiores.
Se puede acceder al objeto CDS View Entity en ABAP, pero no en Hana Sql (sin datos).
12. Defina una entidad de vista simple de una única fuente de datos.
plantilla:
/*
template 12: Defines a simple CDS view entity with one data source.
*/
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: '${ddl_source_description}'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define view entity ${ddl_source_name_editable} as select from ${data_source_name}
{
${data_source_elements}${
cursor}
}
Ejemplo:
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_DEMO12_VIEW_ENTITY'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define view entity YCDS_DEMO12_VIEW_ENTITY as select from scarr
{
key carrid,
carrname,
url
}
13. Definir la entidad de la vista raíz.
plantilla:
/*
template 13: Defines a root CDS view entity with a specialized association to a child CDS entity.
Root nodes, compositions and to-parent associations are used to define the structure of a business object which can be used in the ABAP RESTful programming model.
*/
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: '${ddl_source_description}'
define root view entity ${ddl_source_name_editable} as select from ${data_source_name}
composition of ${target_data_source_name} as ${_association_name}
{
${data_source_elements}${
cursor}
${_association_name} // Make association public
}
14. Defina la entidad de vista asociada con la entidad principal.
plantilla:
/*
template 14: Defines a CDS view entity with a specialized association to its parent CDS entity.
Compositions and to-parent associations are used to define the structure of a business object which can be used in the ABAP RESTful programming model.
*/
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: '${ddl_source_description}'
define view entity ${ddl_source_name_editable} as select from ${data_source_name}
association to parent ${target_data_source_name} as ${_association_name}
on $$projection.${element_name} = ${_association_name}.${target_element_name}
{
${data_source_elements}${
cursor}
${_association_name} // Make association public
}
15. Heredar entidades de vista de proyección
plantilla:
/*
template 15: Extends an existing CDS projection view entity by adding the specified elements to its select list.
*/
extend view entity ${view_name} with {
${base_data_source_name}.${element_name}
}
16. Heredar entidades abstractas
plantilla:
/*
template 16: Extends an abstract CDS entity by adding the specified elements to its select list.
*/
extend abstract entity ${entity_name} with
{
${element_name} : ${element_type};
}
17. Heredar la entidad del cliente
plantilla:
/*
template 17: Extends a custom CDS entity by adding the specified elements to its select list.
*/
extend custom entity ${entity_name} with
{
${element_name} : ${element_type};
}
creado por xlevon el 20230206.
Artículo original, indique la fuente para la reimpresión - Expediente X
Descripción detallada:
ABAP CDS: sintaxis
para trabajar con jerarquías en
entidades personalizadas de ABAP SQL: plataforma de tecnología empresarial (plataforma en la nube SAP)