I am trying to find a way to preserve a space within SQL concatenation.
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
.
I am trying to form the same value in SQL, but it seems like ABAP SQL auto-trims all trailing spaces.
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
. lpad
seems to work just fine (returning XYZ
), which leads me to believe I'm doing something wrong. Is there any way to pad/preserve the spaces in ABAP SQL (without pulling data and doing it in application server)?
The trailing spaces seem to be ignored in OpenSQL/ABAP SQL, as they are with ABAP fixed-length character variables.
I simplified your example to extract the line Walldorf plant
:
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
:
SELECT * FROM t001w
WHERE concat_with_space( 'Walldorf', 'plant', 1 ) = t001w~name1
INTO TABLE @DATA(itab_3).
General information: ABAP documentation - SQL string functions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.