Using the CDS text association, you can define the relationship between an element (field) and its corresponding texts or descriptions. The texts are usually language-dependent and are displayed in the end user's language. If you annotate an element with a text association (as described below), the associated text or description field is added as a field to the referencing entity. At runtime, this field is read from the database and filtered by the logon language of the OData consumer automatically. It is not necessary to use session properties or view parameters in your CDS view.
To retrieve texts by direct use of text associations, proceed as follows:
The following set of CDS annotations is relevant when defining text views:
Relevant Annotations:
The following annotation is required at the view level:
Annotation and Value |
Effect |
---|---|
@ObjectModel.dataCategory: #TEXT | Indicates that the annotated CDS view represents texts
(defines a text provider view) Note Usually one key element
is used to specify the language!
|
The following annotations are required at the view element level to annotate the language key element and the text elements from the view’s element list:
Annotation and Values |
Effect |
---|---|
@Semantics.language: true | The annotated element identifies the language field. |
@Semantics.text: true |
Identifies view elements as text elements (fields
pointing to a textual description)
Note
In general, you can annotate more than one view field as a text field. However, only the first annotated field will be considered in the text consumer view for OData exposure. |
Example
The listing below implements a sample text view. Its entity is named I_UnitOfMeasureText and uses database table T006A as its data source. In this example, the two fields MSEHT (UnitName) and MSEHL (UnitLongName) are annotated as text fields with @Semantics.text: true. However, note that - in OData exposure scenarios - the first text element listed in the annotation array will be handled as a descriptive text of the annotated field in the consumer view.
... @ObjectModel.dataCategory: #TEXT @EndUserText.label: 'Unit of Measure Text' define view I_UnitOfMeasureText as select from T006A as TextProvider { key TextProvider.msehi as UnitOfMeasure, @Semantics.language: true -- identifies the language key TextProvider.spras as Language, @Semantics.text: true -- identifies the first text field for names TextProvider.mseht as UnitName @Semantics.text: true -- identifies the second text field TextProvider.msehl as UnitLongName }
The following CDS annotation is relevant when creating text associations:
Annotation and Values |
Effect |
---|---|
@ObjectModel.text.association: '<_AssocToTextProvider>' | Name of an association with a text view that provides descriptive texts for the annotated element. In other words: the annotation indicates that the description for the annotated element is available using the text association <_AssocToTextProvider>. |
Example
The view I_UnitOfMeasure in the listing below serves as a consumer for the text provider that has been implemented in the previous step. For this purpose, the association _Text with the target view UnitOfMeasureText is defined. To indicate the field for which a text should be made available through the association _Text, the annotation @ObjectModel.text.association is added. Note that only the first text element (UnitName) from the text provider, which is annotated with @Semantics.text: true, will be considered for OData exposure.
... define view I_UnitOfMeasure as select from T006 as UnitOfMeasure association [0..*] to I_UnitOfMeasureText as _Text on $projection.UnitOfMeasure = _Text.UnitOfMeasure { ... @ObjectModel.text.association: '_Text' key msehi as UnitOfMeasure, _Text }