Standard service - a fixed amount of work that is performed at a fixed price.  Post Service

  

Monday, 18 February 2019 02:30

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

Written by 
Rate this item
(0 votes)

SAPYard has the best practical tutorials onSAP OData and also onSAP ABAP for S/4HANA. SAPYard exercises feature on the 1st

page of Google searches for both these topics. Now, our team is focusing on reigning the Core Data Services. As of date, we have 13 articles on CDS. 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 aCDS object.

  • EndUserText.label

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

  • EndUserText.quickinfo

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

Also Read : ADT Eclipse/HANA Studio for ABAPers

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 textsdefined 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.

Also Check How I created my first OData Service in SAP?

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 isused for this purpose. This T-Code will execute ABAP program RS_LXE_RECORD_TORDER or RS_LXE_LOG_EXPORT depending on theversion 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 –

Also Explore : How to Consume Custom OData in SAPUI5 Application

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.

I hope you found this article useful. The SE63 and the steps to put the translated text into transport remains the same in SAP ECC. Many developers do not get opportunity to work in translated objects if their clients do not have global presence. So, for them, this might act as a reference page to come back in future if they need it.

In the coming days, I would write articles on Associations in CDS. So, please stay tuned.

Your feedback if our motivation. Please leave your thoughts, both positive and not so positive.

We have a very active Telegram (App) SAP Technical Group with more than 3850+ SAP Technical Practitioners from 6 Continents of the SAP World. Please join it using below link.
Telegram SAP Technical Discuss Group. You need to install the Telegram App first on your mobile device. Once you have it on your mobile, you can join the group and also access it from the Web on your computer and laptop.

Free Step by Step Core Data Services Exercises

Read 125 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Support

Follow us on