메뉴 건너뛰기

SAP 한국 커뮤니티



2 byte 글자 자르기 관련

정군 2009.04.30 22:34 조회 수 : 6383

질문을 올리신 분이 있어서 ...


참조하시라고 올립니다. 완전히 원하는 바가 나오진 않겠지만, 소스를 곰곰히 보고 있으면 이해 되실 겁니다.


 


 


[IMPORT]


I_STR TYPE C
I_LEN TYPE I


 


[EXPORT]


O_STR TYPE STRING


 


 


[SOURCE]


FUNCTION Z_GET_LONG_TEXT.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(I_STR) TYPE  C
*"     VALUE(I_LEN) TYPE  I
*"  EXPORTING
*"     REFERENCE(O_STR) TYPE  STRING
*"----------------------------------------------------------------------



*-----------------------------------------------------------------------
*            Data Declaration
*-----------------------------------------------------------------------


  DATA: sta TYPE i,    " HEXA location
            flg.               " current 2Byte Pair status
  FIELD-SYMBOLS: <str>,             " Hexa Value of input String
                            <xstr> TYPE x. " Hexa value of 1byte Charater


 


*-----------------------------------------------------------------------
*            Main Procedure of Function
*-----------------------------------------------------------------------


  DATA: o_len TYPE i.


  CLEAR   : o_str, o_len.


 


*--- if Input String doesn't exist, return
    o_len = STRLEN( i_str ).
    IF o_len = 0.
      EXIT.
    ENDIF.


*- if Input length is greater than total length, check input length
*  if Input length is smaller than total length, check total length
    IF o_len > i_len.
      o_len = i_len.
    ENDIF.


*--- Begin of correction
    ASSIGN i_str TO <str> TYPE 'X'.
    CLEAR: sta, flg.
    DO o_len TIMES.
      sta = sy-index - 1.


      ASSIGN <str>+sta(1) TO <xstr>.
      IF <xstr> >= '80'.       " 2Byte Character
        IF flg = space.
          flg = 'X'.           " 1st Byte of TWO
        ELSE.
          flg = space.         " 2nd Byte of TWO : Normal Case
        ENDIF.
      ENDIF.
    ENDDO.


*- if valid character is incompletede 2Byte,cut from pre-character
    IF flg = 'X'.           " IF Last character was cut abnormally
      o_len = o_len - 1.
    ENDIF.


    o_str = i_str(o_len).      "Return Value
*    APPEND  o_str.  CLEAR o_str.
    SHIFT i_str BY o_len PLACES.
*  ENDDO.


ENDFUNCTION.