Text Elements and Translation

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

A program that shows words to people, such as a button label, a field caption, a column heading or an error message, should not have those words typed into the code. If they are, a Spanish-speaking user sees English, and a small wording change needs a developer and a transport. ABAP solves this by keeping such texts outside the code, in named stores, and by keeping one copy per language. The code asks for a text by its number or name, and the system hands back the copy in the language the user logged on with. This page names each store, shows how a program reads from it, and explains how a translator fills in the other languages. It is written against Standard ABAP release 8.16 and ABAP for Cloud Development release 9.20 (2608). Text pools belong to classic Standard ABAP programs; text symbols and the INTO form of the MESSAGE statement are also described in the keyword documentation for ABAP for Cloud Development, where messages are maintained in ADT. The code examples below need a system with a text pool and a message class, so they are labelled "requires an SAP system; not run here".

Before you read

Key terms

  • Text element: a text kept in the text pool of a program or class instead of in its source code.

  • Text symbol: a numbered or named text element that code reads as TEXT-001.

  • Selection text: the caption shown next to an input field of a selection screen.

  • Message class: a development object that holds numbered message texts (numbers up to three digits), shared by many programs.

  • Online Text Repository: a central repository of reusable texts, opened with transaction SOTR_EDIT.

  • Logon language: the language a user picks at logon, which decides which copy of a text the program reads.

  • Translation: the work of adding the same text in another language so the system can pick the right copy.

The text pool of a program

A program of a type that supports text pools (an executable program, class pool, function pool, module pool or subroutine pool) owns a text pool: a set of texts that belongs to it and is translated with it. There is one text pool for the original language of the program and one for each translation language. The text pool holds three kinds of text elements:

  • Text symbols: general texts that the code reads, such as a caption, a title or a sentence.

  • Selection texts: captions of the parameters and select-options of a selection screen.

  • List headings: the title line and the column headings that a classic list prints on its pages (the standard page header).

A text symbol has a three-character identifier made of letters, digits or the underscore, often a number such as 001, and a length that you define in the text elements. Choose the length with the translation in mind: the official documentation points out that a translation can need more characters than the original, for example seven for the six-character English word window (Fenster in German).

Reading a text symbol

There are two ways to refer to a text symbol in the code. The first, and the one to prefer, writes the identifier after TEXT-, as if it were a component of a structure. The second writes a literal followed by the identifier in parentheses. In the second form the literal is only a fallback: it is shown if the loaded text pool has no entry with that identifier. If the plain form TEXT-001 finds no entry, it behaves like an empty single-character field, so nothing useful is shown.

The next listing is a short classic report for the Expense claims example. It needs a text pool with the entries 001 (Claim status) and 002 (No claims found), and it requires an SAP system; not run here.

REPORT zexp_claim_status.

PARAMETERS p_status TYPE zexp_claim-status DEFAULT 'OPEN'.

START-OF-SELECTION.
  " First form: the identifier after TEXT-
  WRITE: / text-001, p_status.

  SELECT COUNT(*) FROM zexp_claim WHERE status = @p_status INTO @DATA(lv_count).
  IF lv_count = 0.
    " Second form: literal with identifier; the literal is the fallback
    WRITE / 'No claims found'(002).
  ENDIF.

Source: Text Symbols

Two rules follow from this. A text symbol behaves like a constant of type c with the length defined in the text elements. And the pool is chosen by the language of the user, not of the developer: the same program shows 001 in Spanish for a Spanish logon without any change to its code, provided a Spanish text pool exists.

When a sentence contains a changing value, keep the whole sentence in one text symbol or one message and put the value in as a placeholder, because word order differs between languages and a sentence glued together from several symbols is hard to translate well.

Selection texts and list headings

A PARAMETERS or SELECT-OPTIONS statement declares a field on the selection screen. The screen shows a caption next to it. Without a selection text, the caption is the technical name, for instance P_STATUS. With a selection text, it is the readable caption in the user’s language. A selection text can also come from the ABAP Dictionary instead of the text pool; such a text is not stored in the text pool of the program.

A frame title or a free comment line on the selection screen is a plain text symbol and is written with TEXT- in the statement. The title of a frame and the text of a comment may be written as TEXT-idf with the three-character identifier of a text symbol; if that symbol does not exist, no title or comment text is shown. The next listing needs the text symbols t01 and c01, and requires an SAP system; not run here.

SELECTION-SCREEN BEGIN OF BLOCK blk_status WITH FRAME TITLE TEXT-t01.
  PARAMETERS p_status TYPE zexp_claim-status.
  SELECTION-SCREEN COMMENT /1(40) TEXT-c01.
SELECTION-SCREEN END OF BLOCK blk_status.

List headings belong to the classic list output: the text pool keeps the title bar text of the list and up to four column headings for the standard page header. A program that writes its own header uses text symbols for those words instead.

Message texts and message classes

