You are on page 1of 6

Web Dynpro abap file download

Example to achieve the functionality

Create Web Dynpro Component and Save it a local object.

When we specify Window name and View name when we create web dynpro component, View is embedded in Window. Go to Component Controller o Context tab->Create node EMP_DET with cardinality 0..n

Method tab->Create GET_DATA method to prepare data for EMP_DET node.

Code
METHOD get_data . DATA lo_nd_emp_det TYPE REF TO if_wd_context_node. DATA lt_emp_det TYPE wd_this->elements_emp_det. * navigate from <CONTEXT> to <EMP_DET> via lead selection lo_nd_emp_det = wd_context->get_child_node( name = wd_this>wdctx_emp_det ). SELECT * FROM pa0002 INTO CORRESPONDING FIELDS OF TABLE lt_emp_det UP TO 30 ROWS. lo_nd_emp_det->bind_table( new_items = lt_emp_det set_initial_elements = abap_true ). ENDMETHOD.

Go to view DOWNLOAD_V o Context tab->Map Component Controller context to View Context.

Layout tab->Change layout property of ROOTUIELEMENTCONTAINER to MatrixLayout.

Layout tab->Create Table UI element ->Bind EMP_DET context node to table element->Set Layout data property to MatrixHeadData

Layout tab-> Create Button UI element for downloading file-> Create OnAction event DOWNLOAD_DATA for the button.

Code for the ONACTIONDOWNLOAD_DATA method.

Code
METHOD onactiondownload_data . DATA lo_nd_emp_det TYPE REF TO if_wd_context_node. DATA: lt_emp_det TYPE wd_this->elements_emp_det, ls_emp_det TYPE wd_this->element_emp_det. DATA: str TYPE string, xstr TYPE xstring. * navigate from <CONTEXT> to <EMP_DET> via lead selection lo_nd_emp_det = wd_context->get_child_node( name = wd_this>wdctx_emp_det ). lo_nd_emp_det->get_static_attributes_table( IMPORTING table = lt_emp_det ). "Prepare download file. LOOP AT lt_emp_det INTO ls_emp_det. CONCATENATE str ls_emp_det-pernr ls_emp_det-nachn ls_emp_det-vorna

ls_emp_det-gbdat cl_abap_char_utilities=>newline INTO str SEPARATED BY cl_abap_char_utilities=>horizontal_tab. ENDLOOP. CALL FUNCTION 'SCMS_STRING_TO_XSTRING' EXPORTING text = str IMPORTING buffer = xstr EXCEPTIONS failed = 1. "Attach file CALL METHOD cl_wd_runtime_services=>attach_file_to_response EXPORTING i_filename = 'Download.xls' i_content = xstr i_mime_type = 'EXCEL' i_in_new_window = abap_false i_inplace = abap_false. ENDMETHOD. o

Methods tab->Call GET_DATA method in WDDOINIT method to get EMP_DET node elements to display in Table.

method WDDOINIT . DATA lo_componentcontroller TYPE REF TO ig_componentcontroller . lo_componentcontroller = wd_this->get_componentcontroller_ctr( ). lo_componentcontroller->get_data( ). endmethod.

Save and Activate Web Dynpro component. Create Web Dynpro Application and Save it as local object.

Run Web Dynpro Application.

You might also like