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: 

Searching strings for Non printable characters???

former_member445996
Participant
0 Kudos

Hi All,

I have a string which contains some non-printable characters such as tab, Carriage return/Line feed, etc, etc. How can I search for these characters in a string. I have tried to search them with SEARCH command using hex values but nothing is found. Is there a way to accomplish this? Any FM that removes all non-printable characters from the string?

Thanks in advance.

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, you can search using the values from CL_ABAP_CHAR_UTILITIES. There are values for other non-printable characters as well.

For example, you want to search for a tab.

search str for CL_ABAP_CHAR_UTILITIES=>horizontal_tab.

Regards,

Rich Heilman

8 REPLIES 8

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, you can search using the values from CL_ABAP_CHAR_UTILITIES. There are values for other non-printable characters as well.

For example, you want to search for a tab.

search str for CL_ABAP_CHAR_UTILITIES=>horizontal_tab.

Regards,

Rich Heilman

0 Kudos

HI Anurag,

Use Class CL_ABAP_CHAR_UTILITIES

Method horizontal_tab

i.e, CL_ABAP_CHAR_UTILITIES=>horizontal_tab

thanks Rich for that correction ....

Regards,

Santosh

Message was edited by: Santosh Kumar P

0 Kudos

Santosh, to be clear, this is not a FM, it is a class.

Regards,

Rich Heilman

0 Kudos

Class CL_ABAP_CHAR_UTILITIES has these attributes:

HORIZONTAL_TAB

VERTICAL_TAB

NEWLINE

CR_LF

FORM_FEED

BACKSPACE

You can refer to any of them by prefixing 'CL_ABAP_CHAR_UTILITIES=>'.

But if you are not sure of the non-printable values you wish to eliminate maybe you can work out what IS printable and remove everything else?

eg,

  • first line of keyboard......

DATA first_LINE(30) VALUE

'`1234567890-=~!@#$%^&*()_+'.

DATA SECOND_LINE(30) VALUE

'qwertyuiop[]\QWERTYUIOP{}|'.

DATA THIRD_LINE(30) VALUE

'asdfghjkl;''ASDFGHJKL:"'.

DATA FOURTH_LINE(30) VALUE

'zxcvbnm,./ZXCVBNM<>?'.

data printable(150).

concatenate first_line second_line third_line fourth_line

into printable.

condense printable.

data string(120).

data hex type c.

field-symbols <hex> type x.

assign hex to <hex> casting.

*you probably don't need 'casting' in 4.6

<hex> = '09'.

concatenate first_line third_line fourth_line into string separated by hex.

write:/ string.

do.

*end when all characters are printable

if string co printable. exit. endif

string+sy-fdpos(1) = ''.

enddo.

write:/ string.

0 Kudos

hi Anurag,

Check this out

Reward if it helps

Regards,

Santosh

0 Kudos

You can use the hex values then. For example, horizontal tab is 09.

constants: tab type x value '09'.

REgards,

Rich Heilman

former_member445996
Participant
0 Kudos

Thanks guys,

This class is not available to us as we are on 4.6 where as this one is availabe 4.7 and up.

Any other ideas/suggestions?

Thanks

former_member445996
Participant
0 Kudos

Thanks to everyone for their ideas and suggestions.