0% found this document useful (0 votes)
591 views

Cds Views Examples

Uploaded by

parul_kapoor92
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
591 views

Cds Views Examples

Uploaded by

parul_kapoor92
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

1) Aggregate Functions:

@AbapCatalog.sqlViewName: 'ZAGGRVIEW'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_CDS_AGGREGATE_EXPRESSIONS'

define view Z_Cds_Aggregate_Expressions as select from sflight {

key sflight.carrid,
key sflight.connid,
sum( price ) as Total_Amount,
sflight.currency,
count( *) as Lines
}

group by carrid, connid, currency

2) Arithmetic Expressions:

@AbapCatalog.sqlViewName: 'Z_SQL_ARTHI'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_CDS_ARITHMATIC_EXPRESSIONS'
define view Z_Cds_Arithmatic_Expressions as select from sflight as s
{
key s.carrid,
key s.connid,
key s.fldate,
s.price,
s.currency,
(s.seatsmax)-(s.seatsocc) as Avai_Seats_in_Economy_Class,
(s.seatsmax_b)-(s.seatsocc_b) as Avai_Seats_in_Business_Class,
s.seatsmax_f - s.seatsocc_f as Avai_Seats_in_First_Class
}

3) Associations:

First View:

@AbapCatalog.sqlViewName: 'ZVBAP'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_ASSOCIATION_VBAP'
define view Z_Association_Vbap as select from vbap
left outer join makt on vbap.matnr = makt.matnr
{
vbeln,
posnr,
vbap.matnr,
makt.maktx,
zwert,
zmeng
}

SecondView:

@AbapCatalog.sqlViewName: 'ZVBAK'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_ASSOCIATION_VBAK'

define view Z_Association_Vbak as select from vbak

association[1..1] to Z_Association_Vbap as _OrderItems

on $projection.vbeln = _OrderItems.vbeln //instead of using source table use


projection

{
key vbeln,
erdat,
vbtyp,
auart,
vkorg,
vtweg,
spart,
netwr,
waerk,
_OrderItems[inner].matnr,
_OrderItems[inner].maktx
}

4) Basic view and Consumption views:

Basic View:

@AbapCatalog.sqlViewName: 'Z_SQL_Basic'
@ClientDependent : true
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType : #BASIC
@EndUserText.label: 'CDS View demo'
@Analytics.dataCategory: #CUBE
define view Z_Cds_Basic as select from sflight {

key sflight.carrid ,
key sflight.connid,
key sflight.fldate,
@DefaultAggregation: #SUM
sflight.paymentsum
}

Consumption View:
@AbapCatalog.sqlViewName: 'Z_sql_Consum'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_ALLOWED
@Analytics.dataExtraction.enabled: true
@VDM.viewType: #CONSUMPTION
@Analytics.query: true
@EndUserText.label: 'CDS View demo'
@OData.publish: true
define view Z_Cds_Consumption as select from Z_Cds_Basic
{
Z_Cds_Basic.carrid,
Z_Cds_Basic.connid,
Z_Cds_Basic.fldate,
Z_Cds_Basic.paymentsum
}

5) Currency Conversions:

@AbapCatalog.sqlViewName: 'Z_SQL_Currency'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_CDS_CURRENCY_CONVERSION'
define view Z_Cds_Currency_Conversion with parameters p_curr: abap.cuky(5),
p_dat:abap.dats
as select from sflight as s
{
key s.carrid,
key s.connid,
key s.fldate,
currency_conversion( amount => s.price,
source_currency => s.currency,
target_currency => :p_curr,
exchange_rate_date => :p_dat ) as local_amount,

:p_curr as local_currency

where carrid = 'AA'

6) String Functions:

