Skip to Content
Author's profile photo Former Member

Removing Invalid Characters using field routine

Summary

 

This Blog shows a simple way to remove the Invalid Characters in BW using a Field Routine.

 

We often face the issue of load failures due to Invalid characters in BW, Instead of Editing the data in PSA temporarily, we wrote a simple routine in Field level.

  

Load Failed Due to Invalid Chars

image

 

Info object ZSR_DEC contains Invalid Chars

image

 

Field Routine In Transformations

image

Explanation

 

1)  ‘,<>?/\:;””ABCDEFGHI JKLMNOPQRSTUVWXYZ!%^&*()__+=1234567890’.

These are the Valid chars and numbers which will be accepted by BW system, System will throw an error only when load receives a char which is not there in the above. And that char will be treated as a Invalid Char.

 

2)  IF  A+l_time(1)  CN    ‘,<>?/\:;””ABCDEFGHI JKLMNOPQRSTUVWXYZ!%^&*()__+=1234567890’.

     A is a Char which contains the data .

    I_time is used for iteration(it’ll check each char by char in a word/Sentence).

    CN – Contains not

     

 A+l_time(1) = ‘~’.

 What ever the special/Invalid char appears in the load apart from the above mentioned, system will convert  them to ‘~’

 

 

3) REPLACE ALL OCCURRENCES OF ‘~’ IN a WITH space.

   CONDENSE A.

  
   System will replace all the ~ with space, then condenses the space.

Activate the transformation, Delete and Reload the data 

image

 

load successful to Data target

 image

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Suhas Karnik
      Suhas Karnik
      It would be quite useful to have this to automate the work.

      To build upon this idea, an FM can be written which reads the RSKC values and replaces any invalid characteristics with space. This FM can then be called in the field-level routines for any InfoObject. Saves time in case the RSKC values need to be changed in future or if you face the same problem with some other characteristic.

      Author's profile photo Former Member
      Former Member
      This is what I found in SAP help:

      *Only the following standard characters are valid in characteristic
      *values by default:
      *!"%&''()*+,-./:;<=>?_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.
      *Furthermore, characteristic values that only consist of the character #
      * or that begin with ! are not valid.

      So check is a little bit more complicated and also you have to check for UPPER/LOW case depending on Info objects settings and of course it is better to do the check in a Function module.
      I've been using the following function for that:

      FUNCTION zbw_allow.
      *"----------------------------------------------------------------------
      *"*"Local Interface:
      *" IMPORTING
      *" VALUE(UPPER) TYPE CHAR1 DEFAULT ' '
      *" VALUE(CONDENSE) TYPE CHAR1 DEFAULT 'X'
      *" VALUE(CHAR_DEF) TYPE CHAR1 DEFAULT ' '
      *" CHANGING
      *" VALUE(SL_CHAR)
      *"----------------------------------------------------------------------

      DATA: sl32(32) TYPE c VALUE '!"%&''()*+,-./:;<=>?_0123456789 '.
      DATA: slcap(26) TYPE c VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
      DATA: sllow(26) TYPE c VALUE 'abcdefghijklmnopqrstuvwxyz'.
      DATA: sl60(60) TYPE c.

      DATA: sl_pos LIKE sy-fdpos.

      sl60 = sl_char.

      IF char_def CA sl32
      OR char_def CA slcap
      OR char_def CA sllow.
      ELSE.
      CLEAR char_def.
      ENDIF.

      *Only the following standard characters are valid in characteristic
      *values by default:
      *!"%&''()*+,-./:;<=>?_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.
      *Furthermore, characteristic values that only consist of the character #
      * or that begin with ! are not valid.

      IF sl60 EQ '#'.
      sl60 = char_def.
      ENDIF.

      CLEAR sl_pos.
      DO 60 TIMES.
      IF sl60+sl_pos(1) CA sl32
      OR sl60+sl_pos(1) CA slcap
      OR sl60+sl_pos(1) CA sllow.
      ELSE.
      sl60+sl_pos(1) = char_def.
      ENDIF.
      ADD 1 TO sl_pos.
      ENDDO.
      SHIFT sl60 LEFT DELETING LEADING ' '.

      WHILE sl60(1) = '!'.
      sl60(1) = char_def.
      SHIFT sl60 LEFT DELETING LEADING ' '.
      ENDWHILE.

      IF upper = 'X'.
      TRANSLATE sl60 TO UPPER CASE.
      ENDIF.

      IF condense = 'X'.
      CONDENSE sl60 NO-GAPS.
      ENDIF.

      CLEAR sl_char.
      sl_char = sl60.

      ENDFUNCTION.

      This function allows you to choose with what character you want the invalid character to be replaced with (space or something else).

      Hope this helps,
      Stan

      Author's profile photo Former Member
      Former Member
      I use this method (found on SDN, my apologies for not remembering the originator).

      class ZCL_IOBJ_CHECK definition
      public
      create public .

      *"* public components of class ZCL_IOBJ_CHECK
      *"* do not include other source files here!!!
      public section.

      type-pools RSD .
      class-methods ELIM_INVALID_CHARS
      importing
      value(IN_VALUE) type /BI0/OIPOSTXT
      value(IN_INFOOBJECT) type RSD_IOBJNM
      exporting
      value(OUT_VALUE) type /BI0/OIPOSTXT .

      method ELIM_INVALID_CHARS.
      DATA: length TYPE I,
      index TYPE I,
      current_char TYPE C,
      result(60) TYPE C,
      infoobject TYPE RSD_IOBJNM.

      CLEAR: result, infoobject.
      MOVE IN_VALUE TO result.
      MOVE IN_INFOOBJECT TO infoobject.
      * TRANSLATE result TO UPPER CASE.
      length = strlen( result ).
      index = -1.
      DO length TIMES.
      index = index + 1.
      current_char = result+index(1).
      CALL FUNCTION 'RSKC_CHAVL_OF_IOBJ_CHECK'
      EXPORTING
      I_CHAVL = current_char
      I_IOBJNM = infoobject
      EXCEPTIONS
      CHAVL_NOT_ALLOWED = 1.
      IF SY-SUBRC <> 0.
      MOVE ' ' TO result+index(1).
      ENDIF.
      ENDDO.
      MOVE result TO OUT_VALUE.
      endmethod.

      Author's profile photo Former Member
      Former Member

      Hi Jyothi

      Nice one...

      Author's profile photo Mohit Agrawal
      Mohit Agrawal

      Hi Jyothi,

      That's great. But wouldn't the use of condense remove every space from the string?

      I think we should use below statement:

      REPLACE ALL OCCURRENCES OF ‘~’ IN a WITH ''.

      So that would replace all tilde with and make the string compact like needed.

       

      Thanks

      Mohit