Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Application server to CSV Format

Former Member
0 Likes
1,402

Hi All,

I have downloaded my internal table data to Application server with the help of Open Dataset and

Close Dataset.Now I want t download this Application server data to CSV Format.

Could you please tell me How can I do this in program?

Regards,

Amar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,134

Hi,

Data: <converted_format_workarea> TYPE text4096,

<converted_format_table> TYPE TABLE OF text4096.

<data_table> should have all the fields in character format.

DATA: lv_file_separator TYPE c.

lv_file_separator = ','. "give separator as comma (,)

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

i_field_seperator = lv_file_separator

TABLES

i_tab_sap_data = <data_table>

CHANGING

i_tab_converted_data = <converted_format_table>

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

DATA: lv_app_server_file TYPE string.

lv_file_name = <file_name>.

OPEN DATASET lv_app_server_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT <converted_format_table> INTO <converted_format_workarea>.

TRANSFER <converted_format_workarea> TO lv_app_server_file.

ENDLOOP.

CLOSE DATASET lv_app_server_file.

Hope it will help.

In case of doubt, reply.

Regards

Natasha Garg

Edited by: Natasha Garg on Apr 20, 2009 9:08 AM

9 REPLIES 9
Read only

Former Member
0 Likes
1,134

Hi Amar

Checkl the thread ,somewhat similar to yours

Hope it helps

S@chin

Read only

Former Member
0 Likes
1,134

hello,

Read the data from the application server into an internal table and then use FM ' GUI_DOWNLOAD' to download the contents into CSV file format.

Regards,

Mansi.

Read only

Former Member
0 Likes
1,134

Hi Amar,

Please follow the following code

  • Type(s) definition

TYPES: BEGIN OF ty_testfile,

field1 TYPE bukrs,

field2 TYPE anln1,

field3(10) TYPE c,

field4(10) TYPE c,

field5(10) TYPE c,

END OF ty_testfile.

TYPES: BEGIN OF ty_testfile_file,

field1(10) TYPE c,

field2(10) TYPE c,

field3(10) TYPE c,

field4(10) TYPE c,

field5(10) TYPE c,

END OF ty_testfile_file.

  • Work area(s) definition

DATA: wa_file_data TYPE text4096,

wa_testfile TYPE ty_testfile,

wa_testfile_file TYPE ty_testfile_file.

  • Internal table(s) definition

DATA: tb_file_data TYPE TABLE OF text4096,

tb_testfile TYPE TABLE OF ty_testfile,

tb_testfile_file TYPE TABLE OF ty_testfile_file.

  • EVENT - INITIALIZATION

INITIALIZATION.

  • EVENT - START OF SELECTION

START-OF-SELECTION.

  • Perform to upload data from a file

PERFORM upload_file.

PERFORM data_assign.

*&----


*

  • Form upload_file

*&----


*

  • To upload file data into SAP

*&----


*

FORM upload_file.

  • To read output in specified format from application server

PERFORM upload_app_server.

*To convert raw format to specified format

PERFORM data_convert.

ENDFORM. "upload_file

*&----


*

  • Form upload_app_server

*&----


*

  • To read file from application server

*&----


*

FORM upload_app_server.

DATA: lv_app_server_file TYPE string.

lv_app_server_file = 'pa_filep'.

  • To read file from Application server

OPEN DATASET lv_app_server_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

READ DATASET lv_app_server_file INTO wa_file_data.

IF sy-subrc = 0.

APPEND wa_file_data TO tb_file_data.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET lv_app_server_file.

ENDFORM. "upload_app_server

*&----


*

  • Form data_convert

*&----


*

  • To convert file to specified format

*&----


*

FORM data_convert.

DATA: lv_file_separator TYPE c.

lv_file_separator = ','.

  • To upload file in other formats(CSV, Tab delimited etc)

CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'

EXPORTING

i_field_seperator = lv_file_separator

i_tab_raw_data = tb_file_data

TABLES

i_tab_converted_data = tb_testfile_file

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.

ENDFORM. "data_convert

*&----


*

  • Form data_assign

*&----


*

  • To assign field value into character format

*&----


*

FORM data_assign.

LOOP AT tb_testfile_file INTO wa_testfile_file.

wa_testfile-field1 = wa_testfile_file-field1.

wa_testfile-field2 = wa_testfile_file-field2.

wa_testfile-field3 = wa_testfile_file-field3.

wa_testfile-field4 = wa_testfile_file-field4.

wa_testfile-field5 = wa_testfile_file-field5.

APPEND wa_testfile TO tb_testfile.

CLEAR wa_testfile.

ENDLOOP.

ENDFORM. "data_assign

Regards,

Manish

Read only

Former Member
0 Likes
1,134

hey..

if u want the data in CSV format then why don't u download the Data into the application server In CSV format

It will be Better

Separate the internal table data in CSV i.e Comma separated

take it to another internal table and download data into Application server in CSv format.

Read only

Former Member
0 Likes
1,135

Hi,

Data: <converted_format_workarea> TYPE text4096,

<converted_format_table> TYPE TABLE OF text4096.

<data_table> should have all the fields in character format.

DATA: lv_file_separator TYPE c.

lv_file_separator = ','. "give separator as comma (,)

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

i_field_seperator = lv_file_separator

TABLES

i_tab_sap_data = <data_table>

CHANGING

i_tab_converted_data = <converted_format_table>

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

DATA: lv_app_server_file TYPE string.

lv_file_name = <file_name>.

OPEN DATASET lv_app_server_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT <converted_format_table> INTO <converted_format_workarea>.

TRANSFER <converted_format_workarea> TO lv_app_server_file.

ENDLOOP.

CLOSE DATASET lv_app_server_file.

Hope it will help.

In case of doubt, reply.

Regards

Natasha Garg

Edited by: Natasha Garg on Apr 20, 2009 9:08 AM

Read only

0 Likes
1,134

Hi,

It is working perfectly but it is coming in one coloum only.

Means all the data is coming in one coloum of XL sheet.

Could you please tell me what should I do for that.

Read only

0 Likes
1,134

Hi,

It will come in one column only as it is a string now.

Regards

Natasha Garg

Read only

Former Member
0 Likes
1,134

type-pools:TRUXS.

data: ftab type TRUXS_T_TEXT_DATA.

CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'

EXPORTING

I_FIELD_SEPERATOR = ','

TABLES

I_TAB_SAP_DATA = itab

CHANGING

I_TAB_CONVERTED_DATA = ftab

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:\filename.txt'

TABLES

data_tab = ftab

EXCEPTIONS

OTHERS = 1.

Regards,

Joan

Read only

Former Member
0 Likes
1,134

Hi Amar,

You can use FM 'GUI_DOWNLOAD'.

You can refer to the below code:

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:\status.xls'

FILETYPE = 'DAT'

TABLES

DATA_TAB = IT_maintain.

Thanks,

Archana