关注领域建模

追随UML,学会思考

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.

posted on 2009-04-15 09:48  Beewolf  阅读(1770)  评论(0编辑  收藏  举报

导航