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

Exporting SAP DATA to CSV Format .

Former Member
0 Likes
5,471

I need to know how can we export data from SAP data to a CSV Format file while downloading. It will be very helpful to me.

Thanks and regards.

Omer Farook.

6 REPLIES 6
Read only

Former Member
0 Likes
1,110

Omer,

I am assuming that you are trying to download the data to your application server.

Assuming you have the internal table T_DATA.

DATA FNAME(60) VALUE 'myfile'.

DATA : record type string.

OPEN DATASET FNAME FOR OUTPUT.

LOOP AT T_data.

CONCATENATE COLUMN1, COLUMN2, ... INTO RECORD SEPARATED BY ','.

TRANSFER RECORD TO FNAME

clear record

endloop.

CLOSE DATASET FNAME.

Regards,

Ravi

Note : If this solves your issus, please close the thread by marking the stars on left side of the screen.

Read only

Former Member
0 Likes
1,110

Omer,

I am assuming that you are trying to download the data to your application server.

Assuming you have the internal table T_DATA.

DATA FNAME(60) VALUE 'myfile'.

DATA : record type string.

OPEN DATASET FNAME FOR OUTPUT.

LOOP AT T_data.

CONCATENATE COLUMN1, COLUMN2, ... INTO RECORD SEPARATED BY ','.

TRANSFER RECORD TO FNAME

clear record

endloop.

CLOSE DATASET FNAME.

Regards,

Ravi

Note : If this solves your issus, please close the thread by marking the stars on left side of the screen.

Read only

Former Member
0 Likes
1,110

Hi,

Check this sample code...

report ztest.
type-pools:TRUXS.
data: begin of itab occurs 0,
      vbeln like vbap-vbeln,
      posnr like vbap-posnr,
      end of itab.
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

vijay

Read only

0 Likes
1,110

Hi Vijay. Thanks for your response. This function module is working with a semicolon and i need a comma to be inserted. if you have suggestions kindly help me.

regards

omer farook.

Read only

0 Likes
1,110

Hi Omer,

Inside the FM SAP_CONVERT_TO_CSV_FORMAT, field separator is hardcoded to semicolon. Irrespective of any value passed to FM, it will consider only semicolcon.

Thanks

Lakshman

Read only

0 Likes
1,110

Omer,

Simple solution for you would be to copy the FM SAP_CONVERT_TO_CSV_FORMAT into your own FM and pass COMMA instead of the hardcoded SEMICOLON to the FM.

Cheers

Nishanth