0% found this document useful (0 votes)
8 views12 pages

ABAP CDS Views and F4 and annotation

The document describes different ways to work with parameters in ABAP CDS views. It presents three scenarios for creating views with simple or multiple parameters, or with a selection range. The document also explains how to generate input help for the parameters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

ABAP CDS Views and F4 and annotation

The document describes different ways to work with parameters in ABAP CDS views. It presents three scenarios for creating views with simple or multiple parameters, or with a selection range. The document also explains how to generate input help for the parameters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

ABAP CDS Views: Working with parameters

& F4 Help
91233.067

ABAP CDS Views: Working with parameters & F4 Help

Version: SAP S/4 HANA 1909

Introduction:

In the SAP Embedded Analytics world, ABAP Core Data Service Views are also known as ABAP CDS Views.
ABAP CDS Views are defined on top of existing database tables. Which can be further used in UI5
application for reporting purpose. When we deal with reports, then we need some selection parameters to
restrict data in to get expected output. Which works as selection screen in UI5 application. Such
functionality can be achieved with the help of ABAP CDS view.

In the world of SAP Embedded Analytics, ABAP Core Data Service views are also called views.
ABAP CDS. ABAP CDS views are defined on top of existing database tables. Who
can then be used in the UI5 application for reporting purposes. When we process
reports, we need certain selection parameters to filter the data in order to obtain
the expected output. Which functions as a selection screen in the UI5 application. Such a feature
can be obtained with the help of the ABAP CDS view.

Based on my experience & learning; I am drafting information in the article below.

1. Scenario 1: CDS View With parameter

Method 1:

Here we will be creating a CDS view with a parameter.

@AbapCatalog.sqlViewName: Z_XXXX_V1 View Name


@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@VDM.viewType: #CONSUMPTION
@Analytics.query: true
@Analytics.dataExtraction.enabled: true
@EndUserText.label: Consumption view

define view ZCDS_C_XXXX //Defining CDS


