2007 Jun 15 8:52 AM
Hi,
can any one plz tell me the functionality for the FM "SAP_CONVERT_TO_CSV_FORMAT" with example.........
vijay
2007 Jun 15 9:00 AM
Hi Vijay,
Use the Function Module SAP_CONVERT_TO_CSV_FORMAT to convert the internal table into Comma seperated 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.Regards
Sudheer
Hi,
can any one plz tell me the functionality for the FM "SAP_CONVERT_TO_CSV_FORMAT" with example.........
vijay
2007 Jun 15 8:57 AM
2007 Jun 15 8:57 AM
Hi Vijay,
CSV means a text file, where the columns are separated by a character ";".
The best way to change a list to CSV is to create an internal table in the ABAP, with the structure of the required CSV.
You have to fill in this internal table.
Because you are running the program in background, you can't download the file, the best would be to store the file on the server in a separated directory.
1ST capture file from application server to internal table using open dataset and close data set.
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.
EX-
Coding -
TYPE-POOLS: truxs.
TYPES:
BEGIN OF ty_Line,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
END OF ty_Line.
TYPES: 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:\TEMP\test.txt'
TABLES
data_tab = itab1
EXCEPTIONS
OTHERS = 1.
Thanks,
Reward If Helpful.
2007 Jun 15 9:00 AM
Hi Vijay,
Use the Function Module SAP_CONVERT_TO_CSV_FORMAT to convert the internal table into Comma seperated 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.Regards
Sudheer
2007 Jun 15 11:59 AM
Hi,
Instead of the FM SAP_CONVERT_TO_CSV_FORMAT...You can use the FM SAP_CONVERT_TO_TEX_FORMAT...Which does the same thing..
<b>SAP_CONVERT_TO_TEX_FORMAT</b>
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.
<b>Code</b>
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.
You would have to modify the above code according to your requirements.
Regards,
Padmam.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |