cancel
Showing results for 
Search instead for 
Did you mean: 

ALV and Lead Selection

Former Member
0 Kudos

Dear experts,

what i want to do:

i have an ALV that displays me a lot of columns. I have a "delete" button too.

so when i mark a line and click on delete i want to delete the line.

My problem is that i can´t get the lead selection. I tried like this:

it worked with a normal table ui element.

please help

thanks and best regards

René

  • navigate from <CONTEXT> to <WORKLIST_TABELLE> via lead selection

lo_nd_worklist_tabelle = wd_context->get_child_node( name = wd_this->wdctx_worklist_tabelle ).

lead_selection = lo_nd_worklist_tabelle->get_lead_selection( ).

if lead_selection is initial.

l_cmp_api = wd_comp_controller->wd_get_api( ).

l_window_manager = l_cmp_api->get_window_manager( ).

move 'löschen ohne Selektion nicht möglich' to text.

append text to lt_text.

clear text.

endif.

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Rene,

The procedure to delete the selected row in ALV is the same as in a normal table ui element. Check the code fragment below:

DATA:  wd_node TYPE REF TO if_wd_context_node,
   lr_element TYPE REF TO if_wd_context_element.

" Get access to the desired context node
  wd_node = wd_context->get_child_node( name = 'NODE' ).

" Get the lead selection of the ALV
  lr_element = wd_node->get_lead_selection( ).

" Remove the element obtained through lead selection
  wd_node->remove_element( EXPORTING element = lr_element ).

The above coding is working perfectly fine for me. Just ensure that the lead selection property has not been disabled for your ALV. For example I use the below coding to enable multiple row selection for my ALV and disable lead selection property for the ALV.

 data: lr_table_settings  TYPE REF TO if_salv_wd_table_settings.
" Setting the ALV selection to multiple selection with no lead selection
 lr_table_settings->set_selection_mode( value = cl_wd_table=>e_selection_mode-multi_no_lead ).

Now then if I were to try delete multiple rows from the ALV I use the following coding for the same:

METHOD onactiondelete_rows .
  DATA:  wd_node TYPE REF TO if_wd_context_node,
         lr_element  TYPE REF TO if_wd_context_element,
         lt_element  TYPE wdr_context_element_set.

  wd_node = wd_context->get_child_node( name = 'NODE' ).

  CALL METHOD wd_node->get_selected_elements
    RECEIVING
      set = lt_element.

  LOOP AT lt_element INTO lr_element.
    wd_node->remove_element( EXPORTING element = lr_element ).
  ENDLOOP.
ENDMETHOD

.

Regards,

Uday

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Rene,

If you want to get the lead selection of the alv table there is a Event Handler method called ONLEADSELECT there you can capture the values of the lead selected values by using the method called GetStaticAtrributes( ).

As you were saying that you were able to create a button as delete and code for that Onclick of delete option you can write in event handler method ONUserFunction( ). There you write code of our own choice.

Hope this works

Regards,

Sana.

Former Member
0 Kudos

hi,

You need to write the code for 'save' button. in standard ALV ,'delete' button deletes the row in the screen only but inorder to effect this deletion in our table data , you need to write code explicitly for 'save' button.

please look in to below code...

DATA lo_nd_user_alv TYPE REF TO if_wd_context_node.

DATA lo_el_user_alv TYPE REF TO if_wd_context_element.

DATA ls_user_alv TYPE wd_this->element_user_alv.

DATA lt_user_alv TYPE wd_this->elements_user_alv.

  • navigate from <CONTEXT> to <USER_ALV> via lead selection

lo_nd_user_alv = wd_context->get_child_node( name = wd_this->wdctx_user_alv ).

  • @TODO handle not set lead selection

IF lo_nd_user_alv IS INITIAL.

ENDIF.

  • get element via lead selection

lo_el_user_alv = lo_nd_user_alv->get_element( ).

  • @TODO handle not set lead selection

IF lo_el_user_alv IS INITIAL.

ENDIF.

  • alternative access via index

DATA:v_indx LIKE sy-index.

DATA:i_mod TYPE TABLE OF y1atl_msa_usr_t,

wa_mod TYPE y1atl_msa_usr_t.

DO.

v_indx = v_indx + 1.

lo_el_user_alv = lo_nd_user_alv->get_element( index = v_indx ).

IF lo_el_user_alv IS NOT INITIAL.

  • get all declared attributes

lo_el_user_alv->get_static_attributes(

IMPORTING

static_attributes = ls_user_alv ).

ENDIF.

IF ls_user_alv-usrid IS NOT INITIAL.

APPEND ls_user_alv TO lt_user_alv.

MOVE-CORRESPONDING ls_user_alv TO wa_mod.

APPEND wa_mod TO i_mod.

  • wa_mod-mandt = sy-mandt.

  • CLEAR:wa_mod.

CLEAR ls_user_alv.

ELSE.

EXIT.

ENDIF.

ENDDO.

data v_index type sy-index .

data :i_Y1ATL_MSA_USR_T type table of Y1ATL_MSA_USR_T .

data :wa_Y1ATL_MSA_USR_T type Y1ATL_MSA_USR_T .

select * from Y1ATL_MSA_USR_T into table i_Y1ATL_MSA_USR_T .

loop at i_Y1ATL_MSA_USR_T into wa_Y1ATL_MSA_USR_T.

v_index = sy-tabix .

read table i_mod into wa_mod with key usrid = wa_Y1ATL_MSA_USR_T-usrid .

if sy-subrc = 0.

wa_Y1ATL_MSA_USR_T-NAME1 = wa_mod-name1 .

wa_Y1ATL_MSA_USR_T-email_id = wa_mod-email_id .

modify i_Y1ATL_MSA_USR_T from wa_Y1ATL_MSA_USR_T index v_index .

endif.

endloop.

IF i_mod[] IS NOT INITIAL.

MODIFY y1atl_msa_usr_t FROM TABLE i_Y1ATL_MSA_USR_T .

ENDIF.

DATA:i_exist TYPE TABLE OF y1atl_msa_usr_t,

wa_exist TYPE y1atl_msa_usr_t.

SELECT * FROM y1atl_msa_usr_t INTO TABLE i_exist.

IF sy-subrc EQ 0.

LOOP AT lt_user_alv INTO ls_user_alv.

READ TABLE i_exist INTO wa_exist WITH KEY usrid = ls_user_alv-usrid.

IF sy-subrc EQ 0.

DELETE i_exist WHERE usrid = ls_user_alv-usrid."INDEX v_index.

ENDIF.

ENDLOOP.

IF i_exist[] IS NOT INITIAL.

DELETE y1atl_msa_usr_t FROM TABLE i_exist.

ENDIF.

ENDIF.

ENDMETHOD.

Hope this will fulfill your requirement.

Regards,

sravan.

Former Member
0 Kudos

hi and thanks for your answers,

@svaran

navigate from via lead selection

which context do you mean ? How can i access the ALV ?

Because my data changes do not affect my node where i got the data from

but i want to save them there.

Thanks and best regards

René

uday_gubbala2
Active Contributor
0 Kudos

Hi Rene,

Have you managed to resolve your problem or are you still stuck up at some point? Do send out a blank email to the id in my business card so that I can send out an example coding along with snapshots for the same.

Regards,

Uday