Register Login

How to download Data in Internal table of CSV file?

Updated May 18, 2018

Downloading Data in Internal table of CSV file

Use the Function Module SAP_CONVERT_TO_CSV_FORMAT to convert the internal table into Comma separated format then download this internal table using the Function Module GUI_DOWNLOAD.

See a sample program below:

TYPE-POOLS: truxs.

TYPES:

BEGIN OF ty_Line,

vbeln LIKE vbap-vbeln,

posnr LIKE vbap-posnr,

END OF ty_Line.

ty_Lines TYPE STANDARD TABLE of ty_Line WITH DEFAULT KEY.

DATA: itab TYPE ty_Lines.

DATA: itab1 TYPE truxs_t_text_data.

SELECT

vbeln

posnr

UP TO 10 ROWS

FROM vbap

INTO TABLE itab.

CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'

EXPORTING

i_field_seperator = ';'

TABLES

i_tab_sap_data = itab

CHANGING

i_tab_converted_data = itab1

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:TEMPtest.txt'

TABLES

data_tab = itab1

EXCEPTIONS

OTHERS = 1.

 


×