View
with parameters
@EndUserText.label: Service Order Type
P_OrderType: abap.char( 4 //Parameter name &
Type

as select from ZCDS_I_XXXX(P_OType:$parameters.P_OrderType) // Passing


parameter value to compositeview

{
@AnalyticsDetails.query.axis: #ROWS
key aXYZ,
@EndUserText.label: Service Order Type
@AnalyticsDetails.query.axis: #ROWS
OrderType

Note: Parameter values can be passed to composite view as shown in above code.

Executing CDS in RSRT tcode will give us prompt as shown below:

Generating Input help:

In the above example, we are getting a pop-up to provide inputs, but we are not getting F4 help for inputs.
can be achieved as below.

Input help with Key & Text


Let’s have look at CDS view to identify how Value help is generated –

We have added annotation @Consumption.valuehelpDefinition: at parameter level to get input help. Name
& element helped us to connect with input help fields from CDS view ZCDS_XXXX_Value_Help.

We have not added any other association related ZCDS_XXXX_Value_Help in Consumption / composite /
interface views.

Sample Code -

define view ZCDS_C_XXXX // CDSView Name


with parameters
@Consumption.valueHelpDefinition: // Annotationto link
parameter with CDSview which will help to generate Text
[{
entity: { name: ZCDS_XXXX_Value_Help
element: 'OrderType'}
}]
@EndUserText.label: Service Order Type
P_OrderType: abap.char( 4 )

as select from ZCDS_I_XXXX(P_OType:$parameters.P_OrderType)

{
@AnalyticsDetails.query.axis: #ROWS
key aXYZ,
@EndUserText.label: Service Order Type
@AnalyticsDetails.query.axis: #ROWS
#KEY_TEXT
OrderType

Method 2:
In this method we are not creating CDS with parameters but we are going to use annotation
@consumption.filter.mandatory : True. This annotation will give us prompts the same as the parameter.

@AbapCatalog.sqlViewName: Z_XXXX_V1
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@VDM.viewType: #CONSUMPTION
@Analytics.query: true
@Analytics.dataExtraction.enabled: true
@EndUserText.label: Consumption view
define view ZCDS_C_XXXXas select from ZCDS_I_XXXX
{
@AnalyticsDetails.query.axis: #ROWS
key aXYZ,
@Consumption.Filter.mandatory: True // Annotationfor input
prompts
@Consumption.valueHelp: _ValueHelp.aXXXX // Annotation to link with
CDSview which will generate text
@EndUserText.label: Service Order Type
@AnalyticsDetails.query.axis: #ROWS
#KEY_TEXT
OrderType
}

Output:

Here we can see that F4 help is also enabled and it has happened because of annotation.
@Consumption.ValueHelp.

When we use this annotation then we must provide connection to our association in Consumption view.

@Consumption.ValueHelp: ‘_ValueHelp.aXXXX’

Here ‘_ValueHelp’ is the association name and ‘aXXXX’ is the field on which we are generating value help.

Let’s have a look at composite View.

Here we have created an association with the CDS view from which we are generating Value help. In addition to
this, we have mentioned 3 annotations above order type. We must use those annotation if we are generating
value help in parameter.
@AbapCatalog.sqlViewName: ZVM_XXX_A1
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Analytics.dataCategory: #CUBE
@VDM.viewType: #COMPOSITE
@EndUserText.label: Parameter based CDS view
define view ZCDS_I_XXXX
as select from aXXX_Table
association [0..1] to ZCDS_XXXX_Value_Help_ValueHelp
on $projection.OrderType= _ValueHelp.OrderType
{
key aXYZ,
@Search.defaultSearchElement: true
@Search.fuzzinessThreshold: 0.8
@ObjectModel.foreignKey.association: _ValueHelp
aXXXX as OrderType,

//Association
_ValueHelp

@ObjectModel.Foreignkey.association will work with primary key of CDS view used in association.

An alternative way to achieve this will be as follows -

i) In composite view, use the @ObjectModel.Text.Association annotation and provide a direct mapping to Text.
View.

ii) In Consumption view use @Consumption.valueHelp: annotation.

Advantage: With this method, there will be no need for a dimension view while generating input help.

2. Scenario 2: Parameters with multiple Selection

If we want to allow users to select multiple inputs, then use the annotation below at the consumption level.

@Consumption.filter.multipleSelections: true
Sample Code –

define view ZCDS_C_XXXXas select from ZCDS_I_XXXX


{
@AnalyticsDetails.query.axis: #ROWS
key aXYZ,
@Consumption.Filter.mandatory: True
@Consumption.Filter.MultipleSelections: True // Annotationto
enable multiple selection
@Consumption.valueHelp: _ValueHelp.aXXXX
@EndUserText.label: Service Order Type
@AnalyticsDetails.query.axis: #ROWS
@AnalyticsDetails.query.display: #KEY_TEXT
OrderType
}

This will give us option to have multiple selection. User can choose & pass multiple inputs to report.

3. Scenario 3: Parameter with range option

If we face a scenario where we need an option to have a range selection screen, then we can use the annotation below.
in Consumption view.

@Consumption.filter.mandatory: True
@Consumption.filter.selectionType: #RANGE

Writing code to generate Value help

Till now we have seen multiple options to generate parameters & F4 help for it. Now let’s have look at
CDS view in which we have generated value help. Highlighting annotations which are important in both
CDS views.
CDS view used for Value help association

1. CDSview used for Value help association

@AbapCatalog.sqlViewName: ZXXXXX //SQL View


Name
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Analytics.dataCategory: #DIMENSION
@VDM.viewType: #BASIC
@Search.searchable: true
@EndUserText.label: Value Help
define view ZCDS_XXXXX_Value_Help select from tXXXX // CDSView
Name and Source Table
association [0..1] to ZCDS_XXXXX_TEXT as _TEXT CDSView
from which we will fetch text value
on $projection.OrderType= _TEXT.OrderType
{
@Search.defaultSearchElement: true
key aXXXXas OrderType,
//Association
TEXT
}

CDS view for Text

2. CDSview for Text

@AbapCatalog.sqlViewName: ZXXXXTEXT1
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #BASIC
@ObjectModel.dataCategory: #TEXT
@Search.searchable: true
@EndUserText.label: Value Help Text
define view ZCDS_XXXXX_TEXTas select from tXXX01 // CDSView to
generate text
{
key aXXXXas OrderType, //Key Field
@Semantics.text: true
@Search.defaultSearchElement: true
@Search.fuzzinessThreshold: 0.8
txt as OrderTypeText //Text Field
} where spras= 'E'

Important note

If we define the txt field as Key in the CDS view, then the text will not appear in the F4 help.
define view ZCDS_XXXXX_TEXTas select from tXXX01 // CDSView to
generate text
{
key aXXXXas OrderType, //Key Field
@Semantics.text: true
@Search.defaultSearchElement: true
@Search.fuzzinessThreshold: 0.8
Key txtas OrderTypeText //Text Field
as Key
}

In the below screenshot, only keys are appearing. Text is missing in F4 help as we have defined txt field as
Key.

Conclusion: ABAP CDS views are helpful to build user-friendly reports. We can allow users to have single
selection, multiple selection or range when the user executes those reports via any UI5 application.

References:

SAP Help Portal –Link

Consumption Annotations – Link

Object Model Annotations – Link

Consumption Filter –Link

FollowLikeRSS Feed
Alert Moderator
Assigned Tags

SAP S/4HANA Embedded Analytics


#cdsAnnotations
#CDSparameters
#cdstext
#CDSVIEWS
#f4help
#valuehelp

View more...
Similar Blog Posts
ABAP CDS Views: Optional parameters in CDS View
By Yogen Patil June 03, 2021
ABAP CDS Views: Default values in parameters
By Yogen Patil June 03, 2021
Predefined Virtual Data Model as an example for understanding the difference of CDS View type
By Masaaki Arai Oct 18, 2018
Related Questions
CDS View F4 help - AnalyticsDetails.query.display #KEY_TEXT not working for parameters
By Christian Müller Mar 10, 2022
Passing multiple values in an input parameter for CDS views
By Vidhatha Ramakrishna Appikonda Jun 24, 2020
Text Value not Appearing in F4 Help of Input Parameter in Consumption CDS View
By Shilpi MajumdarSep 05, 2021
9 Comments
You must be logged in to comment or reply to a post.

KJ 911
June 16, 2021 at 4:28 pm

Excellent! Thank you very much for the information, it has worked perfectly for me.

However, I have a doubt, is it possible that when showing the aid values, it only ...
shows me the values that are written or are within the execution of the query.

Currently help values show all values from the master table.

Thank you!
Like 0
Share

Abhishek Chanders
August 6, 2021 at 8:46 am

Great Post.

I am having an issue with the last part. I tried to display only the key in the f4 help and hide the text.
by making it as a Key. But it is not working for me. In RSRT it is working as expected, but in
FIORI Query Browser, the Text is still displaying. The values in the Key field are copied to the
Text Field and it is showing the same values in both Key and Text Columns in F4. Let me know if
Is there any other solution for this?
Thank You
Like 0
Share

Yogen Patil
Blog Post Author
August 26, 2021 at 8:32 am
Remove association of text view from CDS view which is linked to generate input help.
Like 0
Share

Mamatha Krishna
February 23, 2022 at 5:49 pm
Helpful blog. Thank you !!
Like 1
Share

Yogen Patil
Blog Post Author
March 4, 2022 at 11:42 am
Thank You
Like 0
Share

Joseph BERTHE
March 3, 2022 at 3:51 pm

Hello, very helpful, thank you.

I have an issue regarding my F4 Value Help. When I try to search on the key field, it is OK, but when
I want to search on Text field, nothing happened. Is it a restriction or is there any annotations to
make it possible?

The OData query seems to be fine:

GET Idtf?$skip=0&$top=10&$filter=startswith(IdtfText,%27L%27)

Regards,

Joseph
Like 1
Share
Yogen Patil
Blog Post Author
March 4, 2022 at 11:41 am

Hi Joseph,

F4 help will work with Text as well. Please check if you are using all annotations mentioned.
above.

Regards,

Yogendra
Like 0
Share

Maxine Chin
March 23, 2022 at 10:05 PM

Hi Yogendra,

Thank you so much.

It's so constructive, a great guide!

Cheers,

Max

Like 0
Share

Yogen Patil
Blog Post Author
April 29, 2022 at 2:21 pm
Thank You

You might also like