cancel
Showing results for 
Search instead for 
Did you mean: 

Null character removal in sap using a function module

Former Member
0 Kudos

Little background :

1) we are using a lot of interfaces with legacy and the data in sap has null characters for example : phone#123 .

the prob is not on sap side but on bw side when i extract this data it converts to hex format and the load fails.

2) so i wrote a abap function module for the extractor which uses the function modules SRET_TEXT_TO_BINARY and SRET_BINARY_TO_TEXT and passed the variable that has the null character and replaced it with space.

3) the prob is i get null characters in a lot of fields now and i am not sure how i can pass it to SRET_BINARY_TO_TEXT OR SRET_TEXT_TO_BINARY as they are SAP standard and it takes in just a single variable. i have all my fields in a internal table .

I apologize for the the length of the message but any help is greatly appreciated.I want to know how to pass a internal table with null in all fields to a standard function module bec . The code is below :

=======================================================

CALL FUNCTION 'SRET_TEXT_TO_BINARY'

EXPORTING

TEXT = input

  • TEXT_LENGTH = -1

LAISO = '00'

  • IV_CATID = ' '

  • IV_RFC_FOR_INITIALIZE = ' '

IMPORTING

  • OUTPUT_LENGTH =

XBUFFER = v_hexa

EXCEPTIONS

FAILED = 1

OTHERS = 2

.

IF SY-SUBRC = 0.

*Replacing all NULL (X'00') values with SPACE (X'20')

REPLACE ALL OCCURRENCES OF c_null IN v_hexa WITH c_space IN BYTE MODE.

CALL FUNCTION 'SRET_BINARY_TO_TEXT'

EXPORTING

XBUFFER = v_hexa

LAISO = '00'

  • IV_CATID = ' '

  • IV_RFC_FOR_INITIALIZE = ' '

IMPORTING

  • OUTPUT_LENGTH =

TEXTBUFFER = output

EXCEPTIONS

FAILED = 1

OTHERS = 2

Accepted Solutions (0)

Answers (3)

Answers (3)

andreas_mann3
Active Contributor
0 Kudos

Hi,

try this:

data trhex(4) type x value '0020'.

translate record using trhex.

Grx Andreas

Former Member
0 Kudos

You can try the CONDENSE statement.

Regards

Elini.P

Former Member
0 Kudos

The entire code :

=======================================================

FUNCTION YFR1_CA_U_NULL_SPACE.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(INPUT) TYPE C

*" EXPORTING

*" REFERENCE(OUTPUT) TYPE C

*" EXCEPTIONS

*" LENGTH_TOO_LONG

*" FAILED

*"----


  • This function provides the functionality of replacing the NULL

  • characters with SPACE .

*----


DATA : v_hexa(100) TYPE X ,

c_space(2) TYPE X VALUE '0020' ,

c_null(2) TYPE X VALUE '0000' ,

v_length TYPE i .

COMPUTE v_length = STRLEN( input ) .

IF v_length > '100'.

RAISE length_too_long .

ENDIF .

CALL FUNCTION 'SRET_TEXT_TO_BINARY'

EXPORTING

TEXT = input

  • TEXT_LENGTH = -1

LAISO = '00'

  • IV_CATID = ' '

  • IV_RFC_FOR_INITIALIZE = ' '

IMPORTING

  • OUTPUT_LENGTH =

XBUFFER = v_hexa

EXCEPTIONS

FAILED = 1

OTHERS = 2

.

IF SY-SUBRC = 0.

*Replacing all NULL (X'00') values with SPACE (X'20')

REPLACE ALL OCCURRENCES OF c_null IN v_hexa WITH c_space IN BYTE MODE.

CALL FUNCTION 'SRET_BINARY_TO_TEXT'

EXPORTING

XBUFFER = v_hexa

LAISO = '00'

  • IV_CATID = ' '

  • IV_RFC_FOR_INITIALIZE = ' '

IMPORTING

  • OUTPUT_LENGTH =

TEXTBUFFER = output

EXCEPTIONS

FAILED = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

RAISE FAILED .

ENDIF.

ELSE.

RAISE FAILED .

ENDIF .

ENDFUNCTION.