In the previous Tutorial, we saw how a CDS view can be made input enabled. This opens a new set of Code Push Down possibilities in AS ABAP.
SAP provides a limited way(till release 7.51) for CDS view to accept optional parameters. Optional parameters here mean that parameters are optional in nature during CDS consumption. This is possible with Environment System fields made available by CDS framework.
Let’s directly go to an example and check how to get this done!
CDS Source Code:
@AbapCatalog.sqlViewName: ‘ZTEST_CDS123’
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: ‘Example optional Input in CDS…’
// …Using Environment System field
// Use ofsuch optional parameter in CDS is limited
define view z_cds_default_input
with parameters
@Environment.systemField: #CLIENT
p1 : mandt,
p2 : uname @<Environment.systemField: #USER,
p3 : erdat @<Environment.systemField: #SYSTEM_DATE
as select from vbak as a
{
:p1 as Client,
:p2 as Ordered_By, // a.bname
:p3 as OrderDate, // a.erdat
a.vbeln as OrderNumber
}
where
a.mandt = :p1 // sy-mandt
and a.bname = :p2 // sy-uname
and a.erdat = :p3 // sy-datum
ABAP Source code to consume CDS:
REPORT zcds_optinal_input.
” Use case 1
SELECT *
FROM z_cds_default_input
INTO TABLE @DATA(lt_data1).
” Use case 2
SELECT *
FROM z_cds_default_input( ” p1 = @sy–mandt – NOT ALLOWED
p2 = @sy–uname )
INTO TABLE @DATA(lt_data2).
” Use case 3
SELECT *
FROM z_cds_default_input( p2 = @sy–uname ,
p3 = @sy–datum )
INTO TABLE @DATA(lt_data3).
Conclusion:
Limited System fields can be made optional in a CDS view or Table function. This can be achieved only with Environment System fields with two syntax possibilities.
Check the code by yourself for both CDS and ABAP report on GitHub.
Hi,I log on to your blog named “CDS with Optional Parameters – SAP Generation n><t…" daily.Your story-telling style is awesome, keep up the good work! And you can look our website about free proxy.
This is not optional parameters, this is system parameters