OPEN SQL Statement To Access The CDS View

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

************************************************

* OPEN SQL statement to access the CDS View *


************************************************
SELECT * FROM ZCDS_DEMO_EXAMPLE1 INTO TABLE @DATA(lt_data).

************************************************
* CDS View in ABAP ALV Report *
************************************************
DATA: lo_alv TYPE REF TO if_salv_gui_table_ida.

cl_salv_gui_table_ida=>create(
EXPORTING
iv_table_name = 'ZV_DEMO_01' "Name of CDS View name
RECEIVING
ro_alv_gui_table_ida = lo_alv
).
* CATCH cx_salv_db_connection. "
* CATCH cx_salv_db_table_not_supported. "
* CATCH cx_salv_ida_contract_violation. "

* Display ALV
lo_alv->FULLSCREEN( )->display( )

5. Lets look at the code, we have used CDS view name created in our previous
tutorial to the ALV with IDA class CL_SALV_GUI_TABLE_IDA as a data source to the
ALV. Save and activate the ABAP program.

CDS View Association is nothing but, establishing the relationship between these 2 CDS
views on a common field/expression to get the order header and its line item information.

Association with cardinality


Now lets try to add the cardinality on the target cds view which is defined with
association with this syntax [min..max]

Below are the rules for min and max values.

 max cannot be 0.
 An asterisk * for max means any number of rows.
 min can be omitted (set to 0 if omitted).
 min cannot be *.
 When an association is used in a WHERE condition, 1 must be specified
for max.

Association ON condition rules


When specifying the ON condition with association, following rules are applied.

 The fields specified in the ON condition should be included in the SELECT


list. In our example, the field VBELN is specified in ON condition and
SELECT list.
 The fields of source data source can be prefixed with $projection instead
of data source name.

 define view ZCDS_SALESORDER_HDR

 as select from vbak

 association [1..*] to ZCDS_SALESORDER_ITM as _OrderItems

 on $projection.vbeln = _OrderItems.vbeln

{ ..... }
Association as join type
The association defined in an ABAP CDS view will be converted to join type at run-
time. By default the join type is LEFT OUTER JOIN.

The below CDS view will result in LEFT OUTER JOIN when executed.

o achieve INNER JOIN, you need to define the attribute in the path expression like
below.

@AbapCatalog.sqlViewName: 'ZV_ORD_HDR'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Order Header Information'

define view ZCDS_SALESORDER_HDR

as select from vbak

association [1..*] to ZCDS_SALESORDER_ITM as _OrderItems

on $projection.vbeln = _OrderItems.vbeln

key vbeln,

erdat,

vbtyp,

auart,

netwr,
waerk,

_OrderItems[inner].matnr

Usage of CDS view with association in ABAP


using OpenSQL

CL_SALV_GUI_TABLE_IDA

CREATE Static Method Public Create ALV with integrated data access (IDA)

CREATE_FOR_CDS_VIEW Static Method Public Create 'ALV with IDA' for Core Data

Services(CDS)

DB_CAPABILITIESStatic Method Public Capabilities supported by current DB

CREATE_FOR_ABQI Static Method Private

We can access the CDS view which has associations defined in ABAP program using
Open SQL statement using the path expressions like below
DATA(is_supported) = cl_abap_dbfeatures=>use_features(
requested_features = VALUE
#( ( cl_abap_dbfeatures=>views_with_parameters ) ) ).
IF is_supported IS NOT INITIAL.
SELECT *
FROM zcds_salesorder_hdr
INTO TABLE @DATA(lt_data).
ENDIF.

CDS Annotations
The following list summarizes all SAP annotations of the Data Definition Language (DDL) of ABAP
CDS. SAP CDS annotations are evaluated by SAP frameworks and can be either ABAP annotations
or framework-specific annotations.

ABAP CDS - ABAP Annotations


CDS annotations that are evaluated by ABAP runtime:

 AbapCatalog Annotations

 AccessControl Annotations

 ClientDependent Annotations

 DataAging Annotations

 EndUserText Annotations

 Environment Annotations

 MappingRole Annotations

 Metadata Annotations

 Semantics Annotations

Framework-Specific Annotations

CDS annotations that (as a rule) are evaluated during runtime by specific frameworks such
as SADL, BOPF, Analytics, or Enterprise Search:

 Analytics Annotations

 AnalyticsDetails Annotations

 Consumption Annotations

 DefaultAggregation Annotations

 EnterpriseSearch Annotations

 Hierarchy Annotations

 ObjectModel Annotations

 OData Annotations

 Search Annotations
 Semantics Annotations

 UI Annotations

 VDM Annotations

You might also like