Thursday, March 15, 2012
We use method CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE to download file from Web Dynpro Application.
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
- 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
- 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.
- 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.
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Step by step tutorial on Smart Forms - Template Node
- ABAP - Sending email with pdf attachment
- SAP Adobe Form - Steps to create simple ADOBE Form and calling it from ABAP Program
- SAP ABAP - CL_ABAP_CHAR_UTILITIES class usage
- ABAP - Multiple value selection from F4 help for SELECT-OPTIONS
- Execute ABAP Report using SUBMIT statement
- ABAP - Select all or Deselect all in ALV or Check box handling in ALV
- Web Dynpro ABAP ALV - ON_CLICK event
- ABAP - Dynamic WHERE clause
I am a SAP ABAP/ITS Consultant. I am working for one of the largest MNC in India as a SAP ABAP/ ITS developer from past one year. During this period I have been working on ABAP and Internet Transaction Server(ITS). My major work has been on ITS(Both of my Projects). So I would like to know whether I should continue working on ABAP/ITS or I should pursue a career in SAP WebDynpro and later go SAP EP Cretfication. Which would add much better value to my Career? Working on ABAP or a career in SAP WebDynpro?
ReplyDeleteWell got across this online course for SAP as well. http://www.wiziq.com/course/8153-sap-web-dynpro-pro-abap-training
Wonder it works for me.
Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!
ReplyDeleteSAP ABAP Training in Chennai
Hi at all,
ReplyDeleteit is not correct, the convertion "SCMS_STRING_TO_XSTRING" will not work!
It looks maybe logical but if you try it, than you will see, that it will not work.
Superb Post on SAP Module
ReplyDeleteSAP Training
SAP Training in Chennai
SAP Training in Bangalore
SAP Training in Hyderabad
SAP Training in Coimbatore
SAP Training in Ameerpet
SAP Training in India
Thanks for sharing this Information. SAP Dynpro Training in Gurgaon
ReplyDeleteThanks for sharing this Information. SAP Web Dynpro Institute in Gurgaon
ReplyDeleteThanks for Sharing this Information. SAP Dynpro Institute in Gurgaon
ReplyDelete
ReplyDeleteSAP Web Dynpro Training in Noida
SAP Web Dynpro Course in Noida
ReplyDeletehttps://erptraininginnoida.wordpress.com/2022/01/18/sap-web-dynpro-training-institute-in-noida/
SAP Web Dynpro Course in Noida
ReplyDeletehttps://erptraininginnoida.wordpress.com/2022/01/18/sap-web-dynpro-training-institute-in-noida/