CDS View with input parameters Part 7 ABAP on HANA Course
Summary
TLDRThis video tutorial delves into the creation and use of parameterized CDS (Core Data Services) views in SAP. It explains how to define parameters for a CDS view, making some mandatory and others optional by setting default values. The video walks through examples of passing parameters such as sales order numbers and dates, and shows how default system fields like client, system date, and user ID can be applied. Additionally, the tutorial discusses the differences between DDIC-based CDS views and new CDS entity views, providing insights on how to manage parameters effectively.
Takeaways
- 📊 Parameterized CDS views require user input for certain values to execute, especially for filtering data dynamically.
- ⚙️ Parameters can be passed during the execution or while calling the CDS view in a select statement.
- 💡 Defining parameters in a CDS view allows more flexibility as users can input values instead of relying on constants.
- 📝 Parameters need to be referenced using the `$parameters` syntax to pass the user input into WHERE conditions.
- 🚫 All parameters are mandatory unless a default system value (like system date or client) is assigned.
- 📅 You can define multiple parameters, including dates, and use them in the WHERE clause or output fields.
- 🚀 Default values for parameters can be assigned using system variables (e.g., system date), making those parameters optional during execution.
- 🔧 When using parameters in output fields, an alias must be specified.
- 📝 SAP provides system fields like system date, system time, and client as default values, but only a few system fields can be used as defaults.
- 🖥️ SAP's standard demo programs provide examples for testing and understanding parameterized CDS views.
Q & A
What is a parameterized CDS view in SAP?
-A parameterized CDS view is a Core Data Services (CDS) view that accepts input parameters. When executing the view, it asks for parameter values, and only after these values are provided does it generate the output.
Why would you use a parameterized CDS view instead of a normal CDS view?
-You would use a parameterized CDS view when you want to control which data is displayed by asking the user to provide specific input values. This makes the view more dynamic and flexible, as it can return different results based on the parameters passed.
How do you define a parameter in a CDS view?
-To define a parameter in a CDS view, you add the `with parameters` clause after the view entity definition. You specify the parameter name, its data type (like ABAP types or data elements), and optionally default values using system variables.
Can you explain how to access a parameter in a WHERE clause in CDS?
-To access a parameter in a WHERE clause, you use the `$parameters` keyword followed by the parameter name. For example, `$parameters.p_vbeln` would be used to access a parameter named `p_vbeln` and pass its value to the WHERE clause.
Are parameters in a CDS view always mandatory?
-Yes, parameters in a CDS view are mandatory by default. However, there is an exception if you provide a default value using system fields (like system date, system client). In such cases, the parameter is not mandatory.
What annotation is used to assign a default value to a parameter in a CDS view?
-The `@Environment.systemField` annotation is used to assign default values to parameters in a CDS view. This annotation allows you to use predefined system values like the system date, time, client, etc.
What happens if you don't pass a parameter value when calling a parameterized CDS view in ABAP?
-If a mandatory parameter is not passed when calling a parameterized CDS view in an ABAP program, the system will raise a syntax error or cause a dump, indicating that the parameter is missing.
Can a parameter be used in fields other than the WHERE clause?
-Yes, parameters can be used in various parts of the CDS view, such as the field list, WHERE clause, or even in aggregation and on conditions. You can access the parameter value using the `$parameters` expression.
What types of system fields can be used as default values in CDS parameters?
-The system fields that can be used as default values include the system client, system date, system time, system user, system language, and system timezone.
What is the difference between a DDIC-based CDS view and a CDS view with entity definitions?
-A DDIC-based CDS view can use colon syntax (:) to access parameters, while a CDS view with entity definitions requires the use of the `$parameters` expression. The newer entity-based CDS views have stricter syntax rules.
Outlines
👋 Introduction to Parameterized CDS Views
The video begins with an introduction to parameterized CDS views in SAP. It explains that parameterized CDS views require user input to display data and discusses the importance of parameters when executing or using CDS views in select statements. A step-by-step guide is provided on how to convert a normal CDS view into a parameterized one by adding a parameter called `p_vbln` for the sales order number. The video emphasizes that the view will only execute if the user provides the required parameter.
⚠️ Parameters in Select Statements and Syntax Errors
This section explains the importance of passing parameters when calling parameterized CDS views in select statements. If parameters are not provided, the view will generate an error or dump. The video demonstrates how to resolve syntax errors by binding the required parameter `p_vbln` and passing the sales order value. It also highlights the strict nature of mandatory parameters and the impact of omitting them.
📅 Adding Multiple Parameters and Default Values
The presenter introduces adding multiple parameters to a CDS view and assigning default values to avoid mandatory input requirements. A new date parameter (`p_date`) is added, and it is explained that default values for certain system fields (e.g., client, system date, system time) can make these parameters optional. The video showcases how the date parameter displays either user input or defaults to the system date if no input is provided.
🛠️ Using Environmental Annotations for Default Values
This section focuses on environmental annotations, specifically `@Environment.systemField`, used to assign default values to parameters in CDS views. The video explains that only certain system fields (e.g., system date, client, user ID) can be set as default values. A demonstration is given on how to activate and execute the CDS view when a default value is set, showing that mandatory fields become optional if they have a system-defined default.
📝 SAP Standard Program and Demo for Parameterized Views
The final section covers an SAP standard demo program that uses a parameterized CDS view with system default values. The video explains how parameters in this demo are not mandatory due to default values and shows how the program handles both cases—when parameters are passed and when they are omitted. The difference between DDIC-based CDS views and new CDS view entities is also discussed, particularly regarding syntax differences when accessing parameters.
Mindmap
Keywords
💡Parameterized CDS View
💡CDSU
💡Mandatory Parameters
💡Default Value
💡Environmental Annotation
💡DDIC-Based CDS View
💡Activation (Ctrl+F3)
💡Select Statement
💡Expression Table
💡SFP
Highlights
Introduction to parameterized CDS views and their role in executing queries with user-defined parameters.
Demonstrating how parameters in a CDS view ask for user input, ensuring the query result is based on that input.
Creating a parameterized CDS view by adding a parameter after defining the view entity name.
Usage of system annotations to create default values for parameters, making them optional.
Explanation of using system variables like system date, time, and user data as default values in parameterized CDS views.
Illustration of converting a standard CDS view into a parameterized CDS view by using the 'with parameters' clause.
Showing how parameters can be used in the WHERE clause to filter results dynamically based on user input.
Clarification on the usage of '$parameters' to access user input values in the CDS query logic.
Default parameter values can only be assigned from system variables like client, system date, and user.
Steps to activate a parameterized CDS view and how to test it by running a program in ABAP.
Showing how using parameters in the field list can help display user-entered data directly in the output.
Demonstrating the use of multiple parameters in a CDS view by separating them with commas.
Explaining the importance of aliasing parameters in the field list for proper view activation.
Illustrating how to call parameterized CDS views within ABAP programs and handling the mandatory nature of parameters.
SAP’s best practices and guidelines for working with parameterized CDS views, including a reference to SAP's standard demo program for further experimentation.
Transcripts
hello everyone welcome to sfp
technomaniac in this video we will learn
about the parameterized cds view and we
will able to answer some of the best
equations like when we use the parameter
cdsu is it all the parameters are
mandatory to enter in the cds view or
there is some exception as well where we
will
not enter some parameters value still
our serious view will be executing so
let's get started
to create a view with parameter i will
use same
tds which we have created in my last
video
so
this is the normal cds view we will
convert the cds view into a
parameterized cds view
what i mean by the parameter is cdsu
whenever we execute this particular cds
view it will ask for the some value when
we enter that value then only the result
will be displayed
not only the
exit on the execution but also when we
call this particular cdsu in my select
statement
uh then also
it will ask for the values and then only
it will be activated
what i will do
i will use i will create one parameter
for this particular cds view for
creating a parameter you after the
defined view entity and we are giving
the entity name just after that we have
to write with parameters
and as soon as
we will write with parameter i have to
give the parameter name so what is the
parameter name p underscore controls
i have to give the vbln as a parameter
because instead of passing this
parameter is a constant value i
currently when i am executing this
particular cdsu entity i have passed in
where condition as a sales order is a
sixth sales order number i am displaying
in the output but i want
that user should enter any sales order
number that should be displayed in the
output so for that purpose i have
created this parameter p underscore vbln
i have to give the parameter name then
the column then i have to give the type
of this particular parameter i can use
any about type of parameter or system
default whatever the environmental
parameter which is we are using whenever
we are defining that any day variables
in the normal program those all we can
use data element also we can use so in
this case we will use the data element
we know the type should be vblm so i
have used the vbl and as a type
so as soon as i have defined this
particular parameter
now the system is telling like that you
have defined this parameter
but but you are you are not using this
particular parameter in anywhere in your
cds
so for this purpose i want to access
this parameter in my wire condition so
instead of passing this constant
whatever the user will enter
in the parameter value that value i will
pass
in this where condition for that purpose
to access the parameter in the system
what i have to use i have to use the
dollar
parameters
and if i do control space all the
parameters will be displayed and i will
pass this
sales order number which user have
entered that in the where condition and
it will be displayed once the user do
app hit let me activate this one control
f3
of now just ignore this program where we
are using this particular cds view
ok i have activated this particular
program let me do
fade to this particular cds view
f8
so it soon i did the effect you can see
it is asking for the parameter value
because i have defined one parameter in
my cds view
i can and this is also mandatory i can
see the star symbol means it's a
mandatory that's very important thing so
i have to pass this value then only the
cdsu will be executed otherwise it will
be not executed so one two three four
five six seven eight nine and any number
i can give i use the six number because
we were using previously
and i am clicking on ok button then the
output will come this time instead of
where condition we have
we have passed the
through const instead of passing through
constant we have passed as a parameter
this particular sales order value and we
can see the result
or let me do f8 once again this time i
will pass instead of six sales order
some other sales order
i can pass suppose i have a passport to
sales order and i will do
so you can see i this time i got that's
order number four so like that
i can get any sales order detail when i
pass the sales order value this is the
normal thing
so as you remember from my previous
video i have called this particular cds
view
in my one of the program
that time that this particular cdsu was
not
this particular cds view was not
parameterized
and here we
we normally call the cds view and we got
the result easily but now if i try to
do f8 i will get the dump
because now you have converted your cds
you to the parameter cds view and you
don't pass those parameters here because
parameters are mandatory
you have to pass there is one exception
case that also i will explain but as of
now you can see parameters are mandatory
and uh
since we didn't pass this particular
parameter so it will give us a dump and
if you try to activate this one we will
get on first place the
syntax error you can see activation
failed with the error c problem view
basically we got the syntax error what
syntax error the parameter was not bound
we didn't pass any parameter
so for how to pass the parameter when we
call the cds
view or cds entity in our select
statement what is just after the cdsu
entity name we have to click on control
space
control z control space
just
so i can give the p underscore vbl and
value and i have to pass p underscore
vbln value i can pass any value one two
three four five six seven eight
nine ten
so i have passed this particular sales
order value to display in the output i
am using the cl demo output to display
in the output i have passed you can see
that particular syntax error got removed
because i since my
the cds view entity is the parameterized
and i have passed this particular
parameter as well let me activate this
one control f3
and let me see the result
if i do f9
so
let me open console over here so you can
see the result as well let me clear out
the console and do the f9 again
so i go to the result with the fourth
size
sales order number four fourth and other
detail also i put
like that i can call the parameterized
cds view in my ab report or my program
now
the other thing is i told you
the parameters are mandatory we have to
pass there is one exception
if we can give some default value to
this parameter
then these are not mandatory
and the default value we can give is
only as a system variables
so how to give the default value for
explaining purpose i will add one more
parameter to our cds that will be the
date
so what i will do if you want to add
multiple parameter to particular cds you
have to give the comma separated list i
have to do comma
and i have to give another
parameter which i want to give this will
be the date parameter i want to give the
date parameter over here and the type
should be
i can use this time the ab date is a
it's
is a parameter
so this will uh
again i have created one more parameter
and i didn't use this time instead of
using in my where condition i will use
this particular parameter in my
filled list
so you can use in the field list or if
you are doing any automatical operation
there also you can use if you are doing
any aggregation operation there also you
can use and if you can you can use on
the on condition filter condition or in
wire condition anywhere you can use this
parameters as per your requirement
so i just want to display this
particular p underscore date to access
this particular parameter again i have
to use this
a dollar
parameter expression and control space
we underscore date
i want to display this date whatever
user have entered
so if i do control f3
one more important thing if you are
using the
i got the error if you are using
the parameter
in the field list you have to
mandatorily give the alias name so i
have to give some alias name then only i
can use is
just date
i can give some name
just date now i will not get the error
let me do activation of this control f3
and now our
tdsu entity got activated now let me
execute this span
you can see i can enter two parameter
but both parameters are mandatory
let me pass some value 1 2 3 4 5 6 7 8 9
10
and let me pass some date also 1991 1104
or some any date you can pass
and because it is mandatory to pass the
date otherwise this particular view
entity will be not executed let me do
okay
and we can see the result
let me open over here
so this system did go uh this this date
whatever i have entered the date with
same date got displayed over here
but that was mandatory
as i told you there is one hack over
here i can there one exception where we
can
though those parameters are mandatory
in those cases those parameters will be
not mandatory so for making that i have
to pass some default value to the
parameter
so default value to parameter i can pass
only the four or five very values are
there that i can pass as a default value
like this client values system date
system time
or
system variables basically i want to say
system variable i can pass as a default
value and since it is a date field i can
pass a system date as a default value
and this will be not mandatory because i
have passed this parameter as a default
value so let me do for that purpose i
have to use one again one new annotation
will learn environmental
environment
annotation let me
write it down and wire
environment dot system field to access
system field this is particular
annotation is very very useful and this
system field it will give the default
value to the particular this date
because we defined this particular
annotation just
above the this particular date either we
can define over here or just after this
p date also we can define so let me do
what value i want to use here then i can
use only five values client system date
system language system type user or one
more thing is there user date and user
time zone six values only
is a parameter with the default this six
value is
i can use as a default value apart from
that and any value i can't use as a
default value
so these are the values i can easily use
as a default value i will use system
date in this case as a default value
and i will activate my tds view entity
let me analyze little bit over here and
let me activate it ctrl f3
one interesting thing you will see
when you execute this one
now you can see this date is not
mandatory but sales order is still
mandatory you have to pass the size of
that one two three four five six seven
eight nine
and ten any sales order i can display
okay
so sales order nine got displayed but
the important thing is that which i want
to show you this time
uh system date go displays two days did
what is the two days that because i
didn't pass any date value so it took
the system date and that date got
particular date code displayed in the
output
and with the same goes with the
this one also if i will not define this
particular
parameter is a default if i will not
pass any default value
ctrl z ctrl x and control f3 and i will
try to activate this particular program
where i have used this particular cds
entity it will give me error
what error i will get
okay let me activate this first
ctrl f3
and let me activate this particular
program as well control f3
i got one error activation failed with
the
this will basically say you didn't pass
date is a mandatory if i pass this date
also p underscore date some value
then i will not get that error
what i will pass
1991-0202
something i can pass so
since i have passed the now this
particular since we have to pass here
comma as well if we are passing the
multiple uh parameter so
if i try to activate now control f3 i
will not get any error and if i do f9 as
well then i will get the result pro
result also there you go i got the
result but this time date is different i
go to some other date
system date i got here in previous
execution i didn't get the system date
because i didn't that time in my
parameter the system date was not there
so it's a simple simple thing but if i
use uh
environmental system field
and if i activate now this control f3
and
if i pass then whatever i am passing
that will be displayed and if i don't
pass this particular date
and i will try to activate this time it
will get activate because i pass default
value using the environment environment
annotation so that is the reason it is
getting activated and if i try to get
the result see the result in console let
me do f9
so i got this time but the date is a
system date two days date i got and the
result you can see how we are getting
so like this is the way we can create
the parameters cdsu before going further
i just want to show you one sfp standard
program there if you if you want to do
experimental
experimental thing with the parameter
things so i have something standard
program that is very useful control c
and this is
what this is written i have written the
same thing whatever i return
let me close everything
else
so it's written like the same thing
default value can be assigned with the
annotation this annotation and parameter
are optional only when the default value
is assigned we can assign the default
value to parameter how we can assign
using the environmental annotations
environmental annotation we have the
limitation only five or six
environmental annotations we can use and
we can as i assign as a default value
and we can only use the system field to
search as a system date system language
as a default value other value we can't
use so basically we can say apart from
this six value we can't pass any default
value and other
apart from 56 value if you are using any
other value then the parameter will
become the mandatory
and we have one
cdsu control c
control shift a
control v
let me this is sfp standard demo cdsu
which used in this particular program i
just want to show you this particular
program
this we how we usually do the this is
main method we are this is local class
demo uh and we have one static main
method which we are calling instead of
selection inside that they have one demo
expression table that first what they
are doing they are deleting everything
from this demo expression table then
they are inserting one entry with the id
one if you see this demo expression
table it is having the id field as a key
field i just want to show you id field
is a key field they have entered one
entry with the other field are blank
then what they are doing they are
pulling on cdsu if you see this
particular cdsu
this is ddic based cds view i will show
you
the this is the
ddac based cdsu you can see in this ddac
base cdsu they are using
four parameter or four or five parameter
one two three four five parameter they
are using all parameters are
uh they are using the some default value
using this particular environmental
environment annotation
and all the fields they are displaying
in the output and one more thing they
are just using id1 which they have
inserted that particular entry so this
is basic demo cds view given for the
purpose of the how we can pass the
default value values to parameter one
what all are the values are possible
only these five values are possible so
they have used all
five values so what they are doing
if i do the f9 or f8 to this particular
cds view you can say f8
and all
four parameters are there one two three
four and all are not mandatory actually
hola
not mandatory if i do i if i do the f8
over here uh if i click on ok button
still is it will display some result
with the system date client userid
language and other detail it will
display the error and if i call this
particular cds you can so in the program
also they have called in one select
statement they have passed the all the
parameter in another select statement
they didn't pass any parameter but still
we can see
in both the cases we will get the same
result and i just want to show you let
me do f9
you can see we got the result client
date you date field time and both the
cases we have got the same result from
this particular program this is the one
of the sfp standard demo program which i
have used but one more important thing i
just want to do might have seen what is
this
semicolon doing here we are accessing
this particular parameter using the
colon
this got absolute
because
they have used the ddic based
3ds view
this ddic based cdsu we can use still
this colon but in the if i try to use in
my
entity define view entity this
particular
cds like this this particular to access
the parameter i will use colon then it
will give us you have to use the
expression this particular expression
dollar parameter expression you have to
use instead of this so that is the
reason
the uh in the
define view entity or new cds view
entity we have the stricter syntax check
so we have to follow strictly
uh
we have to use pyramid dollar parameter
only so one simple thing i just want to
for this cds also we have another
cds also there let me show you that cds
also uh let me go here ctrl c
ctrl c this is fills v
and let me do ctrl shift a
ctrl v
this is the another cds is there
where this is
this cds and this cds both are similar
but this is
ddic based cds view
this one and this one is the
defined view entity means the cds view
with entity a defined created with the
cdsu entity in uh newer way of the
view creation that newer way that is the
reason in this they have used the colon
and in this they can't use column they
have to use mandatory dollar parameter
and in this case they have created one
sql view in this in this case we we
don't have any sql
this is the one of the example i just
want to show you sf standard example
so if you want to see because this kind
of example available in every system you
can experiment you can copy this program
past in
your local
local program and you can do whatever
you want i hope you learn something new
from this video before going to next
video please like this video
subscribe this channel and share these
videos with others as well with that
thank you and happy learning
5.0 / 5 (0 votes)