Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenating strings with trailing whitespace

Former Member
0 Kudos

Hi All,

I have a String 'ABC XYZ ' which has a trailing space character. This string has to be concatenated with another string '1234'. The expected output is

'ABC XYZ 1234'

I'm using the concatenate function but the whitespace after XYZ is getting truncated and the output is coming as 'ABC XYZ1234'. I tried concatenating a whitespace also

CONCATENATE 'ABC XYZ' ' ' '1234'INTO temp.

but the result is the same. Does someone have a solution?

Thanks,

Sandeep

9 REPLIES 9

Former Member
0 Kudos

Use

CONCATENATE 'ABC' 'XYZ' '1234' INTO v_zzz SEPERATED BY SPACE.

OR Try this

CONSTANTS: c_abc(7) VALUE 'ABC XYZ',
           c_1234(4) VALUE '1234'.

DATA: v_xyz(12) TYPE C.
Then write 

CONCATENATE c_abc c_1234 INTO v_xyz <b>SEPERATED BY SPACE</b>.

This will do.

Kindly reward points and close the thread.

Former Member
0 Kudos

Hi,

The CONCATENATE statement combines two or more separate strings into one.

CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].

This statement concatenates the character fields <c1> to <cn> and assigns the result to <c>. <b>The system ignores spaces at the end of the individual source strings</b>.

<b>The addition SEPARATED BY <s> allows you to specify a character field <s> which is placed in its defined length between the individual fields.</b>

If the result fits into <c>, SY-SUBRC is set to 0. However, if the result has to be truncated, SY-SUBRC is set to 4.

DATA: C1(10) VALUE 'Sum',

C2(3) VALUE 'mer',

C3(5) VALUE 'holi ',

C4(10) VALUE 'day',

C5(30),

SEP(3) VALUE ' - '.

CONCATENATE C1 C2 C3 C4 INTO C5.

WRITE C5.

CONCATENATE C1 C2 C3 C4 INTO C5 SEPARATED BY SEP.

WRITE / C5.

Output:

Summerholiday

Sum - mer - holi - day

In C1 to C5, the trailing blanks are ignored. The separator SEP retains them.

Thanks,

Ruthra

Former Member
0 Kudos

HI Sandeep,

try this

CONCATENATE 'ABC XYZ' '1234'INTO TEMP SEPARATED BY SPACE.

regards

kingshuk

0 Kudos

Hi Sandeep,

to preserve the white spaces you can do the following

concatenate <b>`</b>This <b>`</b> <b>`</b>is<b>`</b> <b>`</b> test.<b>`</b> into <var>.

Please note that i have not used single quote , instead used <b>`</b> .

Regards

Raja

Former Member
0 Kudos

Kindly reward if ur problem got solved or get back with queries.

rainer_hbenthal
Active Contributor
0 Kudos

I'm astonished that no one mentioned the "in character mode" to make the program unicode capable.

0 Kudos

If you do not specify the mode, character string processing is performed.

Regards

Raja

0 Kudos

In unicode you have to specify either in character mode or in byte mode. So why not make programs for the future and just add these three words. to do it or not is not a discussiuon worth, just do it and your programmes part of life will be easier.

Former Member
0 Kudos

I think this might help u out.

<b>Concatenating Character Strings</b>

The CONCATENATE statement combines two or more separate strings into one.

CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].

This statement concatenates the character fields <c1> to <cn> and assigns the result to <c>. The

system ignores spaces at the end of the individual source strings.

The addition SEPARATED BY <s> allows you to specify a character field <s> which is placed in

its defined length between the individual fields.

If the result fits into <c>, SY-SUBRC is set to 0. However, if the result has to be truncated, SYSUBRC

is set to 4.

DATA: C1(10) VALUE 'Sum',

C2(3) VALUE 'mer',

C3(5) VALUE 'holi ',

C4(10) VALUE 'day',

C5(30),

SEP(3) VALUE ' - '.

CONCATENATE C1 C2 C3 C4 INTO C5.

WRITE C5.

CONCATENATE C1 C2 C3 C4 INTO C5 SEPARATED BY SEP.

WRITE / C5.

Output:

Summerholiday

Sum - mer - holi - day

In C1 to C5, the trailing blanks are ignored. The separator SEP retains them.

<b>Splitting Character Strings</b>

To split a character string into two or more smaller strings, use the SPLIT statement as follows:

SPLIT <c> AT <del> INTO <c1> ... <cn>.

The system searches the field <c> for the separator <del>. The parts before and after the

separator are placed in the target fields <c1> ... <cn>.

To place all fragments in different target fields, you must specify enough target fields. Otherwise,

the last target field is filled with the rest of the field <c> and still contains delimiters.

If all target fields are long enough and no fragment has to be truncated, SY-SUBRC is set to 0.

Otherwise it is set to 4.

DATA: STRING(60),

P1(20) VALUE '++++++++++++++++++++',

P2(20) VALUE '++++++++++++++++++++',

P3(20) VALUE '++++++++++++++++++++',

P4(20) VALUE '++++++++++++++++++++',

DEL(3) VALUE '***'.

STRING = ' Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5'.

WRITE STRING.

SPLIT STRING AT DEL INTO P1 P2 P3 P4.

WRITE / P1.

WRITE / P2.

WRITE / P3.

WRITE / P4.

The output appears as follows:

Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5

Part 1

Part 2

Part 3

Part 4 *** Part 5

Note that the contents of the fields P1 ...P4 are totally overwritten and that they are

filled out with trailing blanks.

You can also split a string into the individual lines of an internal table as follows:

SPLIT <c> AT <del> INTO TABLE <itab>.

The system adds a new line to the internal table <itab> for each part of the string.