问题描述
在字符串模板中使用新的 COND
语法时,我发现了一个奇怪的行为。这是关于字符串长度默认设置。看起来字符串的长度将始终默认为 THEN
之后的内容,即使不满足条件也是如此。
检查以下代码!
REPORT zzz。
类别lcl_main定义最终创建私有。
公共部分。
类别方法:
主要。
ENDCLASS。
类别lcl_main实施。
方法主要。
DATA(l_bool)= abap_true。
DATA(l_v_line)= | {COND#(当l_bool最初是'AAA'否则是'BBBB')} |。
DATA(l_v_line2)= | {COND#(当l_bool最初是'AAA'否则是'BBBB')WIDTH = 4} |。
DATA(l_v_line3)= | {COND#(当l_bool最初是'AAA'ELSE'BBBB'}} |。
DATA(l_v_line4)= | {COND#(当l_bool不是最初的,然后是 BBBB,否则为 AAA))||。
WRITE /:l_v_line,l_v_line2,l_v_line3,l_v_line4。
终结法。
ENDCLASS。
选择开始。
lcl_main => main()。
输出
BBB
BBB·
BBBB
BBBB
即使条件评估为false,前两个变量 l_v_line
和 l_v_line2
也会被截断。如果我在 l_v_line3
中的 AAA
之后放置空格,那就可以了。在 THEN
之后将 BBBB
放在 l_v_line4
之后可以解决此问题。 / p>
我的问题是:此行为在SAP文档中是否有记录?我找不到任何线索可以导致我这么做。
I have spotted a strange behaviour of new COND
syntax when used inside a string template. It is about string length defaulting. It looks like the length of the string will be defaulted always to what stands after THEN
even if the condition is not met.
Check out the following piece of code!
REPORT zzz.
CLASS lcl_main DEFINITION FINAL CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS:
main.
ENDCLASS.
CLASS lcl_main IMPLEMENTATION.
METHOD main.
DATA(l_bool) = abap_true.
DATA(l_v_line) = |{ COND #( WHEN l_bool IS INITIAL THEN 'AAA' ELSE 'BBBB' ) }|.
DATA(l_v_line2) = |{ COND #( WHEN l_bool IS INITIAL THEN 'AAA' ELSE 'BBBB' ) WIDTH = 4 }|.
DATA(l_v_line3) = |{ COND #( WHEN l_bool IS INITIAL THEN 'AAA ' ELSE 'BBBB' ) }|.
DATA(l_v_line4) = |{ COND #( WHEN l_bool IS NOT INITIAL THEN 'BBBB' ELSE 'AAA' ) }|.
WRITE /: l_v_line, l_v_line2, l_v_line3, l_v_line4.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
lcl_main=>main( ).
The output
BBB
BBB·
BBBB
BBBB
The first two variables l_v_line
and l_v_line2
are truncated even if the condition evaluates to false. If I put space after AAA
in l_v_line3
then it is OK. Putting BBBB
after THEN
for l_v_line4
solves the problem.
My question is: is this behaviour documented anywhere in SAP documentation? I could not find any clues that would have led me to it.
这篇关于使用字符串模板和新的COND语法的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!