如何检查报告是否有翻译?
How to check if a report has translations or not?
我有一份报告,我将其翻译成不同的语言,但现在我已将其移至我无权编写翻译的系统中。
这样,报告只能以英文显示:如果用户以另一种语言访问系统,则所有文本符号都不起作用。
考虑到这一点,是否可以在 load-of-program
事件中写一些东西来检查翻译是否存在,如果不存在,将 SY-LANGU
设置为英语?
到目前为止,我有一个简单的 if sy-langu <> 'E'. sy-langu = 'E'. endif.
("E" 英文)
很好用,不过不管怎样,我还是想有个办法看看有没有翻译,然后再设置成英文。
文本符号是 Text Elements 的一部分,后者是程序多语言文本池的一部分。
1) 使用 READ TEXTPOOL
获取另一种语言的文本元素:
"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) 使用辅助语言或使用 SET LANGUAGE
更改文本元素的语言,如 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."
解决方案
如果使用第二语言不满意,请使用此代码:
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
(第二语言zcsa/second_language
)查看配置文件参数。
使用 if sy-subrc <> 0
而不是 if lines( lt_text_symbols ) = 0.
因为在其他一些情况下,如果 lt_text_symbols
包含 READ TEXTPOOL
之前的内容,则其内容不如果请求的语言中没有文本池,则清除。
在 LOAD-OF-PROGRAM
事件中,更喜欢使用 sy-repid
而不是 sy-cprog
,尽管从技术上讲它们在那一刻包含相同的内容,因为后者有另一个 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."
不要改变sy-langu
的值,dixit System Fields:
"they should be used only for reads"
如果要更改 sy-langu
,请使用 SET LOCALE LANGUAGE。它还有其他作用,请仔细阅读文档。 不要将它与设置语言混淆。
我有一份报告,我将其翻译成不同的语言,但现在我已将其移至我无权编写翻译的系统中。
这样,报告只能以英文显示:如果用户以另一种语言访问系统,则所有文本符号都不起作用。
考虑到这一点,是否可以在 load-of-program
事件中写一些东西来检查翻译是否存在,如果不存在,将 SY-LANGU
设置为英语?
到目前为止,我有一个简单的 if sy-langu <> 'E'. sy-langu = 'E'. endif.
("E" 英文)
很好用,不过不管怎样,我还是想有个办法看看有没有翻译,然后再设置成英文。
文本符号是 Text Elements 的一部分,后者是程序多语言文本池的一部分。
1) 使用 READ TEXTPOOL
获取另一种语言的文本元素:
"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) 使用辅助语言或使用 SET LANGUAGE
更改文本元素的语言,如 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."
解决方案
如果使用第二语言不满意,请使用此代码:
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
(第二语言zcsa/second_language
)查看配置文件参数。 使用
if sy-subrc <> 0
而不是if lines( lt_text_symbols ) = 0.
因为在其他一些情况下,如果lt_text_symbols
包含READ TEXTPOOL
之前的内容,则其内容不如果请求的语言中没有文本池,则清除。在
LOAD-OF-PROGRAM
事件中,更喜欢使用sy-repid
而不是sy-cprog
,尽管从技术上讲它们在那一刻包含相同的内容,因为后者有另一个 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."
不要改变
sy-langu
的值,dixit System Fields:"they should be used only for reads"
如果要更改
sy-langu
,请使用 SET LOCALE LANGUAGE。它还有其他作用,请仔细阅读文档。 不要将它与设置语言混淆。