@AbapCatalog.sqlViewName: 'ZSTRINGCDS'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_CDS_STRING_FUNCTIONS'
define view Z_Cds_String_Functions as select from kna1 {

// CONCATENATE name1 & name2


CONCAT( kna1.name1, kna1.name2 ) as full_name,

// CONCATENATE name1 & name2 with 4 space


CONCAT_WITH_SPACE( kna1.name1, kna1.name2, 4 ) as full_name_space,

// To get substring for a given string


SUBSTRING( kna1.name1, 2, 10) as name,

// To get length for a given string


LENGTH( kna1.name1 ) as name_length,

//LEFT(arg, len) – It returns the left-side part of the string which is passed
as argument arg of length len.

//RIGHT(arg, len) – It returns the right-side part of the string which is passed
as argument arg of length len.

//Note: Trailing blanks are ignored

// To get length for a given string


LEFT( kna1.name1, 3) as name_left,
RIGHT( kna1.name1, 3) as name_right,
kna1.name1,

//LTRIM(arg, char) – It removes the trailing blanks and leading character


which matches the parameter char.

//RTRIM(arg, char) – It removes the trailing blanks and trailing character which
matches the parameter char.

// Removes the trailing blanks and character


LTRIM( kna1.name1, 'L') as name_lt,
RTRIM( kna1.name1, 'T') as name_rt
}

7) Date Functions:

@AbapCatalog.sqlViewName: 'ZDATSVIEW'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_CDS_DATE_FUNCTIONS'
define view Z_Cds_Date_Functions

with parameters p_from_date:abap.dats

as select from vbak

{
vbak.vbeln,
vbak.audat,
vbak.vdatu,
vbak.vkorg,
// returns 1 - Valid Date
// returns 0 - Invalid Date
DATS_IS_VALID(:p_from_date) as from_date,

//The date function DATS_DAYS_BETWEEN calculates the no of days


//between the two specified dates, date1 and date2.

DATS_DAYS_BETWEEN(vdatu,audat) as no_of_days,

//The date DATS_ADD_DAYS adds days to the specified date date.


//days should be of type INT4, both negative and positive value for days is
allowed.

DATS_ADD_DAYS(vdatu, 10, 'NULL') as option2, //add 10 days


DATS_ADD_DAYS(vdatu, -10, 'NULL') as option1, //substract 10 days
DATS_ADD_DAYS(vdatu, 5, 'FAIL') as option3,
DATS_ADD_DAYS(vdatu, 4, 'INITIAL') as option4,
DATS_ADD_DAYS(vdatu, 2, 'UNCHANGED') as option5,

//DATS_ADD_MONTHS(date, months, on_error),The date function DATS_ADD_MONTHS add


months months to the specified date date.

DATS_ADD_MONTHS(vdatu, 10, 'NULL') as option6, //add 10 months


DATS_ADD_MONTHS(vdatu, -10, 'NULL') as option7, //substract 10 months
DATS_ADD_MONTHS(vdatu, 5, 'FAIL') as option8,
DATS_ADD_MONTHS(vdatu, 4, 'INITIAL') as option9,
DATS_ADD_MONTHS(vdatu, 2, 'UNCHANGED') as option10

8) Joins :

Inner Join:

@AbapCatalog.sqlViewName: 'zinnerdemo'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Inner Join Demo'
define view Z_Innerjoin_Demo as
select from sflight
inner join scarr on sflight.carrid = scarr.carrid
{
sflight.carrid,
sflight.fldate,
scarr.carrname
}

Calling CDS view from report:

*&---------------------------------------------------------------------*
*& Report z_extension_report
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_extension_report.

SELECT * FROM Z_Innerjoin_Demo INTO TABLE @DATA(it_data).

cl_demo_output=>display_data(
EXPORTING
value = it_data
name = 'Demo: CDS View Enhancement'
).

Left Outer Join:

@AbapCatalog.sqlViewName: 'zleftouterdemo'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Left Outer Join Demo'
define view Z_Leftouterjoin_Demo as
select from sflight
left outer join scarr on sflight.carrid = scarr.carrid
{
sflight.carrid,
sflight.fldate,
scarr.carrname
}

9) Extending the view:

@AbapCatalog.sqlViewAppendName: 'zextendview'
@EndUserText.label: 'Z_CDS_EXTEND_VIEW'

extend view Z_Innerjoin_Demo with Z_Cds_Extend_View {

sflight.price as Price,

case

when

sflight.carrid = 'AA'

then 'Dummy Column'

else 'Original Column'

end as NewExtendedColumn

10) Parameters Demo:

