SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

Save Table Contents into Text File and Download File

This ABAP tutorial shows how to save contents of an internal table into a text file and download text file to a predefined folder using WS_DOWNLOAD ABAP function module. SAP data stored in an internal table can be transferred into a text file using the sample ABAP code given in this tutorial. The ABAP function module WS_DOWNLOAD is easy to use and can be preferred by ABAP developers for fast data export to text file from SAP system.

In following sample ABAP code, I read sample sales order header data from VBAK table into an internal table. Then when I call ws_download ABAP function module providing a valid folder or network share where my permissions are authenticated, a text file will be created with data transferred from internal table.

data ls_vbak type vbak.
data lt_vbak type table of vbak.

select * into TABLE lt_vbak from vbak
 where vbeln between '1427900030' and '1427900035'.

DATA filename LIKE RLGRAP-FILENAME .
filename = '\\kodyaz\c$\abap-codes\order.txt'.

CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
** BIN_FILESIZE = ' '
** CODEPAGE = ' '
FILENAME = filename
FILETYPE = 'ASC'
** MODE = ' '
** WK1_N_FORMAT = ' '
** WK1_N_SIZE = ' '
** WK1_T_FORMAT = ' '
** WK1_T_SIZE = ' '
** COL_SELECT = ' '
** COL_SELECTMASK = ' '
** NO_AUTH_CHECK = ' '
** IMPORTING
** FILELENGTH =
TABLES
data_tab = lt_vbak
* FIELDNAMES =
** EXCEPTIONS
** FILE_OPEN_ERROR = 1
** FILE_WRITE_ERROR = 2
** INVALID_FILESIZE = 3
** INVALID_TYPE = 4
** NO_BATCH = 5
** UNKNOWN_ERROR = 6
** INVALID_TABLE_WIDTH = 7
** GUI_REFUSE_FILETRANSFER = 8
** CUSTOMER_ERROR = 9
** NO_AUTHORITY = 10
** OTHERS = 11
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Code

As ABAP developers will realize this is an easy and simple yet powerful method to transfer or export data from SAP using text file.

write data in tex file using ABAP function module WS_DOWNLOAD



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.