Skip to end of metadata
Go to start of metadata

A frequent issue facing data loads in BIW is the issue of invalid characters . I have reconstructed information already available in SDN into a useful function module that can be used in any scenario. Hope it is useful .

NOTE : THIS WAS DONE ON A NON UNICODE SYSTEM - HAVE NOT DONE THE SAME ON A UNICODE SYSTEM - Arun

 Function Module code :

 DATA: L_USER_ALLOWED_CHAR TYPE RSALLOWEDCHAR,
input(200) type c,
L_ALL_ALLOWED_CHAR(140) TYPE C,
L_RESULT_STR_LEN TYPE I,
L_STR_INCREMENT TYPE I.
CONSTANTS C_SAP_ALLOWED_CHAR(58) TYPE C VALUE
' !"%&''()*+,-./:;<=>?_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

IF L_ALL_ALLOWED_CHAR IS INITIAL.
SELECT SINGLE * FROM RSALLOWEDCHAR
INTO L_USER_ALLOWED_CHAR
WHERE ALLOWKEY = 'S'.
CONCATENATE C_SAP_ALLOWED_CHAR
L_USER_ALLOWED_CHAR-ALLOWCHAR
INTO L_ALL_ALLOWED_CHAR.
ENDIF.

input = inputchar.
TRANSLATE input TO UPPER CASE.
L_RESULT_STR_LEN = STRLEN( input ).
L_STR_INCREMENT = 0.
WHILE L_STR_INCREMENT LE L_RESULT_STR_LEN.
IF NOT input+L_STR_INCREMENT(1) CO L_ALL_ALLOWED_CHAR.
input+L_STR_INCREMENT(1) = ' '.
ENDIF.
ADD 1 TO L_STR_INCREMENT.
ENDWHILE.
outputchar = input.
ENDFUNCTION.

Here the function module takes one input - inputchar type string ( import parameter ) and one output - outputchar type string ( export parameters )

How to use this in a transformation

I have used the same in a local routine in a transformation also...

data: ysourcefield type string.
data: yresult type string.

ysourcefield = SOURCE_FIELDS-inputfield.

CALL FUNCTION 'Z_INVALID_CHAR_REMOVE'
  EXPORTING
    INPUTCHAR        = ysourcefield
 IMPORTING
   OUTPUTCHAR       = YRESULT.

     RESULT = yresult.

Reference threads :

Blog on the same by Eugene Khusainov

Relevant threads...

https://www.sdn.sap.com/irj/sdn/thread?forumID=131&threadID=147836&messageID=1655114

https://www.sdn.sap.com/irj/sdn/thread?threadID=174056