@AbapCatalog.sqlViewName: 'ZPARAMSDEMO'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_CDS_PARAMETERS_DEMO'

define view Z_Cds_Parameters_Demo


with parameters p_mat_group :matkl //MATKL - DATATYPE

as select from vbap

inner join mara on vbap.matnr = mara.matnr

vbap.vbeln as SalesDocNumbr,
vbap.matkl as MaterialType,
mara.matnr as MaterialNo,
mara.meins as UOM,
//parameters as output param
:p_mat_group as MaterialGroup,

// Parameter used in CASE distinction

case :p_mat_group
when 'ZYOUTH' then 'Y'
else
'N'
end as MatGroup

where vbap.matkl = :p_mat_group; //$parameters.p_mat_group ; VBAP.MATKL -


TABLENAME-FIELDNAME

calling cds view from Report:

*&---------------------------------------------------------------------*
*& Report z_report_parameters
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_report_parameters.

PARAMETERS: p_MATKL type VBAP-MATKL.

START-OF-SELECTION.

select * FROM Z_Cds_Parameters_Demo( p_mat_group = @p_MATKL ) into TABLE


@DATA(lt_VBAP).

cl_demo_output=>display_data(
EXPORTING
value = lt_VBAP
name = 'Sales order CDS View with Input Parameters' ).

11) Table Function:

CDS view:

@EndUserText.label: 'Z_CDS_TABLE_FUNCTIONS'

define table function Z_Cds_Table_Functions


with parameters @Environment.systemField: #CLIENT
clnt:abap.clnt, carrid : s_carr_id
returns {
client : s_mandt;
carrname : s_carrname;
connid : s_conn_id;
cityfrom : s_from_cit;
cityto : s_to_city;

implemented by method ZCL_EXAMPLE_AMDP=>GET_FLIGHTS;

class for table function:

class ZCL_EXAMPLE_AMDP definition public.


public section.
interfaces IF_AMDP_MARKER_HDB.
class-methods get_flights for table function Z_Cds_Table_Functions.

protected section.
private section.
endclass.

class ZCL_EXAMPLE_AMDP implementation.

method get_flights by database function


for hdb
language sqlscript
options read-only
using scarr spfli.
RETURN SELECT sc.mandt as client,
sc.carrname, sp.connid, sp.cityfrom, sp.cityto
FROM scarr AS sc
INNER JOIN spfli AS sp ON sc.mandt = sp.mandt AND sc.carrid =
sp.carrid
WHERE sp.mandt = :clnt AND
sp.carrid = :carrid
ORDER BY sc.mandt, sc.carrname, sp.connid;
endmethod.

endclass.

12) Semantics Demo:

@AbapCatalog.sqlViewName: 'Z_SEMANTIC_DEMO'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_SEMANTICS_DEMO_CDS'
define view Z_Semantics_Demo_Cds as select from scustom
{ id,
@Semantics.name.fullName
name,
@Semantics.name.prefix
form,
@Semantics.address.street
street,
@Semantics.address.postBox
postbox,
@Semantics.address.zipCode
postcode,
@Semantics.address.city
city,
@Semantics.address.country
country,
@Semantics.address.subRegion
region,
@Semantics.contact.type
custtype,
@Semantics.language
langu,
@Semantics.eMail.address
email }

13) Dimensions and Measures Example:

@AbapCatalog.sqlViewName: 'Z_Dim_Measure'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Dimesions and Measures demo'
@OData.publish: true
define view Z_Dim_Measures as select from sflight {

//KEY FIELDS

key sflight.carrid as AirlineCode,


key sflight.connid as ConnectionId,
key sflight.fldate as FlightDate,

//Dimensions
sflight.planetype as AircraftType,
sflight.mandt as Client,
sflight.price as Airfare,

//Measure
@DefaultAggregation: #SUM
sflight.paymentsum as TotalBookings

14) Composite and Consumption Views:

zprd_query is the z-table


Composite View :

@EndUserText.label: 'Jerry cube view'


