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

CSV file type incorrect dowload into windows path as unicode txt instead *.CSV

Former Member
0 Likes
1,381

Hi all,

    CSV download report in which an output file produced in Shared server directory using OPEN DATASET OUTPUT in CSV file format and this file was readable but the File save as type in "Unicode *.txt" instead of *.CSV. File content contains Chinese character I have tried below two methods please advice me to correct it.

    p_path = *.CSV

                             

1.   OPEN DATASET p_path FOR OUTPUT IN BINARY MODE.

                                   

    IF sy-subrc EQ 0.

      CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

           EXPORTING

             text           = w_string

            MIMETYPE       =  'APPLICATION/MSEXCEL; charset=utf-16le'

            ENCODING       = '8400'"'4103'

          IMPORTING

            BUFFER         = w_xstring

          EXCEPTIONS

            FAILED         = 1

            OTHERS         = 2

                   .

         IF sy-subrc <> 0.

         ENDIF.

        concatenate  cl_abap_char_utilities=>byte_order_mark_little

                w_xstring

                into w_xstring in byte mode.

          TRANSFER w_xstring TO p_path.

        CLOSE DATASET p_path.

   endif

2.   OPEN DATASET p_path FOR OUTPUT IN BINARY MODE.

                                  

    IF sy-subrc EQ 0.

       TRY.

            cl_bcs_convert=>string_to_solix(

              EXPORTING

                iv_string   = w_string

                iv_codepage = '4103' 

                iv_add_bom  = 'X'    

              IMPORTING

                et_solix  = i_binary

                ev_size   = size ).

          CATCH cx_bcs.

            MESSAGE e445(so).

        ENDTRY.

     

        TRANSFER i_binary TO p_path.

    CLOSE DATASET p_path.

  endif.

Thanks,

Thiru.

Hi all,

    CSV download report in which an output file produced in Shared server directory using OPEN DATASET OUTPUT in CSV file format and this file was readable but the File save as type in "Unicode *.txt" instead of *.CSV. File content contains Chinese character I have tried below two methods please advice me to correct it.

    p_path = *.CSV

                             

1.   OPEN DATASET p_path FOR OUTPUT IN BINARY MODE.

                                   

    IF sy-subrc EQ 0.

      CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

           EXPORTING

             text           = w_string

            MIMETYPE       =  'APPLICATION/MSEXCEL; charset=utf-16le'

            ENCODING       = '8400'"'4103'

          IMPORTING

            BUFFER         = w_xstring

          EXCEPTIONS

            FAILED         = 1

            OTHERS         = 2

                   .

         IF sy-subrc <> 0.

         ENDIF.

        concatenate  cl_abap_char_utilities=>byte_order_mark_little

                w_xstring

                into w_xstring in byte mode.

          TRANSFER w_xstring TO p_path.

        CLOSE DATASET p_path.

   endif

2.   OPEN DATASET p_path FOR OUTPUT IN BINARY MODE.

                                  

    IF sy-subrc EQ 0.

       TRY.

            cl_bcs_convert=>string_to_solix(

              EXPORTING

                iv_string   = w_string

                iv_codepage = '4103' 

                iv_add_bom  = 'X'    

              IMPORTING

                et_solix  = i_binary

                ev_size   = size ).

          CATCH cx_bcs.

            MESSAGE e445(so).

        ENDTRY.

     

        TRANSFER i_binary TO p_path.

    CLOSE DATASET p_path.

  endif.

Thanks,

Thiru.

6 REPLIES 6
Read only

Former Member
0 Likes
1,054
Read only

0 Likes
1,054

Hi Shambu,

Thanks for you help. I have checked the above mentioned like already in this link they given only for GUI download but in my case it's application server path download ( windows server path) meaning report batch job not foreground even I tried the given below FM to covert text to CSV format but it vain.

     SAP_CONVERT_TO_TEX_FORMAT

Thanks,

Thiru

Read only

0 Likes
1,054

Hi,

Try using SAP_CONVERT_TO_CSV_FORMAT for converting to CSV format and for downloading to application server use OPEN DATASET.

Thanks,
Shambu

Read only

0 Likes
1,054

Hi,

SAP_CONVERT_TO_CSV_FORMAT not supporting double byte (chinese text).

Thanks and Regards,

Thiru.

Read only

0 Likes
1,054

use GUI_download function module.

Read only

Clemenss
Active Contributor
0 Likes
1,054

Hi Thirumurugan Durai,

a .CSV file will be pure character file, columns separated by tab or ";" or ',' separator.

Thus you should not use any X type data. Lines should be separated by cl_abap_char_utilities=>NEWLINE for the server, CR_LF for the client.

Then just

OPEN DATASET p_path FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .

and transfer your STRING to dataset.

No conversion, no function call.

I suppose you are on Unicode.

-> simplicity rules

If trouble not resolved: How do you create w_string?

Regards

Clemens