Application Development and Automation 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: 
Read only

CONCATENATE STRING

Former Member
0 Likes
1,702

hi experts,

i have one problem when concatenate string.

{ for example:

condition 1: values of f1 = thane

f2 = mumbai

f3 = delhi

concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

then f = thane , mumbai , delhi ,

this is ok.

condition 2: values of f1 = thane,

f2 = mumbai,

f3 = delhi,

concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

then f = thane, , mumbai, , delhi, ,

but i want f = thane , mumbai , delhi ,

condition 3: values of f1 = thane

f2 =

f3 = delhi,

concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

then f = thane , , delhi, ,

but i want f = thane , delhi ,

}

give me idea

Thanks.

14 REPLIES 14
Read only

Former Member
0 Likes
1,657

well for condition 2 remove the commas before tha concatenate.

in condition 3 after your concantenate do following:

search f for '., ,.'.

if something is found the position of your pattern in string is beeing publishen in sy-fdpos.

the do:

data: lv_fdpos type syst-fdpos.

lv_fdpos = sy-fdpos + 3.

f = f(sy-fdpos) + f+lvfdpos.

Read only

Former Member
0 Likes
1,657

>

> hi experts,

> i have one problem when concatenate string.

> { for example:

>

> condition 1: values of f1 = thane

> f2 = mumbai

> f3 = delhi

> concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

> then f = thane , mumbai , delhi ,

> this is ok.

>

> condition 2: values of f1 = thane,

> f2 = mumbai,

> f3 = delhi,

> concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

> then f = thane, , mumbai, , delhi, ,

> but i want f = thane , mumbai , delhi ,

>

> condition 3: values of f1 = thane

> f2 =

> f3 = delhi,

> concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

> then f = thane , , delhi, ,

> but i want f = thane , delhi ,

> }

> give me idea

>

> Thanks.

FOR condition 2:

values of f1 = thane,

f2 = mumbai,

f3 = delhi,

concatenate f1 f2 f3 into f separated by ','.

then f = thane, mumbai, delhi,

Read only

Former Member
0 Likes
1,657

Use CONDENSE Statement with f.

CONDENSE F.

Edited by: Amresh kumar Panda on Apr 16, 2009 4:59 PM

Read only

Former Member
0 Likes
1,657

>

> hi experts,

> i have one problem when concatenate string.

> { for example:

>

> condition 1: values of f1 = thane

> f2 = mumbai

> f3 = delhi

> concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

> then f = thane , mumbai , delhi ,

> this is ok.

>

> condition 2: values of f1 = thane,

> f2 = mumbai,

> f3 = delhi,

> concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

> then f = thane, , mumbai, , delhi, ,

> but i want f = thane , mumbai , delhi ,

>

> condition 3: values of f1 = thane

> f2 =

> f3 = delhi,

> concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

> then f = thane , , delhi, ,

> but i want f = thane , delhi ,

> }

> give me idea

>

> Thanks.

Hi Ramayya,


 condition 1: values of f1 = thane
                               f2 = mumbai
                               f3 = delhi
 concatenate f1 ',' f2 ',' f3 ',' into f separated by space.
* then f = thane , mumbai , delhi ,
 *this is ok.
> 
 condition 2: values of f1 = thane,
                                f2 = mumbai,
                                f3 = delhi,
 concatenate f1 ',' f2 ',' f3 ',' into f separated by space.   " Use zseperated by ',' instead of Space
 then f = thane, , mumbai, , delhi, ,
 but i want f = thane , mumbai , delhi ,
 
 condition 3: values of f1 = thane
                                f2 = 
                               f3 = delhi,
 concatenate f1 ',' f2 ',' f3 ',' into f separated by space.
 then f = thane ,  , delhi, ,
 but i want f = thane ,  delhi ,

try this 
condense f.

use this syntax to acheive the thane , delhi..



replace ',,' with ',' into f.               "Use this syntax it will work

regards,

Prabhudas

Read only

0 Likes
1,657

Hi.

I would do this within a loop, where you check if the string you would like to add to your list is in the correct format. like this: 'delphi'

- check if initial

- check if ',' in the string

In addition you are able to do this for as many strings as you want to.

Regards, Clemens

Read only

Former Member
0 Likes
1,657

DATA :F1(9),F2(9),F3(9),F(30).

f1 = 'thane'.

f2 = ''.

f3 = 'delhi'.

IF F1 <> '' AND F2 <> '' AND F3 <> ''.

concatenate f1 f2 f3 into f separated by ','.

ELSEIF F1 <> '' AND F2 = '' AND F3 <> ''.

concatenate f1 F3 into f separated by ','.

ENDIF.

WRITE f .

TRY THIS ..IT WILL SOLVE UR PROBLEM.

Read only

Former Member
0 Likes
1,657

Hi,

Check the following code, it is working fine.

ata: thane(5) type c value 'thane',

mumbai(6) type c value 'mumbai',

f(15) type c.

concatenate thane ',' mumbai into f SEPARATED BY space.

condense f.

write f.

Please let me know if there are any further issues on this

Read only

Former Member
0 Likes
1,657

hi,

it very simple

use this code i will get it ..

condition 2: values of f1 = thane,

f2 = mumbai.

f3 = delhi.

concatenate f1 ',' f2 ',' f3 ',' into f separated by space.

then f = thane, mumbai, delhi,

but i want f = thane , mumbai , delhi ,

Read only

Former Member
0 Likes
1,657

Hello Ramya,

This will solve thee second part of your question


IF f CA ',,' .
  REPLACE ',' IN f  WITH ''.
ENDIF.

Explanation :

CA - Contains Any

Regards,

K.Sibi

Please revert back if the answer is not the expected .

Read only

0 Likes
1,657

well that wont work, this will remove exactly ONE comma.

you´d need this addition "ALL OCCURRENCES" of statement replace.

But still it wont wor cause then you wont have any commas at all in your string afterwards.

Read only

0 Likes
1,657

Hello Florian Kemmer ,

I would like to add a point to your reply.We can replace all occurences of "',," with "," this would solve the problem rite?.I have tried to do that .Please correct me if I am wrong .

Regards,

K.Sibi

Read only

Former Member
0 Likes
1,657

Try this:

Split the concatenate statement.


DATA f1(20) TYPE c VALUE 'Thane'.
DATA f2(20) TYPE c VALUE 'Mumbai'.
DATA f3(20) TYPE c. VALUE 'Vashi'.

DATA result(100) TYPE c.

IF f1 IS NOT INITIAL.
  CONCATENATE f1 ' , ' INTO f1.
ENDIF.

IF f2 IS NOT INITIAL.
  CONCATENATE f2 ' , ' INTO f2.
ENDIF.

IF f3 IS NOT INITIAL.
  CONCATENATE f3 ' , ' INTO f3.
ENDIF.

CONCATENATE f1 f2 f3 INTO result SEPARATED BY space.

WRITE result.

regards,

Advait

Read only

Former Member
0 Likes
1,657

USE THESE STATEMENTS BEFORE YOU CONDITION STARTS.

SHIFT F1 RIGHT DELETING TRAILING ',' .
SHIFT F2 RIGHT DELETING TRAILING ',' .
SHIFT F3 RIGHT DELETING TRAILING ',' .

This will give you output as you get it in the first case, for every condition.

Regards,

Lalit Mohan Gupta.

Read only

Former Member
0 Likes
1,657

ok