@Analytics.dataCategory: #CUBE
@VDM.viewType: #COMPOSITE
@AccessControl.authorizationCheck:#CHECK
@AbapCatalog.sqlViewName: 'zprdcube'
define view Z_Cds_Composite_Table as select from zprd_query{
key zprd_query.prod_id,
zprd_query.prod_text,
@DefaultAggregation: #MAX
zprd_query.quantity
}

Consumption View:

@EndUserText.label: 'Jerry query verification'


@VDM.viewType: #CONSUMPTION
@Analytics.query: true
@AccessControl.authorizationCheck:#NOT_ALLOWED
@AbapCatalog.sqlViewName: 'zprdquery'
@OData.publish: true
define view Z_Cds_Consumption_Table as select from Z_Cds_Composite_Table {
key Z_Cds_Composite_Table.prod_id,
Z_Cds_Composite_Table.prod_text,
@DefaultAggregation: #MAX
Z_Cds_Composite_Table.quantity
}

Run RSRT T-code and enter Sql view name appended with 2Czprdquery and execute .

Output:
15) Access control:

CDS VIEW:

@AbapCatalog.sqlViewName: 'Z_SQL_Acl'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck:#CHECK
@EndUserText.label: 'Z_CDS_ACL'
define view Z_Cds_Acl as select from scarr {

key scarr.carrid,
scarr.carrname,
scarr.currcode,
scarr.url

Access Control:

@EndUserText.label: 'Flight Autorization Check'


@MappingRole: true
define role ZSCARR_ROLE {
grant select on Z_Cds_Acl
where ( CARRID ) =
aspect pfcg_auth ( S_CARRID,
CARRID,
actvt = '03' );
}

16) Basic view and Consumption View:

Basic view:

@AbapCatalog.sqlViewName: 'Z_SQL_Basic'
@ClientDependent : true
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType : #BASIC
@EndUserText.label: 'CDS View demo'
@Analytics.dataCategory: #CUBE
define view Z_Cds_Basic as select from sflight {

key sflight.carrid ,
key sflight.connid,
key sflight.fldate,
@DefaultAggregation: #SUM
sflight.paymentsum

Consumption View:

@AbapCatalog.sqlViewName: 'Z_sql_Consum'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_ALLOWED
@Analytics.dataExtraction.enabled: true
@VDM.viewType: #CONSUMPTION
@Analytics.query: true
@EndUserText.label: 'CDS View demo'
@OData.publish: true
define view Z_Cds_Consumption as select from Z_Cds_Basic
{
Z_Cds_Basic.carrid,
Z_Cds_Basic.connid,
Z_Cds_Basic.fldate,
Z_Cds_Basic.paymentsum
}

Run RSRT t-code and enter SQL view name 2CZ_sql_Consum


Execute:

17) Consuming CDS view from Floor plan application:

CDS view:

@AbapCatalog.sqlViewName: 'ZSQLSCARR'
@ClientDependent: true
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Z_CDS_FPM_APP'
@VDM.viewType: #BASIC
@Analytics.dataCategory: #DIMENSION
@Analytics.dataExtraction.enabled: true
@ObjectModel.representativeKey: 'Airline'
define view Z_Cds_Fpm_App as select from scarr {

key scarr.carrid as Airline,


@Semantics.text: true
scarr.carrname as AirName,
@Semantics.currencyCode: true
scarr.currcode as AirCurrency,
scarr.url as AirlineUrl

Run FPM_WB T-code to open floor plan work bench.


Select the option.

In the next screen, provide Webdynpro application name, Description, Application


Configuration and Floor plan Configuration.

Click on next button.


In the next screen, select business entity as Core Data Services and enter cds
view name as Business entity.

Click on next button.

If any associations are defined select associations and click on join check box to
view the fields which are mentioned in the associated table.

Click on Next button.


Click on add chart button to show details in the chart or else click on preview
button.

Click on search button to view results:

18) To show association details in FPM:

CDS VIEW:
@AbapCatalog.sqlViewName: 'Z_SQL_FPM'

