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. 


10 comments:

  1. 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?
    Well 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.

    ReplyDelete
  2. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!

    SAP ABAP Training in Chennai

    ReplyDelete
  3. Hi at all,

    it 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.

    ReplyDelete
  4. SAP Web Dynpro Course in Noida
    https://erptraininginnoida.wordpress.com/2022/01/18/sap-web-dynpro-training-institute-in-noida/

    ReplyDelete
  5. SAP Web Dynpro Course in Noida
    https://erptraininginnoida.wordpress.com/2022/01/18/sap-web-dynpro-training-institute-in-noida/

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.