使用字符串模板和新 COND 语法的奇怪行为 [英] Strange behaviour using string templates and new COND syntax

查看:32
本文介绍了使用字符串模板和新 COND 语法的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在字符串模板中使用时,我发现了新的 COND 语法的奇怪行为.这是关于字符串长度默认值.看起来字符串的长度将始终默认为 THEN 后面的内容,即使不满足条件.

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.

看看下面的一段代码!

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( ).

输出

BBB
BBB·
BBBB
BBBB

前两个变量 l_v_linel_v_line2 被截断,即使条件计算结果为假.如果我在 l_v_line3 中的 AAA 后面加上空格,那么就可以了.将 BBBB 放在 THEN 之后为 l_v_line4 解决问题.

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.

我的问题是:这种行为是否记录在 SAP 文档的任何地方?我找不到任何可以引导我找到它的线索.

My question is: is this behaviour documented anywhere in SAP documentation? I could not find any clues that would have led me to it.

推荐答案

来自 ABAP 文档

# 字符作为操作数类型的符号.

The # character as a symbol for the operand type.

...

如果操作数类型不能完全识别,一个带有静态可识别类型必须在第一个之后指定那么.然后使用这种类型.

If the operand type is not fully identifiable, an operand with a statically identifiable type must be specified after the first THEN. This type is then used.

这篇关于使用字符串模板和新 COND 语法的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