Tuesday, May 6, 2008

Sample ABAP Program to download table using new function GUI_DOWNLOAD

*&---------------------------------------------------------------------*
*& Report ZDOWNLOAD *
*& *
*&---------------------------------------------------------------------*
*& This program uses the new function GUI_DOWNLOAD *
*& Output will be TAB delimited and include MANDT *
*& It can be opened directly by Microsoft Excel *
*& To use this program for any Database Table replace ZTEST with *
*& new table name. *
*&---------------------------------------------------------------------*
*& AUTHOR: Sheila Titchener - abap at iconet-ltd.co.uk *
*& Date: February 2004 *
*&---------------------------------------------------------------------*

REPORT zdownload MESSAGE-ID bd.

DATA: w_tab TYPE ztest.
DATA: i_tab TYPE STANDARD TABLE OF ztest.

DATA: v_subrc(2),
v_recswritten(6).

PARAMETERS: p_file(80)
DEFAULT 'D:\\ICONET\\SAP\\ZTEST.DAT'.

DATA: filename TYPE string.

filename = p_file.

SELECT * FROM ztest INTO TABLE I_TAB.

* If text fields appear right justified or columns not lined up in output set
* TRUNC_TRAILING_BLANKS to X

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = filename
* FILETYPE = 'ASC'
* APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
* HEADER = '00'
TRUNC_TRAILING_BLANKS = 'X '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* IMPORTING
* FILELENGTH =
tables
data_tab = I_TAB
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
.

* SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *

IF sy-subrc <> 0.
v_subrc = sy-subrc.
MESSAGE e899 WITH 'File Open Error' v_subrc.
ENDIF.


DESCRIBE TABLE i_tab LINES v_recswritten.

MESSAGE i899 WITH v_recswritten 'Records Written from ZTEST'.

No comments:

Blog Archive