Skip to Content
author's profile photo Former Member
Former Member

Null character removal in sap using a function module

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 10, 2004 at 03:42 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 10, 2004 at 07:24 AM

    You can try the CONDENSE statement.

    Regards

    Elini.P

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 10, 2004 at 07:46 AM

    Hi,

    try this:

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

    translate record using trhex.

    Grx Andreas

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.