on 05-10-2004 10:17 AM
Hi,
can somebody advise me of how to concatenate strings so that trailing space is not ignored? For example I have two variabvles 'ABC ' and 'XYZ ' I need the result to be 'ABC XYZ '. By default trailing spaces are removed, how to retain them?
thanks,
erki
There is a much easier way.
CONCATENATE `abc ` 'xyz' INTO target.
Using the `` form will keep trailing space characters!
++bcm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The backquote ` is used to delimit a STRING literal whereas the single quote ' is used to delimit a text field literal.
The string literals retain any trailing spaces, the text literals do not.
But the STRING type was not available in 3.1I and therefore this method won't work for you :o(
Cheers,
John
You can also achieve the result you require with a deep data structure. Either group your elements in the order in which they should be concatenated or move the data into the elements into a separate structure. To access the concatenated result, use the higher level data name:
report z_jac_test.
data: begin of concat,
element1(4) value 'ABC ',
element2(4) value 'DEF ',
end of concat.
write: / '[' no-gap, concat no-gap, ']' no-gap.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Erki,
see the docu, this is the example from the docu:
Examples DATA: ONE(10) VALUE 'John',
TWO(3) VALUE 'F.',
THREE(10) VALUE 'Kennedy',
NAME(20).
CONCATENATE ONE TWO THREE INTO NAME SEPARATED BY SPACE.
Then, NAME has the value "John F. Kennedy".
Regards,
Dirk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think Erki's point was that the result he is after, given your example is:
"John F. Kennedy "
The problem with the CONCATENATE statement, as Erki has discovered, is that it truncates trailing spaces. I think the easiest way to get around this problem is be replacing the space with a weirdo character (like a tab) that will not otherwise appear in the input.
Following code is untested and not unicode compliant.
DATA:
BEGIN OF replacechars,
space(1) TYPE C,
tab(1) TYPE X VALUE '09',
END OF replacechars.
DATA:
BEGIN OF replacecharsreverse,
tab(1) TYPE X VALUE '09',
space(1) TYPE C,
END OF replacecharsreverse.
TRANSLATE ONE USING replacechars.
TRANSLATE TWO USING replacechars.
TRANSLATE THREE USING replacechars.
CONCATENATE ONE TWO THREE INTO NAME.
TRANSLATE NAME USING replacecharsreverse.
Alternatively, in this situation, the length of the input field is most likely known, so the same could simply be achieved with (or slightly more complicated logic using dynamic offset specifications determined using the DESCRIBE statement):
NAME+0(10) = ONE.
NAME+10(3) = TWO.
NAME+13(20) = THREE.
Scott
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.