@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_CDS_FPM_ASSOCIATION_APP'
@VDM.viewType: #BASIC
@Analytics.dataCategory: #DIMENSION
@Analytics.dataExtraction.enabled: true
@ObjectModel.representativeKey: 'AirConnection'
define view Z_Cds_Fpm_Association_App as select from spfli
association[0..1] to Z_Cds_Fpm_App as _Scarr
on $projection.Airline = _Scarr.Airline

@ObjectModel.foreignKey.association: '_Scarr'
key spfli.carrid as Airline,
key spfli.connid as AirConnection,
spfli.countryfr as DepatureCountry,
spfli.countryto as ArrivalCountry,
@Semantics.quantity.unitOfMeasure: 'AirDistanceUnit'
@DefaultAggregation: #SUM
spfli.distance as AirDistance,
@Semantics.unitOfMeasure: true
spfli.distid as AirDistanceUnit,
_Scarr

19) Basic view, Composite view and Consumption view example with Association
and other annotations example:

First BASIC view:

@AbapCatalog.sqlViewName: 'ZVWSCARR'
@ClientDependent: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Airlline'
@VDM.viewType: #BASIC
@Analytics.dataCategory: #DIMENSION
@Analytics.dataExtraction.enabled: true
@ObjectModel.representativeKey: 'Airline'
define view ZDemo_Scarr as select from scarr
{
key scarr.carrid as Airline,
@Semantics.text: true
scarr.carrname as AirName,
@Semantics.currencyCode: true
scarr.currcode as AirCurrency,
scarr.url as AirlineUrl
}

Second BASIC view:


