Sunday, December 26, 2010

REPORT ZTEST_ZIP_FILE.
"Types
TYPES:
      TY_PDF     TYPE TLINE.
"Internal Tables
DATA:
      IT_PDF     TYPE STANDARD TABLE OF TY_PDF.
"Structures
DATA
      WA_PDF     TYPE TY_PDF.
"Variables
DATA:
      GV_VAL      TYPE C,
      GV_SPOOL_NO TYPE  TSP01-RQIDENT,
      GV_ZIP_FILE TYPE XSTRING.
"Structures
DATA:
      W_PRIPAR  TYPE PRI_PARAMS,
      W_ARCPAR  TYPE ARC_PARAMS.
*&---------------------------------------------------------------------*
*& Start-of-selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM WRITE_TO_SPOOL CHANGING GV_SPOOL_NO.
  PERFORM READ_SPOOL     USING    GV_SPOOL_NO.
  PERFORM ZIP_FILE       CHANGING GV_ZIP_FILE.
  PERFORM DOWNLOAD_ZIP   USING    GV_ZIP_FILE.



*&---------------------------------------------------------------------*
*&      Form  WRITE_TO_SPOOL
*&---------------------------------------------------------------------*
FORM WRITE_TO_SPOOL  CHANGING P_GV_SPOOL_NO.
  "Read, determine, change spool print parameters and archive parameters
  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      IN_ARCHIVE_PARAMETERS  = W_ARCPAR
      IN_PARAMETERS          = W_PRIPAR
      LAYOUT                 = 'X_65_132'
      LINE_COUNT             = 65
      LINE_SIZE              = 132
      NO_DIALOG              = 'X'
    IMPORTING
      OUT_ARCHIVE_PARAMETERS = W_ARCPAR
      OUT_PARAMETERS         = W_PRIPAR
      VALID                  = GV_VAL.
  IF GV_VAL  NE SPACE AND SY-SUBRC = 0.
    W_PRIPAR-PRREL = SPACE.
    W_PRIPAR-PRIMM = SPACE.
    NEW-PAGE PRINT ON NEW-SECTION PARAMETERS W_PRIPAR ARCHIVE PARAMETERS W_ARCPAR NO DIALOG.
    "Step-1:Loop your internal table.
    "Step-2:Display using WRITE statement.
    "Step-3:The output goes to spool
    WRITE 'Output in spool to create zip file'.
    WRITE 'Output in spool to create zip file'.
    WRITE 'Output in spool to create zip file'.
    WRITE 'Output in spool to create zip file'.
    NEW-PAGE PRINT OFF.
    CALL FUNCTION 'ABAP4_COMMIT_WORK'.
  ENDIF.
  P_GV_SPOOL_NO = SY-SPONO.
ENDFORM.                    " WRITE_TO_SPOOL
*&---------------------------------------------------------------------*
*&      Form  READ_SPOOL
*&---------------------------------------------------------------------*
FORM READ_SPOOL  USING    P_GV_SPOOL_NO.

  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
      SRC_SPOOLID = P_GV_SPOOL_NO
      NO_DIALOG   = SPACE
    TABLES
      PDF         = IT_PDF.

ENDFORM.                    " READ_SPOOL
*&---------------------------------------------------------------------*
*&      Form  ZIP_FILE
*&---------------------------------------------------------------------*
FORM ZIP_FILE CHANGING P_GV_ZIP_FILE.
  DATA
        LO_ZIP   TYPE REF TO CL_ABAP_ZIP.
  DATA:NAME  TYPE STRING VALUE 'Internal_table_data.PDF'.

  DATA:
        CONTENT_X    TYPE XSTRING,
        CONTENT_S    TYPE STRING.

  "Prepare String.
  LOOP AT IT_PDF INTO WA_PDF.
    CONCATENATE CONTENT_S WA_PDF-TDLINE INTO CONTENT_S.
  ENDLOOP.
  "Convert String to XSTRING
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      TEXT   = CONTENT_S
    IMPORTING
      BUFFER = CONTENT_X.

  "Zip file
  CREATE OBJECT LO_ZIP.
  LO_ZIP->ADD( NAME = NAME  CONTENT = CONTENT_X ).
  P_GV_ZIP_FILE = LO_ZIP->SAVE( ).

ENDFORM.                    " ZIP_FILE
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_ZIP
*&---------------------------------------------------------------------*
FORM DOWNLOAD_ZIP  USING    P_GV_ZIP_FILE.
  "Types
  TYPES:
       TY_BINARY_DATA TYPE STRING .
  "Internal tables
  DATA:
        LT_BINARY_DATA TYPE STANDARD TABLE OF TY_BINARY_DATA,
        LT_BINARY_TAB  TYPE TYP_T_ADWP_RAW.

  DATA:
        LV_LENGTH     TYPE I.

  LV_LENGTH = XSTRLEN( P_GV_ZIP_FILE ).
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      BUFFER     = P_GV_ZIP_FILE
    TABLES
      BINARY_TAB = LT_BINARY_TAB.

  CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD(
  EXPORTING
    BIN_FILESIZE  = LV_LENGTH
    FILENAME      = 'C:\file001.zip'
    FILETYPE      = 'BIN'
  CHANGING
    DATA_TAB      = LT_BINARY_TAB ).

ENDFORM.                    " DOWNLOAD_ZIP

5 comments:

  1. Nice describe like it keep it up see sap community network for business management.

    ReplyDelete
  2. Thanks for sharing this valuable information..If anyone wants to get SAP Training in Chennai, please visit FITA Academy located at Chennai which offer best SAP Course in Chennai.



    ReplyDelete
  3. Thanks for sharing this valuable information.and I gathered some information from this blog. I did SAP Training Chennai, at FITA Academy located which offer best SAP Course Chennai with years of experienced professionals.

    ReplyDelete
  4. Thanks for sharing this informative blog..If anyone wants to get SAP ABAP Training in Chennai, please visit FITA Academy located at Chennai, rated as No.1 SAP Training Institute in Chennai.

    ReplyDelete
  5. Latest Govt Bank Railway Jobs 2016

    Hi, after reading this awesome article i am also happy to share my views here with colleagues.............

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.