08-10-2007 7:46 AM
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.
08-10-2007 9:03 AM
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
08-10-2007 7:50 AM
08-10-2007 8:00 AM
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
08-10-2007 7:52 AM
SEPARATED BY SPACE add sapce between two fields while in my case I want sapces within my Field e.g "Name " "Name2 ".
08-10-2007 8:00 AM
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
08-10-2007 8:01 AM
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.
08-10-2007 7:54 AM
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
08-10-2007 7:55 AM
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.
08-10-2007 7:56 AM
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
08-10-2007 8:34 AM
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
08-10-2007 8:59 AM
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>
08-10-2007 9:03 AM
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
08-10-2007 9:05 AM
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