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.

. SELECT * FROM pa0002 INTO CORRESPONDING FIELDS OF TABLE lt_emp_det UP TO 30 ROWS. * navigate from <CONTEXT> to <EMP_DET> via lead selection lo_nd_emp_det = wd_context->get_child_node( name = wd_this>wdctx_emp_det ). DATA lo_nd_emp_det TYPE REF TO if_wd_context_node.o Code METHOD get_data . lo_nd_emp_det->bind_table( new_items = lt_emp_det set_initial_elements = abap_true ). ENDMETHOD. DATA lt_emp_det TYPE wd_this->elements_emp_det. o Layout tab->Change layout property of ROOTUIELEMENTCONTAINER to MatrixLayout.  Go to view DOWNLOAD_V o Context tab->Map Component Controller context to View Context.

.o Layout tab->Create Table UI element ->Bind EMP_DET context node to table element->Set Layout data property to MatrixHeadData o Layout tab-> Create Button UI element for downloading file-> Create OnAction event DOWNLOAD_DATA for the button.

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

endmethod. CALL FUNCTION 'SCMS_STRING_TO_XSTRING' EXPORTING text = str IMPORTING buffer = xstr EXCEPTIONS failed = 1. DATA lo_componentcontroller TYPE REF TO ig_componentcontroller . Create Web Dynpro Application and Save it as local object. ENDLOOP. "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. method WDDOINIT . . lo_componentcontroller->get_data( ). o Methods tab->Call GET_DATA method in WDDOINIT method to get EMP_DET node elements to display in Table. lo_componentcontroller = wd_this->get_componentcontroller_ctr( ).ls_emp_det-gbdat cl_abap_char_utilities=>newline INTO str SEPARATED BY cl_abap_char_utilities=>horizontal_tab.   Save and Activate Web Dynpro component. ENDMETHOD.

. Run Web Dynpro Application.

Sign up to vote on this title
UsefulNot useful