首页 > 代码库 > 20170225 ABAP获取字符串长度/字节长度

20170225 ABAP获取字符串长度/字节长度

函数YGET_CHAR_LONG:

FUNCTION YGET_CHAR_LONG.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(STRING) TYPE  STRING OPTIONAL
*"  EXPORTING
*"     VALUE(STR) TYPE  STRING
*"     VALUE(G_LONG) TYPE  I    "字符串长度
*"     VALUE(G_LONG_STR) TYPE  I"字节长度
*"----------------------------------------------------------------------

  DATA: W_UCCP TYPE I,
  W_TEMP(2) TYPE C,
  W_LEFT(100) TYPE C,
  W_LEN(10) TYPE C,
  S_LEN TYPE I
  .
  W_LEFT = STRING.

  DATA : BEGIN OF LINE,
         TEXT TYPE C,
         END OF LINE,
         ITAB LIKE TABLE OF LINE WITH HEADER LINE.

*DATA str TYPE string.
  DO.
    CALL FUNCTION TEXT_SPLIT
      EXPORTING
        LENGTH = 2
        TEXT   = W_LEFT
      IMPORTING
        LINE   = W_TEMP
        REST   = W_LEFT.

    CALL METHOD CL_ABAP_CONV_OUT_CE=>UCCPI
      EXPORTING
        CHAR = W_TEMP
      RECEIVING
        UCCP = W_UCCP.
    W_LEN = STRLEN( W_TEMP ).
*  WRITE: /1 w_temp,
*  10 w_uccp,
*  25 w_len.
    IF W_UCCP > 256.
      CONCATENATE STR W_TEMP INTO STR.
    ENDIF.
    IF W_LEFT IS INITIAL OR SY-INDEX > 100.
      EXIT.
    ENDIF.
  ENDDO.
  IF STR IS NOT INITIAL.
    DATA:T_LEN TYPE I.
    CLEAR :  S_LEN,G_LONG_STR.
    T_LEN = STRLEN( STRING ).
    G_LONG = STRLEN( STRING ).

    S_LEN = STRLEN( STR ).
    T_LEN =  T_LEN - S_LEN .
    S_LEN = S_LEN * 2 .
    G_LONG_STR =  T_LEN + S_LEN.
*  WRITE :/,CHARLEN= ,charlen, STR= ,str.
  ENDIF.


ENDFUNCTION.

 

20170225 ABAP获取字符串长度/字节长度