Saturday, 10 August 2013

sample code To capture the Lead selection values in webdynpro abap

  DATA lo_nd_it_mara TYPE REF TO if_wd_context_node.
  DATA lt_it_mara TYPE wd_this->elements_it_mara.
  DATA ls_it_mara TYPE wd_this->element_it_mara.
  DATA it_mara_new TYPE wd_this->elements_it_mara.
  DATA ls_mara_new TYPE wd_this->element_it_mara.

*   navigate from <CONTEXT> to <IT_MARA> via lead selection
  lo_nd_it_mara = wd_context->get_child_node( name = wd_this->wdctx_it_mara ).
  lo_nd_it_mara->get_static_attributes_table( IMPORTING table = lt_it_mara ).


  DATA:   ld_element   TYPE REF TO if_wd_context_element,
          it_rows  TYPE wdr_context_element_set,
          wa_rows LIKE LINE OF it_rows.
  DATA: ld_index TYPE i.


*** to get the lead selected values


  ld_element   = lo_nd_it_mara->get_lead_selection( ).
  it_rows  = lo_nd_it_mara->get_selected_elements( including_lead_selection = abap_true ).

  LOOP AT it_rows INTO wa_rows.
    CALL METHOD wa_rows->get_static_attributes
      IMPORTING
        static_attributes = ls_mara_new."wa_selrow.

    READ TABLE lt_it_mara INTO ls_it_mara WITH KEY matnr = ls_mara_new-matnr.
    ld_index = sy-tabix. "index of selected row

    APPEND ls_it_mara TO it_mara_new.
  ENDLOOP.

  IF it_mara_new IS NOT INITIAL.
    DATA lo_nd_it_mara_new TYPE REF TO if_wd_context_node.
    DATA lt_it_mara_new TYPE wd_this->elements_it_mara_new.

* navigate from <CONTEXT> to <IT_MARA_NEW> via lead selection
    lo_nd_it_mara_new = wd_context->get_child_node( name = wd_this->wdctx_it_mara_new ).
    SORT it_mara_new BY matnr.
    lo_nd_it_mara_new->bind_table( it_mara_new ).
  ENDIF.