abap code data services cds in abap adt btp
T Working with ABAP Core Data Services (ABAP CDS)
D Working with ABAP Core Data Services (ABAP CDS)
& Help Working with ABAP Core Data Services (ABAP CDS)
CDS views a data views that also contain annotations(texts, Value helps...), associations(names, cardinality...), and definitions(SQL logic, Joins...) which is used by frameworks like the ABAP RESTful Application programming model (ABAP RAP).
Press ctrl + space to display the value help options, and select DDLS/DF (Data Definition) for CDS views
CDS view data definition
See /DMO/I_Connection example demo CDS view below, it shows the built in select from the main table and INNER joins to other tables /DMO/I_Carrier.
Notice the "as" values as these are the values that you need when referencing the values i.e. /DMO/I_Connection is referenced using connection and /DMO/I_Carrier is referenced using _Airline etc
ABAP code to select from CDS view
A select from a CDS view is the same as directly from the table but remember to use the as values assigned within the CDS view rathe than the actual fiald names of the table.
Also note a CDS view can select from another CDS view
CLASS zcl_mycds DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_mycds IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA: airport_from_id TYPE /dmo/airport_from_id,
airport_to_id TYPE /dmo/airport_to_id,
carrier_id TYPE /dmo/carrier_name,
carrier_name TYPE /dmo/carrier_name.
SELECT SINGLE
FROM /DMO/I_Connection
FIELDS DepartureAirport, DestinationAirport, \_Airline-Name
WHERE AirlineID = 'SQ'
AND ConnectionID = '0011'
INTO ( @airport_from_id, @airport_to_id, @carrier_name ).
out->write( | From:{ airport_from_id } To:{ airport_to_id } - { carrier_name }| ).
ENDMETHOD.
ENDCLASS.