Chinaunix首页 | 论坛 | 博客
  • 博客访问: 482038
  • 博文数量: 199
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1902
  • 用 户 组: 普通用户
  • 注册时间: 2020-05-14 13:25
个人简介

代码5S

文章分类

全部博文(199)

文章存档

2021年(5)

2020年(194)

我的朋友

分类:

2020-05-20 13:55:18

原文地址:ABAP ZIP压缩 作者:qdbarry

REPORT  z_barry_zip_file.

DATA: IZIP       TYPE REF TO CL_ABAP_ZIP,
      CONT       TYPE XSTRING ,
      XZIP_FILE  TYPE XSTRING,
      BINARY_TAB TYPE STANDARD TABLE OF X255 ,
      BIN_LEN TYPE I .

DATA: ITAB TYPE STANDARD TABLE OF SDOKCNTASC .
 
START-OF-SELECTION.
  DO 20 TIMES.
    APPEND 'ABAP¿ª·¢' TO ITAB.
  ENDDO.
  CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'
    EXPORTING
      MIMETYPE = 'text/html;charset=gb2312'
    IMPORTING
      BUFFER   = CONT
    TABLES
      TEXT_TAB = ITAB
    EXCEPTIONS
      FAILED   = 1
      OTHERS   = 2.
 
  CREATE OBJECT IZIP.
  CALL METHOD IZIP->ADD
    EXPORTING
      NAME    = 'ITAB.TXT'
      CONTENT = CONT.
  CALL METHOD IZIP->SAVE
    RECEIVING
      ZIP = XZIP_FILE.
 
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      BUFFER        = XZIP_FILE
    IMPORTING
      OUTPUT_LENGTH = BIN_LEN
    TABLES
      BINARY_TAB    = BINARY_TAB.
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      BIN_FILESIZE = BIN_LEN
      FILENAME     = 'C:\sf.zip'
      FILETYPE     = 'BIN'
    TABLES
      DATA_TAB     = BINARY_TAB.
 
 
解压缩ZIP文件:
TYPES: BEGIN OF t_file,
         name TYPE string,
         date TYPE d,
         time TYPE t,
         size TYPE i,
       END OF t_file .
TYPES: t_files TYPE TABLE OF t_file .
DATA: cl_zip TYPE REF TO cl_abap_zip,
      xstr   TYPE xstring,
      binary_tab TYPE STANDARD TABLE OF x255 ,
      bin_len TYPE i ,
      ls_file TYPE t_file ,
      it_files TYPE t_files .

DATA: itab TYPE STANDARD TABLE OF sdokcntasc .

START-OF-SELECTION.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename   = 'C:\upload.zip'
      filetype   = 'BIN'
    IMPORTING
      filelength = bin_len
    TABLES
      data_tab   = binary_tab.

  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
      input_length = bin_len
    IMPORTING
      buffer       = xstr
    TABLES
      binary_tab   = binary_tab
    EXCEPTIONS
      failed       = 1
      OTHERS       = 2.

  CREATE OBJECT cl_zip.

  CALL METHOD cl_zip->load
    EXPORTING
      zip = xstr.

  LOOP AT cl_zip->files INTO ls_file .
    WRITE: /  ls_file-name,
              ls_file-date,
              ls_file-time,
              ls_file-size .
    CALL METHOD cl_zip->get
      EXPORTING
        name    = ls_file-name
      IMPORTING
        content = xstr.
  ENDLOOP.


 
阅读(1016) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~