Skip to Content

SAP Gateway download Excel via Parameter &$format=xlsx -> Change Filename

Hey guys,

following Scenario: I want to download an Excel File through OData (SAP Gateway) via Parameter &$format=xlsx. How can I change the filename?

Refering to the documenation there is a field in the response that is responsible for the filename.

"The HTTP response header content-disposition is filled to suggest as file name the entity set name to the client:

content-disposition: attachment; filename=Employees.xlsx


But I am not able to set this field in my GET_ENTITYSET Method. Any ideas?

Thanks and regards


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Mar 18, 2018 at 11:36 AM

    This is standard HTTP, in other words: You have to add a simple http header to the response. However, you do this in GET_STREAM and not in GET_ENTITYSET.

    So in your redefined GET_STREAM do something like this:

        ls_header TYPE ihttpnvp,
        lv_filename type string.
    lv_filename     = 'Employees.xlsx'.  "get the value from somewhere...
    ls_header-name  = 'Content-Disposition'.
    ls_header-value = 'attachment; filename="' && lv_filename && '"'.
    me->/iwbep/if_mgw_conv_srv_runtime~set_header( is_header = ls_header ).  
    Add comment
    10|10000 characters needed characters exceeded

    • I had this same issue and this only works for the GET_STREAM method.

      The "Former member" was using XXX_GET_ENTITYSET because he/she is generating the excel file using the $format=xlsx query option.

      Although the code above is syntatically correct, it has no effect.

  • Oct 08, 2018 at 02:20 PM

    I did some investigation about it.

    First of all, please notice that the xlsx file is generated in the Front End System. So, nothing that you do in your back end will help here.

    The filename is generated in the following code snippet


    As you can see, there is no enhancement points in this piece of code. I do not recommend using an implicit enhancement inside method "lo_binary_provider->set_entity_header".

    Internally this uses interface "IF_SALV_EXPORT_CONFIGURATION" so it has the same advantages and disadvantages of exporting an internal table using the standard ALV export feature.

    Based on my conclusion this is unfortuntaly a limitation not specified in the documentation.

    Add comment
    10|10000 characters needed characters exceeded