WS_DOWNLOAD functions to download data from SAP to your harddisk

Your program have to be executed on the Foreground as this function does not work when you submit your program for background processing as the application server is unable to locate your local hard disk.

Used transaction SO21 to set the file location based on the users desired.  The SAP standard program will pick the file location based on each user settings.

A sample abap/4 download program using the functions WS_DOWNLOAD.

**********************************************************
*  Download program using the functions WS_DOWNLOAD
**********************************************************
REPORT Zdownload.

TABLES: Zxxxx.

DATA: BEGIN OF TZXXXX OCCURS 100,
      LINE_NO(3),
      FILLER1(1),
      TXT50(50),
      AMOUNT(10),
      BUDAT(10),
      END OF TZXXXX.

PARAMETERS:  P-FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\TEMP\test.xls',
             S_FILE AS   CHECKBOX DEFAULT 'X'.

     MOVE  'No'           TO TZXXXX-LINE_NO.
     MOVE  'Description'  TO TZXXXX-TXT50.
     MOVE  'Amount'       TO TZXXXX-AMOUNT.
     MOVE  'DATE'         TO TZXXXX-BUDAT.
     APPEND TZXXXX.
     CLEAR  TZXXXX.

SELECT * FROM ZXXXX ORDER BY LINE_NO.
     MOVE  ZXXXX-LINE_NO  TO TZXXXX-LINE_NO.
     MOVE  ZXXXX-TXT50    TO TZXXXX-TXT50.
     WRITE ZXXXX-AMOUNT   TO TZXXXX-AMOUNT
                             USING EDIT MASK 'RRV_______.__'.
     WRITE ZXXXX-BUDAT    TO TZXXXX-BUDAT.
     APPEND  TZXXXX.
     CLEAR   TZXXXX.
ENDSELECT.

  CALL FUNCTION 'WS_DOWNLOAD'
     EXPORTING
*         BIN_FILESIZE        = ' '
*         CODEPAGE            = ' '
          FILENAME            = P-FILE
          FILETYPE            = 'DAT'
*         filetype            = 'WK1'
*         MODE                = ' '
*         WK1_N_FORMAT        = ' '
*         WK1_N_SIZE          = ' '
*         WK1_T_FORMAT        = ' '
*         WK1_T_SIZE          = ' '
*         COL_SELECT          = ' '
*         COL_SELECTMASK      = ' '
*     importing
*          filelength          =
     TABLES
          DATA_TAB            = TZXXXX
*         FIELDNAMES          =
     EXCEPTIONS
          FILE_OPEN_ERROR     = 1
          FILE_WRITE_ERROR    = 2
          INVALID_FILESIZE    = 3
          INVALID_TABLE_WIDTH = 4
          INVALID_TYPE        = 5
          NO_BATCH            = 6
          UNKNOWN_ERROR       = 7
          OTHERS              = 8.

IF SY-SUBRC = 0.
   SKIP.
   WRITE:/  'Very good, download successful'.
ELSE.
   FORMAT COLOR COL_TOTAL.
   SKIP.
   WRITE:/  'Error in Download'.
   SKIP.
   WRITE:/  'Is the file Open by Excel or Lotus?'.
ENDIF.

More Function Module
Functions / SAP Script / ALV

Tables
Database Table

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.