Vous êtes sur la page 1sur 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 SAP Embedded Analytics world ABAP Core Data Service Views 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 help ABAP CDS view.

Dans le monde SAP Embedded Analytics, les vues ABAP Core Data Service sont également appelées vues
ABAP CDS. Les vues ABAP CDS sont définies au-dessus des tables de base de données existantes. Qui
peut ensuite être utilisé dans l'application UI5 à des fins de création de rapports. Lorsque nous traitons des
rapports, nous avons besoin de certains paramètres de sélection pour restreindre les données afin d'obtenir
la sortie attendue. Qui fonctionne comme écran de sélection dans l'application UI5. Une telle fonctionnalité
peut être obtenue avec l'aide de la vue ABAP CDS.

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

1. Scenario 1: CDS View With parameter

Method 1:

Here we will be creating CDS view with parameter.

@AbapCatalog.sqlViewName: 'Z_XXXX_V1' // SQL 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 composite view

{
@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 above example we are getting pop up to provide inputs, but we are not getting F4 help for inputs. This
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.valuehelpDefination: 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 // CDS View Name


with parameters
@Consumption.valueHelpDefinition: // Annotation to link
parameter with CDS view 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
@AnalyticsDetails.query.display: #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 same as 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_XXXX as select from ZCDS_I_XXXX
{
@AnalyticsDetails.query.axis: #ROWS
key aXYZ,
@Consumption.Filter.mandatory : True // Annotation for input
prompts
@Consumption.valueHelp : '_ValueHelp.aXXXX' // Annotation to link with
CDS view which will generate text
@EndUserText.label: 'Service Order Type'
@AnalyticsDetails.query.axis: #ROWS
@AnalyticsDetails.query.display: #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 association name and ‘aXXXX’ is field on which we are generating value help.

Let’s have a look at composite View.

Here we have created association with 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 as _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.

Alternative way to achieve this will be as follow –

i)  In composite view use @ObjectModel.Text.Association annotation & provide direct mapping to Text
View.

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

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

2. Scenario 2: Parameters with multiple Selection

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

@Consumption.filter.multipleSelections: true
Sample Code –

define view ZCDS_C_XXXX as select from ZCDS_I_XXXX


{
@AnalyticsDetails.query.axis: #ROWS
key aXYZ,
@Consumption.Filter.mandatory : True
@Consumption.Filter.MultipleSelections : True // Annotation to
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 scenario where we need option to have range selection screen, then we can use below annotation
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. CDS view 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 as select from tXXXX // CDS View
Name and Source Table
association [0..1] to ZCDS_XXXXX_TEXT as _TEXT // CDS View
from which we will fetch text value
on $projection.OrderType = _TEXT.OrderType
{
@Search.defaultSearchElement: true
key aXXXX as OrderType,
//Association
_TEXT
}

CDS view for Text

2. CDS view 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_TEXT as select from tXXX01 // CDS View to
generate text
{
key aXXXX as 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 txt field as Key in CDS view then text will not appear in F4 help.
define view ZCDS_XXXXX_TEXT as select from tXXX01 // CDS View to
generate text
{
key aXXXX as OrderType, // Key Field
@Semantics.text: true
@Search.defaultSearchElement: true
@Search.fuzzinessThreshold: 0.8
Key txt as OrderTypeText // Text Field
as Key
}

In 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 user to have single
selection, multiple selection or range when user execute 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 PatilJun 03, 2021
 ABAP CDS Views: Default values in parameters
By Yogen PatilJun 03, 2021
 Predefined Virtual Data Model as example for understanding difference of CDS View type
By Masaaki AraiOct 18, 2018
Related Questions
 CDS View F4 help - AnalyticsDetails.query.display #KEY_TEXT not working for parameters
By Christian MüllerMar 10, 2022
 Passing multiple values in an input parameter for CDS views
By Vidhatha Ramakrishna AppikondaJun 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 on 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 perfect for me.

However, i have a doubt, it will be possible that at the time of showing the aid values, it only
shows me the values that are written or are within the execution of the query.

Currently help values shows 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 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
there is 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 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 seams 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

Vous aimerez peut-être aussi