Reputation: 925
I have a report which I wrote translations to different languages, but now I have moved it to a system in which I don't have authorizations to write translations.
This way, the report works only in English: all the Text Symbols don't work if the user accesses the system in another language.
With this in mind, is it possible to write something in the load-of-program
event to check if translations exist or not, and if not, set SY-LANGU
to English?
By now, I have a simple if sy-langu <> 'E'. sy-langu = 'E'. endif.
("E" for English)
It works fine, but regardless, I'd still like to have a way to find out if there are translations, and only then set it to English.
Upvotes: 3
Views: 2233
Reputation: 925
Text Symbols are part of Text Elements which are part of multilingual Text Pools of the program.
1) Use READ TEXTPOOL
to get the Text Elements in another language:
"READ TEXTPOOL. This statement reads the text elements of the text pool of the language specified in lang and the program specified in prog from the repository and places them into the internal table itab."
data itab type standard table of textpool.
READ TEXTPOOL prog INTO itab LANGUAGE lang.
2) Either use the secondary language or use SET LANGUAGE
to change the language of the text elements as explained in the ABAP documentation:
"When a program is loaded into an internal session, the text elements of the text pool of the logon language are imported by default. If this text pool does not exist, the text pool of the secondary language in AS ABAP is used. If none of these text pools exists, an empty text pool without text elements is loaded."
"When the program is executed, the text pool of a different language can be loaded using the statement SET LANGUAGE."
If using the secondary language is not satisfying, use this code:
LOAD-OF-PROGRAM.
constants lc_english type sylangu value `E`.
data lt_text_symbols type standard table of textpool.
read textpool sy-repid into lt_text_symbols language sy-langu.
if sy-subrc <> 0.
SET LANGUAGE lc_english.
endif.
PS:
RZ11
(secondary language zcsa/second_language
).Get used with if sy-subrc <> 0
rather than if lines( lt_text_symbols ) = 0.
because in some other situations, if lt_text_symbols
contains something before READ TEXTPOOL
, its content is not cleared if there's no Text Pool in the requested language.
Inside the LOAD-OF-PROGRAM
event, prefer using sy-repid
over sy-cprog
, although technically they contain the same at that moment, because the latter has another meaning:
"In externally called procedures, the name of the calling program; otherwise the name of the current program. If an externally called procedure calls another external procedure, sy-cprog contains the name of the master program, and is not set to the name of the master program of the subsequent calling program."
Don't change the value of sy-langu
, dixit System Fields:
"they should be used only for reads"
If you want to change sy-langu
, use SET LOCALE LANGUAGE. It has other effects, read the documentation carefully. Don't confuse it with SET LANGUAGE.
Upvotes: 6