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: 

How to get HEX 000D = 13 = CR out of a CHAR ?

former_member560074
Participant
0 Kudos

Hi ABAP Gurus,

how to get HEX 000D = 13 = <CR> out of a CHAR ?

Thank You

Martin

11 REPLIES 11

Sandra_Rossi
Active Contributor
0 Kudos

Hi Martin,

the CR character is defined by CL_ABAP_CHAR_UTILITIES=>CR_LF(1) (note that CR is the first character of the 2 of that constant)

and then you use something like FIND or SPLIT using that constant

BR

Sandra

0 Kudos

Hello Sandra,

sorry, but I really do not understand this.

Best Wishes

Martin

0 Kudos

Hello,

Example, that will write "D e a r &nbsp; M a r t i n" only because it stops at the first CR control character:


DATA l_clike TYPE c LENGTH 100.
CONCATENATE ' Dear Martin,' '...' 'Best regards,' 'Sandra'
      INTO l_clike SEPARATED BY cl_abap_char_utilities=>cr_lf(1).
DO.
  IF l_clike+sy-index(1) = cl_abap_char_utilities=>cr_lf(1).
    EXIT.
  ENDIF.
  WRITE l_clike+sy-index(1).
ENDDO.

If it's not what you expect, then please provide an example too, thanks

Sandra

0 Kudos

That is a very good example Sandra, lol

0 Kudos

Hi,

if you want to replace this character, check this:

REPORT  ZMYTEST                              .
                                                                        
data: mycharfield(20).
                                                                        
concatenate 'line1' cl_abap_char_utilities=>cr_lf(1)  'line2'
                    cl_abap_char_utilities=>cr_lf(1)  'line3'
into mycharfield.
                                                                        
write: /1 mycharfield.
                                                                        
replace all occurrences of cl_abap_char_utilities=>cr_lf(1)
in mycharfield with space.
                                                                        
write: /1 mycharfield.

Regards,

Klaus

0 Kudos

Hi Sandra, Claus,

I let run Your versions against my version for 80.000 DS in SAP/BI and yours was 10 % slower ;).

Thank You

Best Wishes

Martin

  • Conventional SAP BI Version:

DATA l_allowed_char type rsallowedchar-allowchar.

DATA count TYPE i.

IF l_allowed_char IS INITIAL.

CALL FUNCTION 'RSKC_ALLOWED_CHAR_GET'

IMPORTING

E_ALLOWED_CHAR = l_allowed_char

* E_DEFAULT_CHAR =

* E_USERDEF_CHAR =

.

ENDIF.

RESULT = SOURCE_FIELDS-SGTXT.

CLEAR count.

WHILE count < 50.

IF NOT RESULTcount(1) CO l_allowed_char.+

CLEAR RESULTcount(1).+

ENDIF.

+count = count + 1.+

ENDWHILE.

0 Kudos

Hi Martin,

Hey, we could not defend ourselves, because we had not the whole context, and I didn't even understand that you wanted a REPLACE "CR" BY "nothing" (which in fact became REPLACE "BI unauthorized chars" BY "space")!

Anyway, I don't think I can do better than your version.

Sandra

0 Kudos

Hi Sandra,

sure, but in SDN a question must be placed as simpliefied and as broken down as possible.

No one is reading more than the first line of an email .....

I got to know there is a world besides ABAL 4GL

Thank You anyhow.

Martin

0 Kudos

Hi guys,

I beleive Martin is looking for faster way to replace and remove CR value.

Try something like this:

 
  FIELD-SYMBOLS:
    <bytes> TYPE x.

  CONSTANTS:
    cr TYPE x LENGTH 2 VALUE '0D00', "Unicode CR
    rc TYPE x LENGTH 2 VALUE '2000'. "Unicode RC - Replace Char in this case SPACE

  DATA:
    result TYPE char50.

  CONCATENATE
    'THIS is a Test'
    cl_abap_char_utilities=>cr_lf
    'for Martin'
  INTO result SEPARATED BY space.

  WRITE: / result.
  ASSIGN result TO <bytes> CASTING TYPE x.
  REPLACE ALL OCCURRENCES OF cr IN <bytes> WITH rc IN BYTE MODE.
  WRITE: / result.

Regards,

Igor.

navdeep_thakur12
Explorer

Hi

check in debugging

if hex value for # is 000D

then use:

REPLACE ALL OCCURANCE OF cl_abap_char_utilities=>cr_lf(1) IN string WITH space.

if hex value is 000A

then use:

REPLACE ALL OCCURANCE OF cl_abap_char_utilities=>cr_lf+1(1) IN string WITH space.

similary you can check for HORIZONTAL_TAB, VERTICAL_TAB etc.

hope this help

Regards

0 Kudos

Hi,

This worked for me. Thanks a lot.