Friday 11 November 2022

Create CDS Value Help or F4 help for In App Field Custom Fields

I was searching for different blogs for this F4 help but unfortunately couldn’t find a detailed blog on this. So, I felt to start writing the same for all technical developers.

For creation of CDS view we have 3 main interface view to be created.

Step 1.

First create a CDS view for Text table.

Use Object model annotations like @ObjectModel.representativeKey, @ObjectModel.dataCategory, @ObjectModel.usageType.dataClass, @ObjectModel.usageType.serviceQuality, @ObjectModel.usageType.sizeCategory, @ObjectModel.supportedCapabilities.

herewith I have also added the CDS view

CDS Value, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials
Figure 1: TEXT CDS View- Basic View

Data Preview

CDS Value, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials
Figure 2: Data Preview on the Text View

Adding the following code for reference.

@AbapCatalog.sqlViewName: 'ZICOUNTRYTEXT'
@ClientHandling.algorithm: #SESSION_VARIABLE
@ObjectModel.representativeKey: 'Land1'
@ObjectModel.dataCategory: #TEXT
@ObjectModel.usageType.dataClass: #CUSTOMIZING
@ObjectModel.usageType.serviceQuality: #X
@ObjectModel.usageType.sizeCategory: #S
@ObjectModel.supportedCapabilities: [#SQL_DATA_SOURCE,#CDS_MODELING_DATA_SOURCE,#CDS_MODELING_ASSOCIATION_TARGET,#LANGUAGE_DEPENDENT_TEXT]
@Search.searchable: true
@VDM.viewType: #BASIC
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Country Text'
define view ZI_countrytext 
as select from t005t 
{
@Semantics.language: true
    key spras as Spras,
    key land1 as Land1,
    
    @Semantics.text: true
      @Search.defaultSearchElement: true
    landx as Landx
}

Step 2.

Then associate the text view with Data table.

CDS Value, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials
Figure 3: Data Help View

Data preview for Help.

CDS Value, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials
Figure 4: Data Preview

Adding the following code for reference.

@AbapCatalog.sqlViewName: 'ZICOUNTRY'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Country Help'

@ClientHandling.algorithm: #SESSION_VARIABLE
@ObjectModel.representativeKey: 'Land1'
@ObjectModel.sapObjectNodeType.name: 'Land1'
@ObjectModel.usageType.dataClass: #CUSTOMIZING
@ObjectModel.usageType.serviceQuality: #A
@ObjectModel.usageType.sizeCategory: #S
@ObjectModel.supportedCapabilities: [#CDS_MODELING_ASSOCIATION_TARGET, #CDS_MODELING_DATA_SOURCE, #SQL_DATA_SOURCE]
@VDM.viewType: #BASIC
define view ZI_country
  as select from t005
  association [0..*] to ZI_countrytext as _countrytext on $projection.Land1 = _countrytext.Land1
 
{
      @ObjectModel.text.association: '_countrytext'
      @Search.defaultSearchElement: true
  key t005.land1 as Land1,
      _countrytext // Make association public
}
 
Step 3.

Then finally access the help data as VH simply by fetching data from Value Help.

Use these following annotations in header

@ObjectModel.dataCategory: #VALUE_HELP
@ObjectModel.usageType.dataClass: #CUSTOMIZING
@ObjectModel.usageType.serviceQuality: #A
@ObjectModel.usageType.sizeCategory: #S
@ObjectModel.supportedCapabilities

And add @ObjectModel.text.association at the item level to refer data as Help view to given field. Add association value from previous view alias for reference.

CDS Value, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials
Figure 5: Value Help CDS View

Data Preview

CDS Value, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Materials
Figure 6: Data Preview

Code for above Value help is added below.

@AbapCatalog.sqlViewName: 'ZIDESTCOUNTRYVH'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Destination country Value Help'
@ClientHandling.algorithm: #SESSION_VARIABLE
@ObjectModel.dataCategory: #VALUE_HELP
@ObjectModel.usageType.dataClass: #CUSTOMIZING
@ObjectModel.usageType.serviceQuality: #A
@ObjectModel.usageType.sizeCategory: #S
@ObjectModel.supportedCapabilities: [#CDS_MODELING_ASSOCIATION_TARGET, #CDS_MODELING_DATA_SOURCE, #SQL_DATA_SOURCE, #VALUE_HELP_PROVIDER, #SEARCHABLE_ENTITY]
@Search.searchable: true
@VDM.viewType: #BASIC
define view ZI_DestcountryVH 
as select from ZI_country 
{
 @ObjectModel.text.association: '_countrytext'
      @Search.defaultSearchElement: true
      key Land1,
      /* Associations */
      _countrytext
    
}

To use it as Value help for In APP custom Fields you need to release the view (Path: Windows -> Show View -> Properties).

And finally, we can have multiple usage of these Help View for Fiori applications like Query browser in analytics, or Fiori Tile in UI5, In App Extension in BTP.

Source: sap.com

No comments:

Post a Comment