ABAP Abap ZIP İşlemleri

rerkuy

Kayıtlı Üye
Katılım
18 Kas 2016
Mesajlar
23
Tepki puanı
14
Puanları
3
Yaş
31
Konum
Konya
Kod:
DATA: lr_abap_zip   TYPE REF TO cl_abap_zip.
DATA: lt_data_tab   TYPE TABLE OF x255,
      lv_bin_size   TYPE i,
      lv_bufferx    TYPE xstring,
      lv_buffer_zip TYPE xstring.

" Input File
PARAMETERS: p_ifile TYPE string  DEFAULT 'C:\temp\file.pdf'.
" Output File
PARAMETERS: p_ofile TYPE string  DEFAULT 'C:\temp\file.zip'.


START-OF-SELECTION.

  " Upload file
  CLEAR: lt_data_tab[],lv_bin_size.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename   = p_ifile
      filetype   = 'BIN'
    IMPORTING
      filelength = lv_bin_size
    TABLES
      data_tab   = lt_data_tab.

  " Convert Binary to XString
  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
      input_length = lv_bin_size
    IMPORTING
      buffer       = lv_bufferx
    TABLES
      binary_tab   = lt_data_tab.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  " Create an instance of cl_abap_zip
  CREATE OBJECT lr_abap_zip.

  " Add Binary File to
  CALL METHOD lr_abap_zip->add
    EXPORTING
      name    = p_ifile
      content = lv_bufferx.

  " Get ZIP File in Binary mode
  CALL METHOD lr_abap_zip->save
    RECEIVING
      zip = lv_buffer_zip.

  CLEAR: lt_data_tab[],lv_bin_size.

  " Convert XSTRING to String
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer        = lv_buffer_zip
    IMPORTING
      output_length = lv_bin_size
    TABLES
      binary_tab    = lt_data_tab.

  " Download ZIP file on Presentation server
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize = lv_bin_size
      filename     = p_ofile
      filetype     = 'BIN'
    TABLES
      data_tab     = lt_data_tab.
 
Üst