Messages are the sentences a program shows or logs when something happens: an input is wrong, a document was posted. They are kept apart from the text pool, in a message class: a collection of messages whose short texts are stored per language in the database table T100. A message class name has at most 20 characters and a message number at most three digits; numbers from 900 to 999 are reserved for customers. A short text has at most 73 characters. Messages are maintained with the message maintenance tool in ADT or with transaction SE91. A short text can hold placeholders written &1 to &4, which the program fills in when it raises the message; the official documentation says that only the numbered form can be used in a text that will be translated, because the sentence structure may change. The same message can be used by many programs and can be changed, and translated, in one place.

A message has a type, one of A, E, I, S, W or X, and the type controls how the message behaves; how it is displayed depends on the context, and type X always causes a runtime error. The statement that sends a message is MESSAGE; the placeholders are filled with the WITH addition, up to four values. In the listing, a message class ZEXP is assumed to hold message 001 with the text "Claim &1 has &2 items". It requires an SAP system; not run here.

" Short form: type e, number 001, message class ZEXP
MESSAGE e001(zexp) WITH lv_claim_id lv_item_count.

" Dynamic form: class, type and number come from variables
MESSAGE ID 'ZEXP' TYPE 'S' NUMBER '001' WITH lv_claim_id lv_item_count
        INTO DATA(lv_text).

With INTO, the program flow is not interrupted: the short text, with its placeholders replaced, is assigned to a variable. This is the only variant of MESSAGE available in ABAP for Cloud Development. If the message is not found in the logon language, the system looks in the secondary language and then in English; if it is still missing, the message type, class and number are used as the text. A message can also be given as an object whose class implements the interface IF_T100_MESSAGE, which is how exception classes point at a message class entry.

The Online Text Repository

The Online Text Repository (OTR) is another central repository for texts, maintained with the transaction SOTR_EDIT. According to the keyword documentation, it is important in ABAP for exception texts and is also used by other frameworks. The details of its entries and of how a text is addressed are described in the in-system documentation of the OTR editor. For texts that a program shows, the two stores described above, the text pool and the message class, are the ones the keyword documentation lists as text repositories.

Choosing the language at run time

By default a program reads its texts in the logon language, the language the user chose at logon. The two stores fall back differently when that language has no copy:

  • Text pool: when the program is loaded, the text pool of the logon language is imported. If it does not exist, the text pool of the secondary language of the system is used, and if neither exists the program gets an empty text pool. The statement SET LANGUAGE can load the text pool of another language while the program runs.

  • Message: if the message is missing in the logon language, the secondary language is searched, then English, and finally the type, class and number are shown as the text.

So a half-translated program still runs, and a missing translation is not noticed until someone logs on in that language.

flowchart TD A[Program asks for text-001] --> B{Text pool of the logon language exists} B -->|yes| C[Entry shown] B -->|no| D{Text pool of the secondary language exists} D -->|yes| C D -->|no| E[Empty text pool, no text]

Source: Text Pools

A program can also read a whole text pool of another program, or in another language, with the statement READ TEXTPOOL. It fills an internal table, whose line type must correspond to the structure TEXTPOOL, with one row per text element, identified by its columns ID and KEY; sy-subrc is 4 if the program, the language or a text pool in that language does not exist. Use it for tools that list or compare texts, not for ordinary screens. It requires an SAP system; not run here.

DATA lt_texts TYPE STANDARD TABLE OF textpool WITH DEFAULT KEY.

READ TEXTPOOL 'ZEXP_CLAIM_STATUS' INTO lt_texts LANGUAGE sy-langu.
IF sy-subrc <> 0.
  " no text pool exists in that language
ENDIF.

Source: READ TEXTPOOL

Translation

Translation means adding a copy of each text in another language. The developer writes the original, in the language the object was created in, and a translator adds the others. The keyword documentation states that text elements and messages are linked to the translation tools of the system, and that a program reads the texts of the logon language by default. How the translation tools are started is described in their in-system documentation. Two habits make translation cheaper:

  • Keep each text a whole, independent sentence with the numbered placeholders inside it, never a sentence built from pieces.

  • Leave room in the length of a text symbol, because a translation can be longer than the original.

Older material you may meet

Older code and older books often differ from current ABAP in a few places that matter for this topic. Reports from before the object-oriented style write every output with WRITE and list headings; the same texts today are normally shown in a SAP Fiori app, an ALV grid or a RAP service, whose labels come from CDS annotations and data element labels instead of a report text pool. Old programs also wrote a literal followed by its number, 'Claim status'(001), everywhere, and stored long error sentences inside the code as literals; the direct TEXT-001 form and a message class are the better habits. Older code often sends messages straight to the screen, whereas the form that works in ABAP for Cloud Development is MESSAGE ... INTO with an inline declaration to capture the text.

Summary

  • Texts users read live outside the source code, in the text pool of a program, in a message class or in the OTR.

  • A text pool holds text symbols (TEXT-001), selection texts and list headings; choose the length of a text symbol with translation in mind.

  • Messages are kept in a message class, have a type, take up to four placeholders and can be sent with MESSAGE or assigned to a string with INTO; only the INTO form exists in ABAP for Cloud Development.

  • The logon language selects the copy; a text pool falls back to the secondary language and then to nothing, a message to the secondary language, English and finally its key.

References