BW转换例程中去掉非法字符

* result value of the routine
   RESULT = COMM_STRUCTURE-txtmd.
  CALL FUNCTION 'Z_ZH_REMOVE_INVLID_CHARARCTER'
    CHANGING
      c_string = RESULT.
* if abort is not equal zero, the update process will be canceled


.....
FUNCTION z_zh_remove_invlid_chararcter.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  CHANGING
*"     REFERENCE(C_STRING) TYPE  ANY
*"----------------------------------------------------------------------

  DATA: l_count TYPE i,
       l_oldpos TYPE i,
       l_str(40) TYPE c,
       l_strlen TYPE i,
       l_maxcount TYPE i.

  FIELD-SYMBOLS: <fs> TYPE x.

  l_count = 0.
  l_str = c_string.
  l_strlen = STRLEN( l_str ).
  l_maxcount = l_strlen - 1.

  DO.
    IF ( l_count > l_maxcount ).
      EXIT.
    ENDIF.

    ASSIGN l_str+l_count(1) TO <fs> CASTING TYPE x.
    IF <fs> <= 127.
      l_count = l_count + 1.  "go to the next
    ELSE.                     "Chinese character
      l_count = l_count + 1.
      IF l_count > l_maxcount.
        "Wrong
        l_oldpos = l_count - 1.
        l_str+l_oldpos(1) = space.
      ELSE.
        ASSIGN l_str+l_count(1) TO <fs> CASTING TYPE x.
        IF <fs> <= 127.
          "  Wrong.
          l_oldpos = l_count - 1.
          l_str+l_oldpos(1) = space.
        ELSE.                      "Correct
          l_count = l_count + 1.   "go to the next
        ENDIF.
      ENDIF.
    ENDIF.
  ENDDO.

  c_string = l_str.
*  BREAK-POINT.


ENDFUNCTION.


以下为网上的例程。

  l_strlen = STRLEN( c_text ).

  DO l_strlen TIMES.
    IF c_text+l_offset(1) < ' '.
      c_text+l_offset(1) = ' '.
    ENDIF.

    ADD 1 TO l_offset.
  ENDDO.

原文地址:https://www.cnblogs.com/Beewolf/p/1436194.html