@AbapCatalog.sqlViewName: 'ZVWSPFLI'
@ClientDependent: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Airline Connection'
@Analytics.dataCategory: #DIMENSION
@Analytics.dataExtraction.enabled: true
@VDM.viewType: #BASIC
@ObjectModel.representativeKey: 'AirConnection'
define view ZDemo_Spfli as select from spfli
association [0..1] to ZDemo_Scarr as _Scarr
on $projection.Airline = _Scarr.Airline
{
@ObjectModel.foreignKey.association: '_Scarr'
key spfli.carrid as Airline,
key spfli.connid as AirConnection,
spfli.countryfr as DepartureCountry,
spfli.countryto as ArrivalCountry,
@Semantics.quantity.unitOfMeasure: 'AirDistanceUnit'
@DefaultAggregation:#SUM
spfli.distance as AirDistance,
@Semantics.unitOfMeasure: true
spfli.distid as AirDistanceUnit,
_Scarr

Third BASIC View:

@AbapCatalog.sqlViewName: 'ZVWSFLIGHT'
@ClientDependent: true
@AccessControl.authorizationCheck:#NOT_REQUIRED
@EndUserText.label: 'Airline Schedule'
@Analytics.dataCategory: #CUBE
@Analytics.dataExtraction.enabled: true
@VDM.viewType: #BASIC
define view ZDemo_Sflight as select from sflight
association [0..1] to ZDemo_Scarr as _Scarr
on $projection.Airline = _Scarr.Airline

association [0..1] to ZDemo_Spfli as _Spfli


on $projection.Airline = _Spfli.Airline
and $projection.AirConnection = _Spfli.AirConnection
{
@ObjectModel.foreignKey.association: '_Scarr'
key sflight.carrid as Airline,
@ObjectModel.foreignKey.association: '_Spfli'
key sflight.connid as AirConnection,
key sflight.fldate as FlightDate,
@Semantics.amount.currencyCode: 'FlightCurrency'
@DefaultAggregation: #MIN
sflight.price as FlightPrice,
@Semantics.currencyCode: true
sflight.currency as FlightCurrency,
@DefaultAggregation: #SUM
sflight.seatsmax as MaximumAvaSeats,
@DefaultAggregation: #SUM
sflight.seatsocc as NumberOfAvaSeats,
/* Associations */
_Scarr,
_Spfli
}

COMPOSITE VIEW:

@AbapCatalog.sqlViewName: 'ZVWCSFLIGHT'
@ClientDependent: true
@AccessControl.authorizationCheck:#NOT_REQUIRED
@EndUserText.label: 'Airline Schedule by Country'
@Analytics.dataCategory: #CUBE
@VDM.viewType: #COMPOSITE
define view ZDemo_Csflight as select from ZDemo_Sflight
{
@ObjectModel.foreignKey.association: '_Scarr'
key ZDemo_Sflight.Airline,
@ObjectModel.foreignKey.association: '_Spfli'
key ZDemo_Sflight.AirConnection,
key ZDemo_Sflight.FlightDate,
@Semantics.amount.currencyCode: 'FlightCurrency'
@DefaultAggregation:#MIN
ZDemo_Sflight.FlightPrice,
@Semantics.currencyCode: true
ZDemo_Sflight.FlightCurrency,
@DefaultAggregation: #SUM
ZDemo_Sflight.MaximumAvaSeats,
@DefaultAggregation: #SUM
ZDemo_Sflight.NumberOfAvaSeats,
/* Associations */
ZDemo_Sflight._Scarr,
ZDemo_Sflight._Spfli,
ZDemo_Sflight._Scarr.AirName,
ZDemo_Sflight._Scarr.AirlineUrl,
ZDemo_Sflight._Spfli.DepartureCountry,
ZDemo_Sflight._Spfli.ArrivalCountry

Consumption View:

@AbapCatalog.sqlViewName: 'ZVWSFLIGHTQUERY'
@ClientDependent: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Flight Analytic Query'
@Analytics.query: true
@VDM.viewType: #CONSUMPTION
@OData.publish: true
define view ZDemo_Sflight_Query as select from ZDemo_Csflight
{
@AnalyticsDetails.query.axis: #ROWS
ZDemo_Csflight.Airline,
@AnalyticsDetails.query.axis: #ROWS
ZDemo_Csflight.AirConnection,
@AnalyticsDetails.query.axis: #ROWS
ZDemo_Csflight.FlightDate,
@Consumption.filter: {selectionType: #SINGLE, multipleSelections: false,
mandatory: true }
@AnalyticsDetails.query.axis: #ROWS
@EndUserText.label: 'Departure Country'
ZDemo_Csflight.DepartureCountry,
@AnalyticsDetails.query.axis: #ROWS
@EndUserText.label: 'Arrival Country'
ZDemo_Csflight.ArrivalCountry ,
@AnalyticsDetails.query.axis: #COLUMNS
ZDemo_Csflight.FlightPrice,
ZDemo_Csflight.FlightCurrency,
ZDemo_Csflight.MaximumAvaSeats,
ZDemo_Csflight.NumberOfAvaSeats

Run RSRT t-code and enter sql view name appending with 2C.

2CZVWSFLIGHTQUERY

Enter Departure country value as US and click on Continue button.

OUTPUT:
20) AMDP CLASS and invoking AMDP from report:
Example 1:

Create class and write below logic:

class Z_AMDP_CLASS_SALESORDER definition


public
final
create public .

public section.

*Marker interface for Database Procedures


INTERFACES: if_amdp_marker_hdb.
*Structure
TYPES:
BEGIN OF ty_order,
vbeln TYPE vbeln,
posnr TYPE posnr_va,
vkorg TYPE vkorg,
item_price TYPE netwr_ap,

END OF ty_order.
* Table type
TYPES:
tt_order TYPE STANDARD TABLE OF ty_order WITH EMPTY KEY.
* Method Definition
CLASS-METHODS get_salesorder_details
IMPORTING
VALUE(iv_vbeln) TYPE vbeln
EXPORTING
VALUE(et_order) TYPE tt_order.
protected section.
private section.
ENDCLASS.

CLASS Z_AMDP_CLASS_SALESORDER IMPLEMENTATION.

METHOD get_salesorder_details BY DATABASE PROCEDURE


FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING vbak vbap.
*To get Sales Order details
et_order = SELECT vbak.vbeln,
vbap.posnr,
vbak.vkorg,
vbap.netwr as item_price
FROM vbak AS vbak INNER JOIN vbap AS vbap
ON vbak.vbeln = vbap.vbeln
WHERE vbak.vbeln = iv_vbeln;
ENDMETHOD.
ENDCLASS.

Invoking AMDP CLASS Method from Report:

*&---------------------------------------------------------------------*
*& Report z_amdp_report_salesorder
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_amdp_report_salesorder.

PARAMETERS: p_vbeln TYPE vbeln.


* To Call AMDP Method
Z_AMDP_CLASS_SALESORDER=>get_salesorder_details(
EXPORTING iv_vbeln = p_vbeln
IMPORTING et_order = data(lt_order) ).
* To display Sales Order Details
cl_demo_output=>display_data( name = 'Sales Order Details'
value = lt_order ).

Example 2:

Create class :

class ZCL_EXAMPLE_AMDP definition public.


public section.
interfaces IF_AMDP_MARKER_HDB.
class-methods get_flights for table function Z_Cds_Table_Functions.

protected section.
private section.
endclass.

class ZCL_EXAMPLE_AMDP implementation.

method get_flights by database function


for hdb
language sqlscript
options read-only
using scarr spfli.
RETURN SELECT sc.mandt as client,
sc.carrname, sp.connid, sp.cityfrom, sp.cityto
FROM scarr AS sc
INNER JOIN spfli AS sp ON sc.mandt = sp.mandt AND sc.carrid =
sp.carrid
WHERE sp.mandt = :clnt AND
sp.carrid = :carrid
ORDER BY sc.mandt, sc.carrname, sp.connid;
endmethod.

endclass.

Invoking AMDP method from report:

REPORT z_amdp_report.

PARAMETERS : p_matnr TYPE matnr DEFAULT '000000000000001109'.

DATA : r_amdp TYPE REF TO Z_AMDP_CLASS,


et_mara TYPE TABLE OF mara,
r_salv TYPE REF TO cl_salv_table.

CREATE OBJECT r_amdp.

r_amdp->my_method( EXPORTING im_matnr = p_matnr


IMPORTING et_mara = et_mara ).

TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = r_salv
CHANGING
t_table = et_mara
.
CATCH cx_salv_msg .
ENDTRY.

r_salv->display( ).

21) When expression

@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SCASE'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view Zdemo_cds_searched_case
as select from
spfli
{
key carrid,
key connid,
distance,
distid,
case
when distance >= 2000 then 'long-haul flight'
when distance >= 1000 and
distance < 2000 then 'medium-haul flight'
when distance < 1000 then 'short-haul flight'
else 'error'
end as flight_type
}
where
distid = 'MI'

22) Hierarchy Views:


