简体   繁体   English

ABAP SQL 保留或填充尾随空格

[英]ABAP SQL preserve OR pad trailing spaces

I am trying to find a way to preserve a space within SQL concatenation.我试图找到一种方法来保留 SQL 串联中的空间。

For context: A table I am selecting from a table with a single concatenated key column.对于上下文:我从具有单个串联键列的表中选择的表。 Concatenated keys respect spaces.连接的键尊重空格。 Example: BUKRS(4) = 'XYZ ' , WERKS(4) = 'ABCD' is represented as key XYZ ABCD .示例: BUKRS(4) = 'XYZ ' , WERKS(4) = 'ABCD'表示为键XYZ ABCD

I am trying to form the same value in SQL, but it seems like ABAP SQL auto-trims all trailing spaces.我试图在 SQL 中形成相同的值,但似乎 ABAP SQL 自动修剪所有尾随空格。

Select concat( rpad( tvko~bukrs, 4, (' ') ), t001w~werks ) as key, datab, datbi 
    from t001w 
       inner join tvko on tvko~vkorg  = t001w~vkorg
       left  join ztab on ztab~key = concat( rpad( tvko~bukrs, 4, (' ') ), t001w~werks ) "This is why I need the concat

    
  • rpad( tvko~bukrs, 4, ' ' ) in this example returns XYZ , instead of XYZ , which leads to concatenated value being XYZABCD , rather than XYZ ABCD . rpad( tvko~bukrs, 4, ' ' )在这个例子中返回XYZ ,而不是XYZ ,这导致串联值是XYZABCD ,而不是XYZ ABCD
  • lpad seems to work just fine (returning XYZ ), which leads me to believe I'm doing something wrong. lpad似乎工作得很好(返回XYZ ),这让我相信我做错了什么。
  • SQL functions don't accept string literals or variables (which preserve spaces in the same circumstances in ABAP) as they are non-elementary types. SQL 函数不接受字符串文字或变量(在 ABAP 的相同情况下保留空格),因为它们是非基本类型。

Is there any way to pad/preserve the spaces in ABAP SQL (without pulling data and doing it in application server)?有什么方法可以填充/保留 ABAP SQL 中的空格(无需提取数据并在应用程序服务器中执行)?

The trailing spaces seem to be ignored in OpenSQL/ABAP SQL, as they are with ABAP fixed-length character variables.尾随空格在 OpenSQL/ABAP SQL 中似乎被忽略了,因为它们与 ABAP 固定长度字符变量一样。

I simplified your example to extract the line Walldorf plant :我简化了您的示例以提取Walldorf plant行:

T001W 几行几列

These ones don't work (no line returned):这些不起作用(没有返回行):

SELECT * FROM t001w
    WHERE concat( 'Walldorf ' , 'plant' ) = t001w~name1
    INTO TABLE @DATA(itab_1).

SELECT * FROM t001w
    WHERE concat( rpad( 'Walldorf', 1, ' ' ), 'plant' ) = t001w~name1
    INTO TABLE @DATA(itab_2).

This one works, using concat_with_space :这个有效,使用concat_with_space

SELECT * FROM t001w
    WHERE concat_with_space( 'Walldorf', 'plant', 1 ) = t001w~name1
    INTO TABLE @DATA(itab_3).

General information: ABAP documentation - SQL string functions一般信息: ABAP 文档 - SQL 字符串函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM