Very often as developers, we are required to write programs that read data based on some business logic, then download....
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
Usually this kind of requirement is handled using functions DOWNLOAD, WS_DOWNLOAD or GUI_DOWNLOAD. This feature has few drawbacks -- fixed length files, only tab/no delimited files, formats of date, quantity and currency fields.
All the above limitations can be very easily overcome by using the function SAP_CONVERT_TO_TEX_FORMAT. This function module will take any internal table as input and convert the data accordingly, using various formatting options defined at data element level, and it will give you the output in text format. In addition, this function will make use of any delimiter you want.
The program below demonstrates the above functionality. Here, we are reading data from table EKKO and downloading the data as '|' delimited file.
Editor's note: This tip works on SAP versions 4.6 or higher.
REPORT y_ss_test_ekko . * To hold selection data DATA: i_ekko TYPE STANDARD TABLE OF ekko. * To hold converted text data DATA: i_text(4096) TYPE c OCCURS 0. * Selection Screen PARAMETERS: p_ebeln LIKE ekko-ebeln. * Select data into an ITAB based on the selection Criteria SELECT * FROM ekko INTO TABLE i_ekko WHERE ebeln = p_ebeln. * Process further only if found some data IF NOT i_ekko IS INITIAL. * Convert data in internal table to a delimited text data CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT' EXPORTING i_field_seperator = '|' TABLES i_tab_sap_data = i_ekko CHANGING i_tab_converted_data = i_text EXCEPTIONS conversion_failed = 1 OTHERS = 2. IF sy-subrc <> 0. WRITE: / 'Program failed to Convert data.'. ELSE. * Download convert data to Presentation Server CALL FUNCTION 'DOWNLOAD' TABLES data_tab = i_text EXCEPTIONS OTHERS = 8. IF sy-subrc <> 0. WRITE: / 'Program failed to download data.'. ENDIF. ENDIF. ENDIF.