SAP Virtual/Onsite Trainings

Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

Create ZIP files in front-end system using Class CL_ABAP_ZIP

By Prasanna, Infosys

Introduction:

Read or Write ZIP files by using the class CL_ABAP_ZIP

Procedure:

1.     Select the files from Desktop and convert the data in BIN format

2.     Convert the data from BIN format to RAW format

3.     Add the files to ZIP using the class CL_ABAP_ZIP

4.     Convert into the ZIP binary format from RAW format

5.     Download the file into Desktop by choosing location using dialog box

Step 1: Data Declarations

        TYPES: BEGIN OF BIN_FILE,

                  NAME TYPE STRING,

                  SIZE TYPE I,

                  DATA TYPE SOLIX_TAB,

                 END OF BIN_FILE  

        DATA: LV_FILENAME           TYPE STRING,

                  WA_BINDATA            TYPE BIN_FILE,

                  IT_BINDATA              TYPE STANDARD TABLE OF BIN_FILE,   

                  OREF_ZIP                 TYPE REF TO CL_ABAP_ZIP,

                  LV_ZIP_XSTRING      TYPE XSTRING,

                  LV_XSTRING             TYPE XSTRING,

                  LV_PATH                   TYPE STRING,

                  IT_FILETAB               TYPE FILETABLE,

                  RET_CODE                TYPE I,

                  V_USR                      TYPE I,

                  V_ZIP_SIZE              TYPE I,

                  IT_ZIP_BIN_DATA     TYPE STANDARD TABLE OF RAW255,

                  V_DEST_FILEPATH    TYPE STRING                           

              CREATE OBJECT OREF_ZIP.

Step 2: Select files that you want to zip

CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG(

      EXPORTING

        WINDOW_TITLE            = 'Select files that you want to ZIP'

        MULTISELECTION          = 'X'

      CHANGING

        FILE_TABLE                 = IT_FILETAB

        RC                              = RET_CODE

        USER_ACTION             = V_USR ).

Step 3: Populate the data of the selected files into internal table in “BIN” Format

      LOOP AT IT_FILETAB INTO WA_FILETAB

            LV_FILENAME = WA_FILETAB-FILENAME.

      CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD(

        EXPORTING

          FILENAME                = LV_FILENAME

          FILETYPE                = 'BIN'

        IMPORTING

          FILELENGTH              = WA_BINDATA-SIZE

        CHANGING

          DATA_TAB                = WA_BINDATA-DATA ).

       

     CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'

        EXPORTING

          FULL_NAME     = LV_FILENAME

        IMPORTING

          STRIPPED_NAME = WA_BINDATA-NAME

        EXCEPTIONS

          X_ERROR       = 1

          OTHERS        = 2.

      APPEND WA_BINDATA TO IT_BINDATA.

    ENDLOOP       

Step 4: Convert the BIN file format to XSTRING format

 LOOP AT IT_BINDATA INTO WA_BINDATA.    

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

        EXPORTING

          INPUT_LENGTH = WA_BINDATA-SIZE

        IMPORTING

          BUFFER       = LV_XSTRING

        TABLES

          BINARY_TAB   = WA_BINDATA-DATA

 

Step 5:  Add file to ZIP folder

OREF_ZIP->ADD( NAME    = WA_BINDATA-NAME

                    CONTENT = LV_XSTRING ).

ENDLOOP

 

Step 6: Get the binary string for ZIP file.

LV_ZIP_XSTRING = OREF_ZIP->SAVE( ).

Step 7: Convert XSTRING to BINARY table.        

 

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

      EXPORTING

        BUFFER        = LV_ZIP_XSTRING

      IMPORTING

        OUTPUT_LENGTH = V_ZIP_SIZE

      TABLES

        BINARY_TAB    = IT_ZIP_BIN_DATA.

Step 8: Opens dialog box to save ZIP file in your desktop

    CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG(

      EXPORTING

        WINDOW_TITLE         = 'SELECT THE LOCATION TO SAVE THE FILE'

        FILE_FILTER          = '(*.ZIP)|*.ZIP|'

      CHANGING

        FILENAME             = LV_FILENAME

        PATH                 = LV_PATH

        FULLPATH             = V_DEST_FILEPATH ).

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image