zoukankan      html  css  js  c++  java
  • [SAP ABAP开发技术总结]以二进制、字符模式下载文件

    20.26.              下载文件

    20.26.1.       BIN 二进制下载

    DATA : xstr TYPE xstring .
    DATA l_codepage ( 4 ) TYPE n .
    DATA l_encoding ( 20 ).
    ********** 字符集名与内码转换
    " 将外部字符集名转换为内部编码
    CALL FUNCTION
    ' SCP_CODEPAGE_BY_EXTERNAL_NAME '
     
    EXPORTING
        external_name
    = 'UTF-8'
     
    IMPORTING
        sap_codepage 
    = l_codepage .
    l_encoding
    = l_codepage .
    ********** 编码
    DATA : convout TYPE REF TO cl_abap_conv_out_ce .
    " 创建编码对象
    convout
    = cl_abap_conv_out_ce => create ( encoding = l_encoding ).
    convout
    -> write ( data = ' 江正军 ' ). " 编码
    xstr
    convout -> get_buffer ( ). " 获取二进制码流
    WRITE : / xstr . "E6B19FE6ADA3E5869B
    ********** 解码
    DATA : convin TYPE REF TO cl_abap_conv_in_ce .
    " 创建解码对象
    convin
    = cl_abap_conv_in_ce => create ( encoding = l_encoding input = xstr ).
    DATA : str TYPE string .
    CALL METHOD convin -> read " 解码
     
    IMPORTING data = str .
    WRITE : / str . " 江正军

    TYPES : xx ( 100 ) TYPE x .
    DATA : xtab TYPE STANDARD TABLE OF xx WITH HEADER LINE .
    xtab
    = xstr .
    APPEND xtab .

    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                       
    = 'c:2.txt'
      filetype                       
    = 'BIN'
    TABLES
     
    "data_tab 的类型为 ANY ,所以 xtab 是一列还是多列,都会写到
     
    " 文件中去,这里还只有一列,而且还没有列名,这也没有关系
      data_tab                       
    = xtab[] .

    20.26.2.       以字符模式下载

    DATA : BEGIN OF strc OCCURS 0 ,
        c1
    ( 2 ) TYPE c ,
        c2
    ( 1 ) TYPE c ,
     
    END OF strc .
    strc
    - c1 = ' ' .
    strc
    - c2 = ' ' .
    APPEND strc .
    APPEND strc .

    CALL FUNCTION 'GUI_DOWNLOAD'
     
    EXPORTING
    *   BIN_FILESIZE          =
        filename             
    = 'c:1.txt'
        filetype             
    = 'DAT' " 列与列之间会使用 TAB 分隔
    *   APPEND                = ' '
    *   WRITE_FIELD_SEPARATOR = ' '
    *   HEADER                = '00'
    *   codepage              = '8400' "GBK
    *   codepage              = '8450' "GB2312
        codepage             
    = '4110' "utf-8
    *   CODEPAGE              = '4102'"UTF-16BE
    *   CODEPAGE              = '4103'"UTF-16LE
     
    TABLES
        data_tab             
    = strc[] .

     

      CODEPAGE

    l   Description

    Use parameter CODEPAGE to specify the desired target codepage. If this parameter is not set, the codepage of the SAP GUI is used as the target codepage. 如果不指定,则使用 SAP GUI 所使用的 Codepage

    l   Value range

    4-digit number of the SAP codepage. The function module SCP_CODEPAGE_BY_EXTERNAL_NAME returns the SAP codepage number for an external character set name, for example, "iso-8859-1". The function module NLS_GET_FRONTEND_CP returns the appropriate non-Unicode frontend codepage for a language.

    You can determine the desired codepage interactively, if the parameter with_encoding of method file_save_dialog is set by cl_gui_frontend_services.

    SPACE: Codepage of the SAP GUI

    l   Default

    SPACE

     

    SCP_CODEPAGE_BY_EXTERNAL_NAME

    该函数可将字符集名称转换为 CODEPAGE ,也可以直接查看 TCP00A

    image006

     

    另外,发现 TCP00 表里也存储了 CODEPAGE ,而且该表有一个 CPCOMPANY 字段标示该代码是由哪个组织定义的(一般我们使用 ISO 国际标准),可以将 TCP00A TCP00 通过 CODEPAGE 联合起来查询, TCP00A 可以根据字符集名称(如 GBK UTF-8 TCP00A-CPATTR 来查询,而 TCP00 可以根据字符集描述(如: Chinese )来查询 TCP00- CPCOMMENT

  • 相关阅读:
    Oracle EBS json
    OAF--基础
    Oracle EBS FA 本年折旧
    Oracle EBS FA 获取累计折旧
    SOAP REST
    Oracle EBS FA 资产取值
    Java ——基础语法
    PL/SQL APIs for Concurrent Processing
    Using Globals in Oracle Reports (Doc ID 34751.1)
    Using SRW Packaged Procedures In Reports (Doc ID 61643.1)
  • 原文地址:https://www.cnblogs.com/jiangzhengjun/p/4265688.html
Copyright © 2011-2022 走看看