ABAP CDS View with input parameters
ABAP CDS Views:
A CDS is defined for existing database tables and any other views or CDS Views in ABAP Dictionary using the statement DEFINE VIEW in the DDL in ABAP Core Data Services(CDS) . This is done in CDS Source code in the ABAP Development tools(ADT). Every CDS view has its own CDS Source code.
Two objects are created in ABAP Dictionary of Every CDS View:
- CDS Database View : It is read-only classical database view in ABAP Dictionary.
- CDS Entity: It is actual CDS view. It covers the CDS Database view and makes other attributes possible, such as authorization checks defined in CDS view
A CDS View has two types of keys:
- For CDS Entities ,KEY can be used to define key elements, This Key is the semantic key of the CDS View
- The key of the CDS database view is determined implicitly, as in a classical view. This key is a technical key of the CDS View.
ABAP CDS- DEFINE VIEW parameter list
Syntax:
…..WITH PARAMETERS pname1:parameter type,pname2…
Effect: Defines Input parameters pname1,pname2 in a CDS View in ABAP CDS in a comma separated list. Each input parameter must be typed with a data type parameter type.
.
Example:
The following CDS View has a list of two input parameters in the WHERE Clause of the SELECT statement.
@AbapCatalog.sqlViewName:’DEMO_INPUT_CDS’
Define view demo_parameters_cds
With parameters p_country:LAND1_GP,
p_region:REGIO
as Select from KNA1
{ key kunnr,
land1 as Country key,
name1,
ort01 as City,
region as Region
} where land1 = : p_country and regio = : p_region;
Steps to be shown in this document:
- Define input parameters in a CDS View
- Use input parameters in a CDS View.
- Define a View as a parameterized view.
- Call a parameterized view with open SQL.
1.Define input parameters in a CDS View.
- Start ABAP in Eclipse
- Right click on the package icon,and from the context menu select New->other ABAP repository object.
2.Use input parameters in a CDS View.
@AbapCatalog.sqlViewName:’ZCDS_DDL_IP1′
@EnduserTextLabel :’ABAP CDS View with input parameters’
Define view ZCDS_DD1_IP_TEST
With parameters matnr:abap.numc(18),
Lang:abap.char(1)
As select from mara as a
inner join makt as b
on a.matnr = b.matnr
{
key a.matnr as material,
b.maktx as description,
$parameters.Lang as language
} where a.matnr = $parameters.matnr and b.spras = $parameters.Lang;
3.Define a Parameterized view.
Shown the material description as per the language specified on input parameter.
4.Call a parameterized view with open SQL.
Define view ZCDS_DD1_IP_CALLCDS
With parameters matnr:abap.numc(18),
Lang:abap.char(1)
As select * from ZCDS_DD1_IP_TEST(matnr:$parameters.matnr,lang:$parameters.Lang)
Reference Links:
hi mpreddy,
I did a test on the system, but there was a problem.
.
Which version (ABAP, HANA, ADT) do you use?
TKS
ABAP version 740 ,ADT version is the latest version
May be the system database is not hana ?
What is the 7.40 SP Version in your system?
This explains the reason for your error. CDS with input parameter is supported only from 7.40 SP8 onwards.
Regards,
Panneer
thank you
just give a try with colon(:) instead of dollar($) symbol.
:lang as language
} Where a.matnr = :matnr and b.spras = :lang
Can you please guide me, from which version of BEx query designer, supports parameterized CDS view?
Thanks,
Tejaswini.
Hello experts,
From which version of NW ABAP parameterized CDS views are supported as BEx queries?
Thanks.
Hi,
Is it possible that the parameters are displayed in Web Intelligence?
Thanks
Can CDS views with parameters be used in JOIN conditions ?
Yes. It can be used. While defining join condition itself, you need to pass required parameter to parameterized view.
e.g.
Define view abc with parameters
p_abc : char4 as select .................
Define view XYZ
with parameters p_xyz:char4
as select from ABC(p_abc:$parameters.p_xyz) inner join PQR on ABC.field1=PQR.field1
{
ABC.field1,
PQR.field1
}
Hope this is what you were looking for.
Hello,
Thanks for the information. Real good for the newbies to CDS Views.
A query - We are using SAP Data Intelligence to extract data from S4 CDS. How can we use selection parameters to filter records while running the SQL query in CDS views?
or how can we pass CDS View selection parameters to SAP Data Intelligence?
Regards,
Avinash