ABAP Tutorial
8 CDS Views
a Create CDS Views
Right-click on your package name, type core in the search box and select Data Definition.
Referenced Object you fill in the name of a table or the name of a CDS view.
This means you can create CDS views of CDS views.
b Using system variables in CDS views
The following system variables are available in CDS views.
vname |
Value in Open SQL Accesses |
user |
Current user name, nominal value of the ABAP system field sy-uname |
client |
Current client. The default value is the nominal value of the ABAP system field sy-mandt. In reads with an Open SQL statement (with the statement USING CLIENT) and in calls of an AMDP method from ABAP (in whose declaration the addition AMDP OPTIONS CDS SESSION CLIENT is specified), the value specified here. |
system_language |
Text environment language of the current internal session, nominal value of the ABAP system field sy-langu |
system_date |
Current system date of the AS ABAP, nominal value of the ABAP system field sy-datum |
Here an example how to use them.
1 define view Z_AWP_CDS_HSMT_MD as select from hsmt_md 2 { key mandt as Mandt, 3 valto as Valto} 4 where valto > $session.system_date
c Join on join
1 2 define view Z_AWP_CDS_HAZ_WRONG 3 as select from Z_AWP_CDS_aqua as A 4 join ScmPrd_Ndbsmatg16 as N 5 on A. Matid = N. guid 6 join Z_AWP_CDS_HSMT_MD as H 7 on N. matnr = H.Matnr 8 {... 9
d Coalesce
COALESCE( arg1, arg2 )
The coalesce function returns the value of the argument arg1 (if this is not the null value); otherwise it returns the value of the argument arg2.
1 define view Z_AWP_CDS_LAGP as select from /scwm/ lagp 2 { key lgnum as Lgnum, 3 coalesce ( cast ( anzle as abap . dec (10,2) ) , 0) as Anzle , 4 coalesce ( cast ( maxle as abap . dec (10,2) ) , 0) as Maxle 5
e Cast
CAST( operand AS dtype [PRESERVING TYPE])
The cast expression converts the value of the operand operand to the dictionary type specified by dtype. The result has the type dtype. The following can be specified for dtype:
I copied the information contained in these two tables from https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abencds_f1_cast_expression.htm. It seems like a good idea, to check, whether this information has been updated.
1 define view Z_AWP_CDS_LAGP as select from /scwm/ lagp 2 { key lgnum as Lgnum, 3 coalesce ( cast ( anzle as abap . dec (10,2) ) , 0) as Anzle , 4 coalesce ( cast ( maxle as abap . dec (10,2) ) , 0) as Maxle 5