码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-02-25 13:26:01      阅读:2953      评论:0      收藏:0      [点我收藏+]

标签:length   ext   获取   blog   tab   head   logs   round   code   

函数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获取字符串长度/字节长度

标签:length   ext   获取   blog   tab   head   logs   round   code   

原文地址:http://www.cnblogs.com/rainysblog/p/6441394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!