You are on page 1of 9

SAP FIORI USING CDS –

VALUE HELPS
- Modelled value help views
- Foreign key association

Pratik Vaidya
Welcome to another document of SAP Fiori using CDS. In this document we will have a look
at how to create value helps for an element.

Prerequisite
The application used for demonstration of this topic has been created in previous the
document – SAP Fiori using CDS – FACETS. Hence, I would strongly recommend you to go
through the below link
https://www.linkedin.com/posts/pratikvaidya9_cds-fiori-elements-facets-activity-
6778233064691703808-UFBZ

More information
For more information on this topic, do check the below link.
https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.52.3/en-
US/ce9deec2b91746f7b2f1ca4421256754.html

APPROACH 1 - Value help based on Modelled View

Requirement
Display a value help for Buyer ID

Solution

Value help provider Consumption view


view
@Consumption.valueHelpDefinition
Annotation for getting a selection field

As we can see, Buyer ID already has an F4 view attached. But clicking on it would not give us
a value help, it only gives us an ability to filter the search.
(after clicking on F4)

In order to get a value help, we need to follow the below steps.

STEP 1: Create a value help CDS


For our example, I have created the below CDS.
@AbapCatalog.sqlViewName: 'ZDEMOPARTNER'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@EndUserText.label: 'Value help for BP'

define view zc_demo_partner_vh


as select from but000
{
key partner as partner,
name_org1 as Name1
}

This CDS fetches the Partner number and Name1 from Business Partner table.
STEP 2: Use the Value help CDS, in our Consumption view
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Consumption view for sales orders'
@Metadata.allowExtensions: true // To allow metadata extensions
@VDM: { viewType:#CONSUMPTION,
usage.type: [#TRANSACTIONAL_PROCESSING_SERVICE] }
define root view entity zc_demo_salesord_pv
as projection on zr_demo_salesord_pv
{
key so_key as SalesOrderKey,
id as SalesOrderExternalId,
lifecycle_status as LifecycleStatus,
@Consumption.valueHelpDefinition: [{ entity.name: 'zc_demo_partner_vh',
entity.element: 'partner' }]
buyer_id as BuyerId,
ship_to_id as ShipTo,
...

Use the highlighted annotation to get a value help for the required field.

Output

A new tab “Search and Select” is added, earlier we only had “Define conditions”.
APPROACH 2: Value help using Foreign key association

NOTE: The examples I am creating are using Restful application programming model. I am
not sure if Foreign key association approach works in RAP, hence using screenshots from my
earlier notes for its demonstration.

Requirement 1
Creating a value help “without text”.
Here we would be creating value help for Sales organization field.

Solution

Value help provider Consumption view


view @ObjectModel.foreignkey.association

This approach is similar to the Modelled approach, only annotation used in Consumption
view is different.
Step 1- Create a value help CDS

Step 2: Use the value help view in Consumption view


Below are the differences compared to Modelled approach

• Add association to the value help provider


• Use @ObjectModel.foreignkey.association annotation
Requirement 2
Creating a value help “with text”

Solution

Text provider Value help provider view Consumption view


view
@ObjectModel.text.association @ObjectModel.foreignkey.association

This approach is similar to “Value help without text”, only difference is that a text
association comes into picture.

Step 1: Create a text provider view for our value help view.
In our case, fetch the Sales organization text from TVKOT and provide it to Sales
organization in the value help.
Note: Don’t miss the highlighted annotations.
Step 2: Create a value help CDS and use the text from the text provider CDS
Note: @Objectmodel.text.association for text association
Step 3 : Use the value help CDS in the consumption view

If you have made it this far, I hope you have understood the concepts demonstrated. Please feel free
to reach out to me if you feel any concepts have been explained incorrectly / there is more to it than
demonstrated.

More documents can be found in my LinkedIn profile https://www.linkedin.com/in/pratikvaidya9/

You might also like