Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Convert to *.CSV format

Hi All~~

I want to convert a internal table to *.csv files, and set the seperator be ',' (not default value: ';' )

When I call a function "SAP_CONVERT_TO_CSV_FORMAT",

and set the parameter " I_FIELD_SEPERATOR = ',' " .

But it's seems didn't work.

The seperator is ';' still.

So.... Maybe somebody can tell me how to do? Thank you.

Tags:
Former Member
Former Member replied

Hi,

Check this code.

It is working fine now.

DATA: BEGIN OF ITAB_TEST OCCURS 0,
COLU_A(10) TYPE C,
COLU_B(10) TYPE C,
END OF ITAB_TEST.

DATA: Delimiter TYPE CHAR01 VALUE ','.
TYPES: BEGIN OF t_data,
        data(100) TYPE c,
        END OF t_data.
DATA: Ouput_String TYPE t_data OCCURS 0 WITH HEADER LINE.

INITIALIZATION.
DO 5 TIMES.
ITAB_TEST-COLU_A = 'TERENCE'.
ITAB_TEST-COLU_B = 'TERENCE'.
APPEND ITAB_TEST.
ENDDO.

START-OF-SELECTION.
LOOP AT ITAB_TEST.
CONCATENATE ITAB_TEST-COLU_A ITAB_TEST-COLU_B INTO Ouput_String-data
SEPARATED BY ','.
APPEND Ouput_String.
ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
*   BIN_FILESIZE                  =
    filename                      = 'E:\test.csv'
*   FILETYPE                      = 'ASC'
*   APPEND                        = ' '
   WRITE_FIELD_SEPARATOR         = '#'
*   HEADER                        = '00'
*   TRUNC_TRAILING_BLANKS         = ' '
*   WRITE_LF                      = 'X'
*   COL_SELECT                    = ' '
*   COL_SELECT_MASK               = ' '
*   DAT_MODE                      = ' '
* IMPORTING
*   FILELENGTH                    =
  tables
    data_tab                      = Ouput_String[]
 EXCEPTIONS
   FILE_WRITE_ERROR              = 1
   NO_BATCH                      = 2
   GUI_REFUSE_FILETRANSFER       = 3
   INVALID_TYPE                  = 4
   NO_AUTHORITY                  = 5
   UNKNOWN_ERROR                 = 6
   HEADER_NOT_ALLOWED            = 7
   SEPARATOR_NOT_ALLOWED         = 8
   FILESIZE_NOT_ALLOWED          = 9
   HEADER_TOO_LONG               = 10
   DP_ERROR_CREATE               = 11
   DP_ERROR_SEND                 = 12
   DP_ERROR_WRITE                = 13
   UNKNOWN_DP_ERROR              = 14
   ACCESS_DENIED                 = 15
   DP_OUT_OF_MEMORY              = 16
   DISK_FULL                     = 17
   DP_TIMEOUT                    = 18
   FILE_NOT_FOUND                = 19
   DATAPROVIDER_EXCEPTION        = 20
   CONTROL_FLUSH_ERROR           = 21
   OTHERS                        = 22
          .
IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

For test purpose i have declared occurs 0 and header line.

Please avoid those in ur coding.

Thanks,

Vinod.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question