Scenario: Download the table contents into excel sheet with the button click can be achieved by using class CL_BSP_UTILITY àdownload.
Step1: Go to SE80 transaction select BSP application and provide the name of application.
Step2: Give the short description of application and assign package to application.
Step3: Right-click on application and create a page.
Step4: Provide the name and description of page.
Step5: CODE
Layout code:
<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<table width="100%" height="100%" border="0">
<tr>
<td bgcolor = "#FFFFFF" >
<center>
<%
if fl_flag = 1.
%>
table = "<%= t_flight %>"
width = "50%"
onRowSelection = "rowSelection"
design = "standard"
tableLayout = "AUTO"
footerVisible = "false" >
title = "Carrier Id" >
title = "Connection ID" >
title = "Flight Date" >
title = "Plane Type" >
<br><center>
text = "Download"
onClick = "test"
width = "20%"/>
<%endif.%>
center>
td>tr>
table>
content>
OnCreate Code:
select carrid connid fldate planetype from sflight into table t_flight
up to 10 rows.
if sy-subrc eq 0.
fl_flag = 1.
endif.
OnInPutProcessing Code:
* event handler for checking and processing user input and
* for defining navigation
DATA: button_event TYPE REF TO cl_htmlb_event_button ,
event TYPE REF TO if_htmlb_data.
DATA: ls_flight LIKE LINE OF t_flight.
DATA:
output TYPE string ,
l_xstring TYPE xstring,
app_type TYPE string.
event = cl_htmlb_manager=>get_event( request ).
IF event IS NOT INITIAL AND event->event_name =
htmlb_eventS=>BUTTON .
button_event ?= event .
CASE event->event_server_name.
WHEN 'test' .
IF t_flight IS NOT INITIAL.
LOOP AT t_flight INTO ls_flight.
CONCATENATE
output
ls_flight-carrid
cl_abap_char_utilities=>horizontal_tab
ls_flight-connid
cl_abap_char_utilities=>horizontal_tab
ls_flight-fldate
cl_abap_char_utilities=>horizontal_tab
ls_flight-planetype
cl_abap_char_utilities=>cr_lf
INTO output SEPARATED BY space.
ENDLOOP.
app_type = 'APPLICATION/MSEXCEL;charset=utf-16le'.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = output
mimetype = 'APPLICATION/MSEXCEL;charset=utf-16le'
IMPORTING
buffer = l_xstring.
CONCATENATE
cl_abap_char_utilities=>byte_order_mark_little
l_xstring INTO l_xstring
IN BYTE MODE.
CALL METHOD cl_bsp_utility=>download
EXPORTING
object_s = l_xstring
content_type = app_type
content_disposition ='attachment;filename=FlightDetails.xls
response = _m_response
navigation = navigation.
ENDIF.
ENDCASE.
ENDIF.
Page Attributes:
fl_flag TYPE I
fs_flight1 TYPE TYPE_S_FLIGHT
t_flight TYPE FS_FLIGHT
w_carrid TYPE SFLIGHT-CARRID
w_input TYPE STRING
Types Definition:
types:
begin of type_s_flight,
carrid type sflight-carrid,
connid type sflight-connid,
fldate type sflight-fldate,
planetype type sflight-planetype,
end of type_s_flight,
fs_flight type standard table of type_s_flight.
OUTPUT:
Step6: Layout is as follows with the flight details and user has option to download the table details with the button click.
Click on download button, Pop up appears asking to open or to save a file.
Popup appears for location of file and name of file.
Excel sheet is stored as flight details as follows:
No comments:
Post a Comment