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

Replace # with space

Former Member
0 Likes
4,665

Hi,

I want to replace '#' with space in a string. I used the below statement.

REPLACE ALL OCCURRENCES OF '#' IN p_text WITH ''.

REPLACE ALL OCCURRENCES OF '##' IN p_text WITH ''.

And it is working fine in Development system. But the same statement is not working properly in Quality and Production.

Replace all statement ends up in sy-subrc = 4 in quality and production. Hence I tried with the below statement.

FIND str IN gtext.

IF sy-subrc = 0.

REPLACE ALL OCCURRENCES OF str IN gtext WITH ' '.

ENDIF.

In this case also, it is working fine in Development. But in Quality, the Find statement ends up in sy-subrc = 4.

Please suggest me some points to resolve this issue.

Thanks in Advance.

Regards,

Vimala

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,260

Hi Vimenen,

I tried with the code below:

DATA: p_text(40) TYPE c VALUE 'A#B#C#D#E'.

BREAK-POINT.

REPLACE ALL OCCURRENCES OF '#' IN p_text WITH ''.

WRITE:/12 p_text.

and I got the outpur ABCD.

Therefore I think the problem is with the data in p_text. Please check it.

Regards,

Md Ziauddin.

19 REPLIES 19
Read only

former_member209217
Active Contributor
0 Likes
3,260

Hi,

I guess there might be problem while populating p_text in quality system.Check whether the string is populated correctly in p_text in Quality system.Debug the code once.

Regards,

Lakshman.

Read only

Former Member
0 Likes
3,261

Hi Vimenen,

I tried with the code below:

DATA: p_text(40) TYPE c VALUE 'A#B#C#D#E'.

BREAK-POINT.

REPLACE ALL OCCURRENCES OF '#' IN p_text WITH ''.

WRITE:/12 p_text.

and I got the outpur ABCD.

Therefore I think the problem is with the data in p_text. Please check it.

Regards,

Md Ziauddin.

Read only

0 Likes
3,260

Sorry, I got the outpur ABCDE.

Read only

0 Likes
3,260

Hi,

Thanks for your replies. For me also, the replace statement works fine. It is exactly replacing the '#' with space in Development server. But the problem is in the Quality system. It is not replacing in Quality and Production.

Moreover, the replace # with space is working fine in Quality for few documents and not for few documents.

Regards,

Vimala P

Read only

0 Likes
3,260

Hi Vimenen

Have you tried in debug if the data is correct.........if is really the replace statement that

not work or if are other statements?

Best regards

Marco

Edited by: Menegazzo Marco on May 18, 2010 11:56 AM

Read only

0 Likes
3,260

Reason may be that for few documents p_text is populating correctly and for few documents there might be null values

and '#' characters migh not be there .

Just debug the logic used for filling p_text .

Regards,

Lakshman.

Read only

0 Likes
3,260

Hi,

I tried debugging and I could see the value in P_text with '#'. The replace statement and even the Find statement couldn't recognize the '#' in p_text in Quality.

And I mentioned it is working fine for few and not working for few documents. In both the cases, the p_text is having '#' symbols.

Regards,

Vimala P

Read only

0 Likes
3,260

Hi,

did you check in debugger if the value # is in hex 23 ?

regards, Dieter

Read only

0 Likes
3,260

Hi,

How to check whether the # is in hex 23 in debugging? Please reply.

Regards,

Vimala P

Read only

0 Likes
3,260

Hi

when you're debugging double click in the variable....in view choose VAR_TABULAR_ASCII_HEX

regards

Marco

Read only

0 Likes
3,260

Hello,

Do you mean u2018#u2019 by horizontal tab?

If yes, then

Could you please try with cl_abap_char_utilities=>horizontal_tab instead of u2018#u2019 ?

Means intead of REPLACE '#' IN gtext WITH ' '

Try with REPLACE cl_abap_char_utilities=>horizontal_tab IN gtext WITH ' '

Regards,

Selva K.

Read only

0 Likes
3,260

Hi,

I checked for the hexadecimal value. Actually am trying to replace '##'. In Quality, for few document manually posted, the hexadecimal value for '##' is 2323 for which the replace statement works fine. For few document posted through batch is having the hexadecimal value as '0D0A' for '##' for them the replace statement is not working. Could you suggest me the better way to replace this kind of strings.

Regards,

Vimala P

Read only

0 Likes
3,260

Hi,

maybe, the # character is for a carry return. Sometimes, I found it at the end of string when I download a file from server to an abap program.

Then, for clear the #, do it like this.

1st, declare a variable:

data: v_var(1) type C value CL_ABAP_CHAR_UTILITIES=>CR_LF.

2nd, look for the # character in a string:

if file_structure+n(1) = v_var.

clear file_structure+n(1).

endif.

If you need to clear two "#", I think it works as well..., then declare 2 positions var.

Hope this help you!

Read only

0 Likes
3,260

Vimala,

You could try and use the following statement instead to see if you get better results:

TRANSLATE p_text USING '# '.

Read only

3,260

Hi Vimenen,

here a short code, try it:


DATA: STR TYPE STRING.
*
CONSTANTS:
   CON_NEWL TYPE ABAP_CHAR1 " 0A
            VALUE CL_ABAP_CHAR_UTILITIES=>NEWLINE,
   CON_CRLF TYPE ABAP_CR_LF  " 0D0A
            VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF,
   CON_TAB  TYPE ABAP_CHAR1 " 09
            VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
*
CONCATENATE 'A' CON_NEWL
            'B' CON_CRLF
            'C' CON_TAB
            'D' INTO STR.
*
WRITE: / STR.
REPLACE CON_NEWL WITH SPACE INTO STR.
REPLACE CON_CRLF WITH SPACE INTO STR.
REPLACE CON_TAB  WITH SPACE INTO STR.
WRITE: / STR.

regards, Dieter

Read only

0 Likes
3,260

Hi,

Thanks for all the replies. My issue was resolved using the below piece of code.

REPLACE ALL OCCURRENCES OF '#' IN p_text WITH ''.

REPLACE cl_abap_char_utilities=>horizontal_tab IN p_text WITH ''.

REPLACE cl_abap_char_utilities=>cr_lf IN p_text WITH ''.

Regards,

Vimala P

Read only

0 Likes
3,260

Just keep in mind: In printout and in debugger, any # hash character just means this is not a printable character. so the replacement of '#' is useless in almost all cases.

In text files, the most common non-printable characters are tab, linefeed and carriage return.

In debugger you have an icon next to the field for display that allows to switch to hexadecimal representation, at least i the classic debugger.

Regards,

Clemens

Read only

Former Member
0 Likes
3,259

Hi Vimenen.

maybe can be the presence of more then one #..so try to use this code:


REPLACE '#' IN gtext WITH ' '.

while sy-subrc eq '0'.
REPLACE '#' IN gtext WITH ' '.
endwhile.

best regards

Marco

Read only

Former Member
0 Likes
3,259

Hi Vimenen,

Not sure how you are populating your string field.

'#' character appears for any unrecognized character.

If you data conatains any currency or quantity field first convert them to char fields using write to char (u can do F1 on write for syntax of wrtie to ) and then move it to string field.

If you are not populating the string youself but getting from soem parameter then may be u need to check types of incoming parameter & then may do some data conversion before moving it to a string variable.

Hope this helps

cheers