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: 

Replace Comma with Space Not Working

Former Member
0 Kudos

Any idea why the following code prints "SAPInc" on my system? I was expecting "SAP Inc".

Thanks for any help.

REPORT zz_temp.

DATA: l_v_char2(30)  TYPE c VALUE 'SAP,Inc'.

REPLACE FIRST OCCURRENCE OF ',' in l_v_char2 with space.

WRITE: / l_v_char2.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Jerry,

Use this


REPORT zz_temp.

DATA: l_v_char2(30)  TYPE c VALUE 'SAP,Inc'.

TRANSLATE l_v_char2 USING ', '.


WRITE: / l_v_char2.

Cheers

Aneesh.

9 REPLIES 9

Former Member
0 Kudos

There should be a space after comma.

DATA: l_v_char2(30) TYPE c VALUE 'SAP, Inc'.

Thanks,

Srinivas

Former Member
0 Kudos

Jerry,

Use this


REPORT zz_temp.

DATA: l_v_char2(30)  TYPE c VALUE 'SAP,Inc'.

TRANSLATE l_v_char2 USING ', '.


WRITE: / l_v_char2.

Cheers

Aneesh.

Former Member
0 Kudos

Hi,

Can you try with LENGTH len addition

REPLACE FIRST OCCURRENCE OF ',' in l_v_char2 with space LENGTH 1.

As per SAP REPLACE is Obsolete in laltest version

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb33cc358411d1829f0000e829fbfe/content.htm

Regards,

Atish

ferry_lianto
Active Contributor
0 Kudos

Hi,

Just use TRANSLATE statement instead.


DATA: L_V_CHAR2(30)  TYPE C VALUE 'SAP,Inc'.
                                                                        
TRANSLATE L_V_CHAR2 USING ', '.
                                                                        
WRITE: / L_V_CHAR2.

Regards,

Ferry Lianto

0 Kudos

Thanks to all. It just bugs me that it seems like it should work since it is syntactically correct.

0 Kudos

If that bothers you, try:

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

ABAP doesn't seem to handle spaces well.

Rob

0 Kudos

Stop! You're torturing me!!

0 Kudos

Yes - I've had a good day

Rob

Former Member
0 Kudos

Check below code. it is printing as you need.

REPORT zz_temp.

DATA: l_v_char2(30) TYPE c VALUE 'SAP,Inc'.

replace ',' with space into l_v_char2.

WRITE: / l_v_char2.