cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Remove special characters in BW transformations

0 Kudos
12,641

Hi BW Gurus,

I have a problem with special characters like the following example: “!210247 NUALJOTA”.

I have ALL_CAPITAL in RSKC, and “Lower case” enable option in the infoobject, and I try to use the FM: SCP_REPLACE_STRANGE_CHARS, but there is ativation issues of the DSO regarding invalid characters for this dimension.

Does anybody knows how to solve this problem?

Thanks in advance.

Best regards,

Cátia Coelho

View Entire Topic
0 Kudos

Hi everyone,

Thank you for the answers! Problem solved with this abap code:

DATA: a TYPE c LENGTH 000050.
DATA: l_len TYPE i,
l_time TYPE i.

MOVE source_fields-sgtxt TO a.
TRANSLATE a TO UPPER CASE.

l_len = strlen( a ).

DO l_len TIMES.
IF a+l_time(1) CN  ',<>?/\:;"''ABCDEFGHI JKLMNOPQRSTUVWXYZ!%^&*()__+=1234567890' .
a+l_time(1) = '!'.
ENDIF.

l_time = l_time + 1.
ENDDO.

REPLACE ALL OCCURRENCES OF '!' IN a WITH space.
CONDENSE a.

result = a.

Thanks.

Best regards,

Cátia Coelho

Former Member
0 Kudos

Hey "cousin"

Thanks for posting back the solution.

Some improvement suggestions:

  1. get the list of invalid characters from the existing configuration, with FM RSKC_ALLOWED_CHAR_GET
  2. Use as escape a character that is more unlikely to be valid, such as: Ø
  3. Pre-define constants at the beginning of the code (makes the code a little more flexible and readable)
  4. using l_sgtxt instead of "a" for the name of the (makes the code more readable).

So, the final code looks like:

CONSTANTS:

           c_allowed_char  TYPE c LENGTH 200 VALUE

           '!,<>?/\:;"''ABCDEFGHI JKLMNOPQRSTUVWXYZ!%^&*()__+=1234567890',

           c_escape        TYPE c VALUE 'Ø'.     " because '!' is a valid character too

     DATA: l_allowed_char  TYPE c LENGTH 200,

           l_sgtxt         TYPE c LENGTH 000050,

           l_len           TYPE i,

           l_time          TYPE i.

     " get list of allowed characters - from system config

     CALL FUNCTION 'RSKC_ALLOWED_CHAR_GET'

       IMPORTING

         e_allowed_char = l_allowed_char.

     IF sy-subrc <> 0.

       " if it fails, get use standard list, from constant

       l_allowed_char = c_allowed_char.

     ENDIF.

     MOVE source_fields-sgtxt  TO l_sgtxt.

     TRANSLATE l_sgtxt TO UPPER CASE.

     l_len = STRLEN( l_sgtxt ).

     DO l_len TIMES.

       IF l_sgtxt+l_time(1) CN  l_allowed_char .

         l_sgtxt+l_time(1) = c_escape.

       ENDIF.

       l_time = l_time + 1.

     ENDDO.

     REPLACE ALL OCCURRENCES OF c_escape IN l_sgtxt WITH space.

     CONDENSE l_sgtxt.

     result = l_sgtxt.

Something else that could be done:

  1. move the call to RSKC_ALLOWED_CHAR_GET' to the Start routine and store its value in a global variable (improves performance).
  2. turn this code into a function module

Cheers

Renato Silva

0 Kudos

I just want to add,  if you don't want the blanks got removed, please don't use the Method Concatenate. Because trailing blanks will be ignored .

You can refer the code below.

CONSTANTS:

          l_c_chars1(41) TYPE c

            VALUE '`"$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJK',

          l_c_chars2(47) TYPE c

            VALUE 'LMNOPQRSTUVWXYZ[]^_{}abcdefghijklmnopqrstuvwxyz',

          c_escape        TYPE c VALUE 'Ø'.

     DATA:

*      l_offset        TYPE i,

       l_length        TYPE i,

       l_strlen        TYPE i,

       l_allowed_chars TYPE string,

       l_times         TYPE i,

       l_index         TYPE i,

       l_char          TYPE c,

       l_output        TYPE char80.

     RESULT = SOURCE_FIELDS-/BIC/PNRPTNTXT.

     CONCATENATE l_c_chars1 l_c_chars2 INTO l_allowed_chars.

     CONDENSE l_allowed_chars NO-GAPS.

     DESCRIBE FIELD RESULT LENGTH l_times IN CHARACTER MODE.

     DO l_times TIMES.

       l_index = sy-index - 1.

       l_char = result+l_index(1).

        IF l_char CN l_allowed_chars.

          result+l_index(1) = space.

        endif.

        enddo.