Hey "cousin"
Thanks for posting back the solution.
Some improvement suggestions:
- get the list of invalid characters from the existing configuration, with FM RSKC_ALLOWED_CHAR_GET
- Use as escape a character that is more unlikely to be valid, such as: Ø
- Pre-define constants at the beginning of the code (makes the code a little more flexible and readable)
- 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:
- move the call to RSKC_ALLOWED_CHAR_GET' to the Start routine and store its value in a global variable (improves performance).
- turn this code into a function module
Cheers
Renato Silva