*&---------------------------------------------------------------------*
*& Report Z_BARRY_TEST *
*& *
*&---------------------------------------------------------------------*
*& 程序1:非UNICODE使用,提取汉字/英文字母等 *
*& *
*&---------------------------------------------------------------------*
REPORT z_barry_nounicode NO STANDARD PAGE HEADING .
DATA: input1(100) TYPE c ,
outch1(100) TYPE c ,
outen1(100) TYPE c ,
len TYPE i.
input1 = 'a中bcde三萨格发'.
PERFORM unicode USING input1 outch1 outen1 len.
WRITE : / 'Input: ' , input1 ,
/ '提取双字节: ' , outch1 ,
/ '提取单字节: ' , outen1 ,
/ 'UNICODE长度: ' , len .
*&---------------------------------------------------------------------*
*& Form nounicode
*&---------------------------------------------------------------------*
FORM unicode USING value(input) TYPE c
outch TYPE c
outen TYPE c
unicodelen TYPE i.
DATA: inlen TYPE i,
charlen TYPE i,
n TYPE i ,
m TYPE i .
inlen = STRLEN( input ).
DO .
charlen = CHARLEN( input ) .
IF charlen = 2 .
CONCATENATE outch input+0(2) INTO outch.
ELSE.
CONCATENATE outen input+0(1) INTO outen.
ENDIF.
unicodelen = unicodelen + 1 .
SHIFT input BY charlen PLACES LEFT IN CHARACTER MODE .
inlen = STRLEN( input ).
IF inlen <= 0 . EXIT. ENDIF.
ENDDO.
ENDFORM.
*&---------------------------------------------------------------------*
*& 程序2:UNICODE系统使用 *
*&---------------------------------------------------------------------*
REPORT z_barry_test.
DATA: input1(100) TYPE c ,
outch1(100) TYPE c ,
outen1(100) TYPE c ,
len TYPE i.
input1 = '中国zhongguo人民renmin'.
PERFORM nounicode USING input1 outch1 outen1 len.
WRITE : / 'Input: ' , input1 ,
/ '提取双字节: ' , outch1 ,
/ '提取单字节: ' , outen1 ,
/ 'ANSI长度 :' , len .
*&---------------------------------------------------------------------*
*& Form nounicode
*&---------------------------------------------------------------------*
FORM nounicode USING input TYPE c
outch TYPE c
outen TYPE c
ansilen TYPE i.
DATA: inlen TYPE i,
n TYPE i ,
result_tab TYPE match_result_tab .
ansilen = cl_abap_list_utilities=>dynamic_output_length( input ) .
FIND ALL OCCURRENCES OF REGEX '[[:unicode:]]' IN input RESULTS result_tab.
inlen = STRLEN( input ) .
DO inlen TIMES.
n = sy-index - 1.
READ TABLE result_tab TRANSPORTING NO FIELDS WITH KEY offset = n BINARY SEARCH.
IF sy-subrc = 0.
CONCATENATE outch input+n(1) INTO outch.
ELSE.
CONCATENATE outen input+n(1) INTO outen.
ENDIF.
ENDDO.
ENDFORM. "nounicode
阅读(4690) | 评论(2) | 转发(0) |