Skip to Content
author's profile photo Former Member
Former Member

File Download / Upload Question

Hi All,

In my BSP application, I am downloading the contents of internal table to a CSV file format. For this, i initially convert the data line to XSTRING using 'SCMS_STRING_TO_XSTRING' function module with the mimetype being 'APPLICATION/MSEXCEL; charset=utf-16le'. As can be seen in the below code, i then use the standard code to write the contents as an attachment. Please note that at this point, the file is stored as a CSV file, but the file type seems to be unicode text. I make some changes to the file and save it. And, i try to load the same file, i am getting a file open error. However, when i open the file in Excel and save as type 'CSV', i am able to successfully load it. How do i change so that the BSP save as File type "Comma Separated". Any help is greatly appreciated. Thanks,Raj

Below is the code:

Download File -

app_type = 'APPLICATION/MSEXCEL; charset=utf-16le'.

call function 'SCMS_STRING_TO_XSTRING'


text = lv_line_item

mimetype = app_type


buffer = l_xstring


failed = 1

others = 2.

mresponse->delete_header_field( name =

if_http_header_fields=>cache_control ).

mresponse->delete_header_field( name = if_http_header_fields=>expires


mresponse->delete_header_field( name = if_http_header_fields=>pragma


  • start Excel viewer either in the Browser or as a separate window

mresponse->set_header_field( name = 'content-disposition'

value = 'attachment; filename = test.csv' ).

data l_len type i.

l_len = xstrlen( lt_xstring ).

mresponse->set_data( data = lt_xstring

length = l_len ).

navigation->response_complete( ).

Upload File -

lcl_data ?= cl_htmlb_manager=>get_data(

request = runtime->server->request

name = 'fileUpload'

id = 'SalesFile').

lv_str =

cl_abap_conv_in_ce=>create( input = lcl_data->file_content ).

lv_str->read( importing data = v_filedata ).

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Posted on Aug 01, 2006 at 07:36 PM

    The problem is probably because you didn't add a BOM (Byte Order Mark) to the beginning of the file. The BOM tells the accepting operating system what Endian you used in your Unicode encoding. You are specifying UTF-16le. The le stands for Little Endian. Try adding some code like the following after the conversion to the binary string:

    ****Add the UTF-16 Little Endian Byte Order Mark to the begining of the file
      concatenate  cl_abap_char_utilities=>byte_order_mark_little
                   into r_xstring in byte mode.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 07:55 PM

    Thanks Thomas for your reply. I forgot to add a piece to my initial question. In the download section, after the call function 'SCMS_STRING_TO_XSTRING', I am doing the following process:

    • Add the Byte Order Mark - UTF-16 Little Endian

    concatenate cl_abap_char_utilities=>byte_order_mark_little


    into lt_xstring in byte mode.

    mresponse->set_header_field( name = 'content-type'

    value = 'APPLICATION/MSEXCEL; charset= utf-16le' ).

    So, I am already doing what you suggested me. But still, the file type is "Unicode text (.txt)". How do I make this "Comma separated"?. Thanks again.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2006 at 01:51 PM

    Hi All,

    Can someone give me suggestions as to how to fix this issue? I am missing a small thing which i can't figure out. Thanks again for your help.


    Add a comment
    10|10000 characters needed characters exceeded

    • I think you should prepare the data before calling SCMS_STRING_TO_XSTRING. It does not take care of CSV, DAT anad so on.

      You should use CONCATENATE statement looping on your reecords and columns...

      Did you had a look to the blog "Downloading data into Excel with Format Options (from SAP Web Applications)" /people/sergio.ferrari2/blog/2006/06/11/downloading-data-into-excel-with-format-options-from-sap-web-applications ?

      After reading the blog answer me: "Do you really need a csv file?"

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.