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: 

CONACTENATE WITH SAPCES - Points will be awarded.

adnanmaqbool
Contributor
0 Kudos

Dear Guys

I want to concatenate the field having spaces e.g Name field of length 100 having a Name of 10 char and remaining 90 characters are SAPCES. I want to concate nate the fields with spaces. While when I am trying to concatenate it, its truncating all the white spaces.

Any Solution Pls

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

try this it may work

DATA : TEXT(15) VALUE '1.234',

text2(20) value '3456',

res(35),

spaces(15),

len type i.

compute len = strlen( text ).

len = 15 - len. " since text is 15 length

concatenate text text2 into res separated by spaces(len).

WRITE : / res.

regards

shiba dutta

12 REPLIES 12

Former Member
0 Kudos

Hi Adnan,

To add spaces, use SEPARATED BY SPACE

Hope this helps,.

0 Kudos

Hello Adnan,

SEPARATED BY SPACE will add only one space.

You could try to use offsets:

CLEAR target_field.

MOVE name to target_field+0(100).

MOVE name2 to target_field+100(100).

Regards

Monika

adnanmaqbool
Contributor
0 Kudos

SEPARATED BY SPACE add sapce between two fields while in my case I want sapces within my Field e.g "Name " "Name2 ".

0 Kudos

Hi Adnan

This code may help for you.

constants : l_space type char1 value ' '.

" While typing the value for the constants after the first quote, put your num lock on and Hold the ALT key and type 0160 from the numpad. This will will provide you with ASCII value of space. Then you release the ALT key and put the ending quote.

Then you can say,

Name+10(90) = l_space.

Reward points if useful !!

~Ranganath

0 Kudos

Try this code,

data : name type string value ' abc' , count type i value 40.

while count ne 0.

concatenate name '*' into name separated by space.

count = count - 1.

endwhile.

replace all occurrences of '*' in str with space.

write : name.

write : name.

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

Try like this:

DATA: C1(20) 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.

Regards,

Bhaskar

Former Member
0 Kudos

hi adnan,

use statement WRITE.

DATA : name(100).

DATA : test(5) VALUE 'TESTS'.

DATA : name1(100) VALUE 'NAME1'.

WRITE name1 TO name.

WRITE: name, test.

this will utilize entire length for writing.

Former Member
0 Kudos

If you assign the field name during declaration as like the below...

data:

w_name(100) type c value 'NAMENAME12 <90 spaces> ' .

And then you concatenate other field your requirement is possible.

Check this sample code....

DATA: t1(10) TYPE c VALUE 'We <10 spaces> ',

t2(10) TYPE c VALUE 'have',

t3(10) TYPE c VALUE 'all',

t4(10) TYPE c VALUE 'the',

t5(10) TYPE c VALUE 'time',

t6(10) TYPE c VALUE 'in',

t7(10) TYPE c VALUE 'the',

t8(10) TYPE c VALUE 'world',

result TYPE string.

CONCATENATE t1 t2 t3 t4 t5 t6 t7 t8

INTO result.

CONCATENATE t1 t2 t3 t4 t5 t6 t7 t8

INTO result SEPARATED BY space.

Regards,

Pavan

Former Member
0 Kudos

Hi Adnan,

Try this code:


data: name_final(100) type c.
data: name1(10) type c.
data: name2(10) type c.

name1 = 'good boy'.
name2 = 'bad boy'.
name_final = name1.
write name2 to name_final+50(10).
write: name_final.

This will result in concatenating two names into one with the required space,.

change code accordingly to suit your need.

Regards,

SJ

varma_narayana
Active Contributor
0 Kudos

Hi..Adnan...

You can try using the FM STRING_INS for this..

Try this code.

REPORT ZSEL_CONCAT .

parameters: p1(10) default 'INDIA',

p2(10) DEFAULT 'TODAY'.

DATA : V_TARGET(100) TYPE C.

DATA : V_LEN TYPE I.

DATA: V_POS TYPE I.

V_POS = 0.

CALL FUNCTION 'STRING_INS'

EXPORTING

insert = P1

position = V_POS

changing

text = V_TARGET

EXCEPTIONS

INVALID_POSITION = 1

INSUFFICIENT_TEXT_LENGTH = 2

OTHERS = 3

.

DESCRIBE FIELD P1 LENGTH V_LEN IN CHARACTER MODE.

CALL FUNCTION 'STRING_INS'

EXPORTING

insert = P2

position = V_LEN

changing

text = V_TARGET

EXCEPTIONS

INVALID_POSITION = 1

INSUFFICIENT_TEXT_LENGTH = 2

OTHERS = 3

.

WRITE : / V_TARGET.

<b>Reward if Helpful</b>

Former Member
0 Kudos

try this it may work

DATA : TEXT(15) VALUE '1.234',

text2(20) value '3456',

res(35),

spaces(15),

len type i.

compute len = strlen( text ).

len = 15 - len. " since text is 15 length

concatenate text text2 into res separated by spaces(len).

WRITE : / res.

regards

shiba dutta

Former Member
0 Kudos

Hi

str = abcd .

str1 = def .

replace all occurrences of space in str with '@'.

concatenate str str1 into str2 separatred by space.

now

replace all occurrences of '@' in str2 with space.

please close this thread

kiran.M