23) Cds view : for UI annotations code:

CSADL_VOC_SOCH – Standard CDS view:

@AbapCatalog.sqlViewName: 'CSADL_VOC_SOCH'
@EndUserText.label: 'Vocan View: Sales Order Chart UI Anno'
@VDM.viewType: #CONSUMPTION

@UI.chart: [
{
title: 'Sales Order Volume Column',
description: 'Sales Order Volume Column Chart',
chartType: #COLUMN,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Columnstack',
title: 'Sales Order Volume Column Stack',
description: 'Sales Order Volume Column Stack Chart',
chartType: #COLUMN_STACKED,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Columnstack100',
title: 'Sales Order Volume Column Stack 100',
description: 'Sales Order Volume Column Stack 100 Chart',
chartType: #COLUMN_STACKED_100,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Area',
title: 'Area',
description: 'Area Chart',
chartType: #AREA,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Areastacked',
title: 'Area Stacked',
description: 'Area Stacked Chart',
chartType: #AREA_STACKED,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Areastacked100',
title: 'Area Stacked 100',
description: 'Area Stacked 100 Chart',
chartType: #AREA_STACKED_100,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Horizontal',
title: 'Horizontal',
description: 'Horizontal',
chartType: #HORIZONTAL_AREA,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Horizontalstacked',
title: 'Horizontal Stacked',
description: 'Horizontal Stacked Chart',
chartType: #HORIZONTAL_AREA_STACKED,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Horizontalstacked100',
title: 'Horizontal Stacked 100',
description: 'Horizontal Stacked 100 Chart',
chartType: #HORIZONTAL_AREA_STACKED_100,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Line',
title: 'Line',
description: 'Line',
chartType: #LINE,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Bar',
title: 'Bar',
description: 'Bar Chart',
chartType: #BAR,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Barstacked',
title: 'Bar Stacked',
description: 'Bar Stacked Chart',
chartType: #BAR_STACKED,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Barstacked100',
title: 'Bar Stacked 100',
description: 'Bar Stacked 100 Chart',
chartType: #BAR_STACKED_100,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Pie',
title: 'Pie',
description: 'Pie',
chartType: #PIE,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Donut',
title: 'Donut',
description: 'Donut',
chartType: #DONUT,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Scatter',
title: 'Scatter',
description: 'Scatter',
chartType: #SCATTER,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Bubble',
title: 'Bubble',
description: 'Bubble',
chartType: #BUBBLE,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Radar',
title: 'Radar',
description: 'Radar',
chartType: #RADAR,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Heatmap',
title: 'Heatmap',
description: 'Heatmap',
chartType: #HEAT_MAP,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Treemap',
title: 'Treemap',
description: 'Treemap',
chartType: #TREE_MAP,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Waterfall',
title: 'Waterfall',
description: 'Waterfall',
chartType: #WATERFALL,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'Bullet',
title: 'Bullet',
description: 'Bullet',
chartType: #BULLET,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolume', 'SalesOrderTaxAmount' ]
},
{
qualifier: 'InvalidChart',
title: 'Should not be displayed',
description: 'Should not be displayed',
chartType: #AREA,
dimensions: [ 'CompanyName', 'Country', 'Status' ] ,
measures: [ 'SalesOrderVolumeNetAmount']
}
]

