cancel
Showing results for 
Search instead for 
Did you mean: 

Downloading internal table as XL file from BSP Applications ?.

Former Member
0 Kudos

Hello,

Is there a way to download an internal table as an Excel file ?.

I referred this weblog and created a similar bsp element as mentioned but I ran into some issues.

/people/thomas.jung3/blog/2004/09/02/creating-a-bsp-extension-for-downloading-a-table

The BSP app I'm working is pretty small and simple, dont have those setup as mentioned in the above weblog.

Thanks in Advance,

Jay

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>mentioned but I ran into some issues

What kind of issues did you run into? Do you need an example of using this extension in a Page with Flow Logic? I probably have something laying around if that is the case.

Former Member
0 Kudos

Hi,

Yes, an example of this extension would be of great help. Could you please let me know.

My appl. is a simple one ( no controller classes), it just query info from table and display. If the user wants, it should download to an excel sheet.

I'm also trying with the other option mentioned earlier in this thread by Raja.

Thanks in advance,

Jay

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Sure here is a simple example (a stateless BSP):

I have two page attribues both with Auto Set

display_url TYPE	STRING        
isflight    TYPE	T_SFLIGHT	Flight

(T_SFLIGHT is a local Type Definition;

types: t_sflight type table of sflight.)

In my OnInitialization I have the following code:

select * from sflight into table isflight.

In OnInputProcessing I have the following code. This is the logic that will create the output object and place a URL to it in the display_url attribute. This is a stateless page so I have to reselect my data. I assume you already have a way to persist your data.

if event_id cs 'htmlb'.
  data: htmlb_event_ex type ref to if_htmlb_data.
  htmlb_event_ex ?= cl_htmlb_manager=>get_event_ex( request ).
  check htmlb_event_ex is not initial.
  if htmlb_event_ex->event_id cs 'DOWNLOAD'.
    data: itab type ref to data.
    select * from sflight into table isflight.
    get reference of isflight into itab.
    me->display_url = zcl_es_bsp_elmnt_dwn_tbl_excl=>handle_event(
                                                     htmlb_event_ex = htmlb_event_ex
                                                     runtime        = runtime
                                                     itab           = itab ).
  endif.
endif.

Finally I have the following very simple Layout(which basically just has my download button and a tableview that shows the data:

<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<%@extension name="xhtmlb" prefix="xhtmlb" %>
<%@extension name="phtmlb" prefix="phtmlb" %>
<%@extension name="ZDOWNLOAD" prefix="zdownload" %>
<htmlb:content design           = "DESIGN2003"
               controlRendering = "sap"
               rtlAutoSwitch    = "true" >
  <htmlb:page>
    <htmlb:form>
      <htmlb:tray id        = "tray"
                  width     = "100%"
                  hasMargin = "false"
                  title     = "<%= page->get_page_name( ) %>" >
        <htmlb:trayBody>
          <htmlb:gridLayout rowSize     = "2"
                            columnSize  = "1"
                            cellSpacing = "0" >
            <htmlb:gridLayoutCell columnIndex = "1"
                                  rowIndex    = "1" >
                            <zdownload:downloadTableExcel text        = "<%= me->text %>"
                                            onDownload  = "Download"
                                            id          = "Download"
                                            display_url = "<%= me->display_url %>" />
              <htmlb:tableView id              = "isflight"
                               table           = "<%= isflight %>"
                               visibleRowCount = "5" />
            </htmlb:gridLayoutCell>
            <htmlb:gridLayoutCell columnIndex = "1"
                                  rowIndex    = "2" >
            </htmlb:gridLayoutCell>
          </htmlb:gridLayout>
        </htmlb:trayBody>
      </htmlb:tray>
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

Answers (1)

Answers (1)

athavanraja
Active Contributor
0 Kudos

if you dont want develop the extension mentioned in the weblog you could simply do as follow.

create a bsp page with mime type set (in the page properties) to "<b>application/vnd.ms-excel</b>"

and in the layout

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">

<% loop at <itab > into <itab_wa> . %>

<tr>

<td><%= itab_wa-field1 %> </td>

<td><%= itab_wa-field2 %> </td>

<td><%= itab_wa-field3 %> </td>

</tr>

<% endloop. %>

</table>

open this page from a button in your original page. this would open the page in excel.

Note: your itab is generated in page1 to get the values in to this page you have to use server side cookies.

another approach:

generate the html for html table into a string variable.

and use the followig code in oninputprocessing

file_mime_type = 'application/vnd.ms-excel'.

file_content = <string var holding the html>.

file_length = STRLEN( file_content ).

response = runtime->server->response.

response->set_cdata( file_content ).

response->set_header_field( name = if_http_header_fields=>content_type

value = file_mime_type ).

response->delete_header_field( name =

if_http_header_fields=>cache_control ).

response->delete_header_field( name = if_http_header_fields=>expires ).

response->delete_header_field( name = if_http_header_fields=>pragma ).

response->set_header_field( name = 'content-disposition' value =

'attachment;filename=webform.xls' ).

navigation->response_complete( ). " signal that response is complete

Hope this is clear.

Regards

Raja