我有一份报告,我用不同的语言编写了翻译,但现在我将其移至一个我无权编写翻译的系统中。
这样,报告只能以英语运行:如果用户以另一种语言访问系统,则所有文本符号均不起作用。
考虑到这一点,是否可以在load-of-program事件中编写一些内容以检查翻译是否存在,如果不存在,则设置SY-LANGU为英语?
现在,我有一个简单的if sy-langu <> 'E'. sy-langu = 'E'. endif.(英语为“ E”)
它可以正常工作,但是无论如何,我仍然希望有一种方法来找出是否有翻译,然后将其设置为英语。
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.
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
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.