CDS Part 14. ABAP Annotations for Translatable Texts in CDS Views

Today, we present how to exploit Annotations for translations in CDS.

For novice, Annotation is just an extension to the CDS SQL. In the beginning of the CDS definitions, whatever you see which begins with ‘@’ is an annotation.

ABAP Annotation plays a very important role as they define technical and semantic attributes of a CDS object. They are usually evaluated for every CDS object when activated by the ABAP runtime environment.

In this article I have tried to explain in detail about the ABAP annotations for translatable texts in CDS views. We would end our article with a small ABAP Program written in ADT showing how to consume the same texts in 2 different languages (English and German). This article would act like a step by step guide to meet all the translation requirements in SAP ABAP and CDS.

Let’s begin.

EndUserText

ABAP annotations starting with EndUserText are used to define translatable semantic texts for a CDS object.

  • EndUserText.label

EndUserText.label is available as view annotation (i.e. available at CDS entity level) or as element annotation (i.e. available for individual element). The maximum length is limited to 60 characters.

  • EndUserText.quickinfo

EndUserText.quickinfo is only available as element annotation (i.e. available for individual element). The value is stored as string and can have arbitrary length.

View Annotation

Element Annotation

Translation of Annotations

The values of text annotations are stored in special tables that have language key and that are translatable. The value specified in the source code should consist of text in the original language of the CDS source code and is translated into the required languages.

Translation of CDS views is done as usual in the translatable editor (T-Code SE63). A new object type CDS view has been added to group User Interface Texts.

Please follow the below steps to translate the texts defined in the given DDL Source:

1. DDL Source whose texts need to be translated

2. Execute T-Code SE63

3. Choose ‘Short Texts’ from the toolbar

4. On the next dialog window, expand node User Interface Texts.

5. Choose and double click on sub-element DDLS CDS Views.

6. On the next dialog window, enter the name of DDL Source, the source and target language.

7. Click on Edit.

8. Enter the texts in target language specified and click on SAVE button to save the values.

Adding CDS Texts Translations to Transport request

Once we have saved the translations, we would require transporting them through various SAP systems in the system landscape. Unfortunately, translations are not added to TR automatically and need to be added manually.

T-Code SLXT is used for this purpose. This T-Code will execute ABAP program RS_LXE_RECORD_TORDER or RS_LXE_LOG_EXPORT depending on the version of SAP you are using.

Execute T-Code SLXT.

Enter the selection as follows and execute –

On execution, Texts would be saved in the created TR –

Dynamic Access to Annotation Texts

The methods of global class CL_DD_DDL_ANNOTATION_SERVICE reads the texts as specified by an input parameter for the language.

If no language is passed to the input parameter, the logon language is used as the default.

Use Case 1) Source Language (English in this case)

Output:

Case 2) Target Language (German in this case)

Output

Note – If no text is found for the language, the secondary language in AS ABAP is used.