Wednesday, March 14, 2012
Steps to achieve
  • Create Web Dynpro Component and Save as local object. 
  • No need to embed View into Window when you specify view and window.
  • Go to Component Controller ->Context tab-> Create two nodes EMP_DET - Cardinality 0..n and FILE with attribute FILE_CONTENTS of type XSTRING. 
  • Go to View UPLOAD_V ->Context tab->Map Component Controller context to View Context as shown below. 
  • Go to Layout tab 
    1. Set ROOTUIELEMENTCONTAINER layout type -MatrixLayout 
    2. Create Group UI element - Layout data - MatrixHeadData
    3. Create File Upload UI element inside Group and bind with context node FILE.
    4. Create button inside Group - Create OnAction event - UPLOAD_FILE
    5. method ONACTIONUPLOAD_FILE .
        DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
        lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).
          lo_componentcontroller->upload_file( ).
      
      endmethod.
      
    6. Create one Table UI element and bind with Context node EMP_DET.
  •  Go to Component Controller -> Method tab -> Write the below code in UPLOAD_FILE.
    METHOD upload_file .
      DATA:
            lo_nd_file    TYPE REF TO if_wd_context_node,
            lo_nd_emp_det TYPE REF TO if_wd_context_node,
            lt_emp_det    TYPE wd_this->elements_emp_det,
            lo_el_file    TYPE REF TO if_wd_context_element.
    
      DATA:
            ls_file    TYPE wd_this->element_file,
            ls_emp_det TYPE wd_this->element_emp_det,
            lt_bin     TYPE TABLE OF sdokcntbin,
            lt_txt     TYPE TABLE OF sdokcntasc,
            ls_txt     LIKE LINE OF lt_txt,
            lv_outlen  TYPE i.
    
    *   navigate from <context> to <file> via lead selection
      lo_nd_file = wd_context->get_child_node( name = wd_this->wdctx_file ).
    
    *   get element via lead selection
      lo_el_file = lo_nd_file->get_element( ).
    
    *   get all declared attributes
      lo_el_file->get_static_attributes(
        IMPORTING
          static_attributes = ls_file ).
      "XSTRING to BINARY
      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          buffer        = ls_file-file_contents
        IMPORTING
          output_length = lv_outlen
        TABLES
          binary_tab    = lt_bin.
      "Binary to Text file
      CALL FUNCTION 'SCMS_BINARY_TO_TEXT'
        EXPORTING
          input_length = lv_outlen
        TABLES
          binary_tab   = lt_bin
          text_tab     = lt_txt.
    
      LOOP AT lt_txt INTO ls_txt.
        SPLIT ls_txt AT cl_abap_char_utilities=>horizontal_tab INTO
                                                                        ls_emp_det-pernr
                                                                        ls_emp_det-nachn
                                                                        ls_emp_det-vorna
                                                                        ls_emp_det-gbdat.
    
        APPEND ls_emp_det TO lt_emp_det.
        CLEAR  ls_emp_det.
      ENDLOOP.
    * navigate from  to  via lead selection
      lo_nd_emp_det = wd_context->get_child_node( name = wd_this->wdctx_emp_det ).
      lo_nd_emp_det->bind_table( new_items = lt_emp_det set_initial_elements = abap_true ).
    
    ENDMETHOD.
    
  •  Create Web Dynpro Application and save it as local object.
  •  Run the application.

2 comments:

  1. i tried this but it is not working and the data i am getting like special characters

    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.