如何进行各种码制数据之间转换

1 系统内部转换命令(一般建议不直接使用) 
SYSTEM-CALL CONVERT ID id DATA data
    ENCODING encoding
    ENDIAN endian
    IGNORE_CERR ignore_cerr N n
    POSITION position
    REPLACEMENT replacement
    LEN len
    BUFFER buffer
    ERR err.
Text and lines are converted between different formats.

2 使用SAP系统封装的类CL_ABAP_CONV_IN_CE and  CL_ABAP_CONV_OUT_CE
样例
data  STR TYPE C.

  DATA: S TYPE STRING,
        LEN TYPE I.
  DATA: CVTI_UTF8 TYPE REF TO CL_ABAP_CONV_IN_CE.
  FIELD-SYMBOLS : <X> TYPE X.

  ASSIGN STR TO <X> CASTING.

  CVTI_UTF8 =  CL_ABAP_CONV_IN_CE=>CREATE( ENCODING = 'UTF-8' INPUT    = <X> ).

  CALL METHOD CVTI_UTF8->READ
    IMPORTING
        DATA = S
        LEN  = LEN
    EXCEPTIONS OTHERS = 1.

  STR = S.

3 使用sap封装的Form
要包含以下单元:RSCPICINC
封装的form
CONV_TO_ASCII
CONV_TO_EBCDIC
CONV_TO_UTF8
CONV_FROM_ASCII
CONV_FROM_ASCII
CONV_FROM_EBCDIC

4使用sap封装的函数(外部->系统默认代码,系统默认代码->外部)
function translate_codepage_in.

*"  IMPORTING
*"     VALUE(CODEPAGE_FROM) TYPE  ABAP_ENCOD
*"  TABLES
*"      T_DATA
*"  EXCEPTIONS
*"      ERROR_TRANSLATE
function translate_codepage_out.
*"  IMPORTING
*"     VALUE(CODEPAGE_FROM) TYPE  ABAP_ENCOD
*"  TABLES
*"      T_DATA
*"  EXCEPTIONS
*"      ERROR_TRANSLATE

5使用TRANSLATE命令
TRANSLATE c ...FROM CODE PAGE g1...     TO CODE PAGE g2.

6 常见代码编号
EBCDIC = '0100'
ASCII  =  '1100'
UTF8 = 'UTF-8'

7 相关的元素
ABAP_ENCOD
TCP00(表)

posted on 2006-11-28 14:52  毛小娃  阅读(308)  评论(0编辑  收藏  举报

导航