define view C_Sadl_Voc_Salesorder_Chart

as select from C_Sadl_Voc_Businesspartner as Document


left outer join C_Sadl_Voc_Salesorder_Eur as _SalesOrderVolume on
_SalesOrderVolume.BusinessPartnerId = Document.BusinessPartnerId

association [0..*] to C_Sadl_Voc_Salesorder_Smpl as _SalesOrders on


_SalesOrders.BusinessPartnerId = Document.BusinessPartnerId

{
key Document.BusinessPartnerId,
Document.CompanyName,
Document.CurrencyCode,
Document.BusinessPartnerRole,
Document.Country,
Document.CreatedBy,
@UI.lineItem: [ {
position: 50,
importance: #MEDIUM,
label: 'Sales Order Volume'
},
{ qualifier: 'ForChart',
position: 51,
importance: #HIGH,
label: 'Sales Order Volume',
type: #AS_CHART,
valueQualifier: 'Columnstack'
}]
@UI.identification: [{
position: 2,
importance: #HIGH,
label: 'Sales Order Volume'
}, {
position: 2,
importance: #HIGH,
label: 'Sales Order Volume',
type: #AS_CHART,
valueQualifier: 'Columnstack'
}]
sum(_SalesOrderVolume.NetAmount) as SalesOrderVolume,
sum(_SalesOrderVolume.TaxAmount) as SalesOrderTaxAmount,

min(_SalesOrderVolume.LifecycleStatus) as Status,

_SalesOrders

}
group by
Document.BusinessPartnerId,
Document.CompanyName,
Document.CurrencyCode,
Document.BusinessPartnerRole,
Document.Country,
Document.CreatedBy

24) S_NWDEMO IS SUPER PACKAGE where all demo apps can be viewed:

25) To view MM related CDS views:

APPL ODATA_MM
Odata service with parameters in CDS view :

//http://madap8036.accenture.tsap:8001/sap/opu/odata/sap/Z_CDS_PARAMS_ODATA_CDS/
//Z_CDS_PARAMS_ODATA(p_carrid='AA')/Set
//http://www.saplearners.com/create-odata-service-abap-cds-views/

@AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO_P'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'OData service on ABAP CDS View'
@OData.publish: true
define view Z_CDS_PARAMS_ODATA
with parameters p_carrid :s_carr_id
as select from scarr
{
key carrid as AirlineCode,
carrname as AirlineName,
currcode as Currency,
url as AirlineURL
}
where carrid = $parameters.p_carrid

You might also like