Using Translatable Text in ABAP

Objectives

After completing this lesson, you will be able to:

  • Describe the translation process for ABAP developments
  • Use text elements for making developments translatable

Translation of ABAP Developments

Some ABAP development objects contain text which could be displayed on the user interface (UI) of an application. In the RESTful Application Programming Model (RAP), for example, the following texts appear on the UI:

  • Labels and headers from annotations in data definitions and metadata extensions
  • Labels from data elements
  • Messages from message classes

These texts need to be different for end users who start the app with different logon languages.

Note
In ABAP Development Tools, you find the original language of a development object on the Properties Tab below the editor view.

Of course, one cannot expect that the developer is able to provide the texts in every different languages. Watch this video to explore how ABAP development deals with different languages.

Text Pools and Text Elements

As discussed, language-dependent texts in data elements, data definitions, metadata extensions, message classes, and so on, are translatable by default. But what about texts in the ABAP source code? Are they translatable by default too?

The answer is no, literals are not translatable! The content of literals is always the same, independent from the logon language of the user.

If literals contain language-dependent text, and if this text reaches the UI, at some point you must replace the literals with text symbols.

Text Symbols

Text symbols, sometimes also referred to as text elements, are stored in the text pool of global ABAP classes.

A text symbol is identified by a three character ID, which has to be unique within the text pool. The ID of a text symbol consists of digits, letters or a combination of both. Text symbol IDs are not case-sensitive. In the text pool editor they are always displayed in upper case.

In our example, the text pool contains a text symbol 001 and a text symbol HAU.

Note
Do not confuse text IDs with message IDs. For messages in message classes only digits are allowed.

Every text symbol defines a text in the original language of the ABAP class. The technical limit for the text length is 255 characters. In addition to this technical limit, a semantical maximum length has to be defined for each text symbol. The maximum length has to lie between the actual length and the technical limit.

In our example, the text symbol HAU has an actual length of 12 and a maximum length of 30.

Caution
The maximum length defines a hard limit for the translator. It should be significantly higher than the actual length to avoid the need for cryptic abbreviations in translated text elements.

There are two ways to access a text symbols in ABAP:

  • Standalone, that is with text, followed by a hyphen, and the text ID
  • Attached to a text literal, that is with the ID inside a pair of brackets immediately after a text literal.

In the second variant the text literal is used as a type of fallback. If the text symbol exists in the currently loaded text pool, then the content of the text symbol is used instead of the literal, otherwise the literal is used.

Note
To avoid confusion, the text of the text symbol and the text in the literal should always match. The "Extended Program Check (SLIN)" in ATC contains a check of character strings. This check issues a warning if the literal and the text symbol are different.

After the translation of the text symbols, the ABAP runtime uses the text that fits the logon language of the user.

How to Use Quick Fixes for Text Symbols

Prerequisites

You have created a global class (suggested name ZCL_##_TEXT_ELEMENTS, where ## stands for your group number) which implements the interface IF_OO_ADT_CLASSRUN.

You opened the class in ADT and copied the following code into the implementation of method IF_OO_ADT_CLASSRUN~MAIN:

Code snippet

   out->write(  TEXT-001          ).
   out->write( 'How are you'(hau) ).
Expand

Although you can edit the text pool manually, it is much easier to create and maintain text symbols using quickfixes in the ABAP editor. Watch this demonstration to learn how to use quick fixes for text symbols.

Log in to track your progress & complete quizzes