Make your own free website on Tripod.com
 

SAP ABAP Programming, Functional and Basis Components Books


WS_DOWNLOAD functions

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.

Back to Previous

Return to SAP Hints and Tips on Configuration and ABAP/4 Programming