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

String concatenate Issue (space is not adding)

former_member295881
Contributor
0 Likes
1,900

Hello Experts,

I've wrote a custom string function to remove commas in Names or address fields. The following code works fine if there is NO SPACE in the given string as it remove all the commas. (i.e D,J,UICE = DJUICE). However, issue happens if I provide a string like this (D,J JE,FF S,AM ,D,ONE.). Instead of making it (DJ JEFF SAM DONE)  it makes it like this (DJJEFFSAMDONE).

Any clue how I can convert it into my desired output, which is DJ JEFF SAM DONE.

Here is my code.

FORM REMOVE_COMMAS  CHANGING  pgv_change_text   TYPE string.

DATA: i type i,
       gv_length type i,
       stest(100),
       sakt(1),
       str1(100).

CONSTANTS: c_deli TYPE c value   ' '.

"Check length
gv_length = strlen( pgv_change_text ).

   WHILE i < gv_length.
     sakt = pgv_change_text+i(1).
      if sakt = ','.
        sakt = ''.
      elseif sakt = ' '.
        sakt = c_deli.
      endif.
      "shift stest.
      concatenate str1 sakt into str1.

      i = i + 1.
   ENDWHILE.
   pgv_change_text = str1.


ENDFORM.                 

Many thanks in advance.

1 ACCEPTED SOLUTION
Read only

Shafiq_Rehman1
Active Contributor
0 Likes
1,838

Try this:

DATA: str TYPE string.

str = 'D,J JE,FF S,AM ,D,ONE'.

REPLACE ALL OCCURRENCES OF ',' IN str WITH ''.

WRITE str.

10 REPLIES 10
Read only

Former Member
0 Likes
1,838

How about replace , with space.  Then split on space.  Then concatenate separated by space.

Neal

Read only

Former Member
0 Likes
1,838

hello.

use

concatenate str1 sakt into str1 separated by space.

Regards

Read only

0 Likes
1,838

Thanks for both of your inputs. I've already tried SEPERATED BY SPACE but then everything get's wrong and I get D J J E F F S A M D O N E. I don't want this output what I need is this ->DJ JEFF SAM DONE.

Read only

Former Member
0 Likes
1,838

Use REPLACE statement, as Neal Wilhite comment.

REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF] pattern

        IN [section_of] dobj WITH new

          [IN {CHARACTER|BYTE} MODE]

        [replace_options].

Example:

REPLACE ',' IN pgv_change_text WITH space.

Read only

sreenadh_mv
Explorer
0 Likes
1,838

Hello,

Change constant value C_deli to a spl character e.g. '&' then use replace.

DATA: i type i,

       gv_length type i,
       stest(100),
       sakt(1),
       str1(100).

CONSTANTS: c_deli TYPE c value   ' '.

"Check length
gv_length = strlen( pgv_change_text ).

for code refer to this link http://scn.sap.com/thread/1222123

Cheers!

Sree

Read only

Shafiq_Rehman1
Active Contributor
0 Likes
1,839

Try this:

DATA: str TYPE string.

str = 'D,J JE,FF S,AM ,D,ONE'.

REPLACE ALL OCCURRENCES OF ',' IN str WITH ''.

WRITE str.

Read only

0 Likes
1,838

Many thanks Rehman, your suggestion resolved my issue.

Read only

former_member196490
Active Participant
0 Likes
1,838

Use 'REPLACE ALL OCCURRENCES OF ',' <string> with ' '

Neha

Read only

Former Member
0 Likes
1,838

This code will give you the desired output.

FORM REMOVE_COMMAS  CHANGING  pgv_change_text   TYPE string.

DATA: i TYPE i,

        gv_length TYPE i,

        stest(100),

        sakt(1),

        str1(100),

        lv_text(80) TYPE c.

CONSTANTS: c_deli TYPE c VALUE   '_'.

i = 0.

"Check length

gv_length = strlen( pgv_change_text ).

BREAK-POINT.

WHILE i < gv_length.

   sakt = pgv_change_text+i(1).

   IF sakt = ','.

     sakt = ''.

   ELSEIF sakt = ' '.

     sakt = c_deli.

   ENDIF.

   "shift stest.

   CONCATENATE str1 sakt INTO str1.

   i = i + 1.

ENDWHILE.

i = 0.

lv_text = str1.

WHILE i < gv_length.

   CLEAR sakt.

   sakt = lv_text+i(1).

   IF sakt = c_deli.

     REPLACE '_' WITH ' ' INTO lv_text.

   ENDIF.

   i = i + 1.

ENDWHILE.

pgv_change_text = lv_text.

ENDFORM


Cheers!

Read only

Former Member
0 Likes
1,838

Hi,

Try this code using REPLACE keyword.

FORM REMOVE_COMMAS  CHANGING  pgv_change_text   TYPE string.

DATA: i type i,
       gv_length type i,
       stest(100),
       sakt(1),
       str1(100).

CONSTANTS: c_deli TYPE c value   ' '.

REPLACE ALL OCCURRENCES OF ',' IN pgv_change_text WITH ''.


ENDFORM.

Thats it.

Regards

Satish