Skip to Content

how to handle errors in handle_user_command event in alv


I created editable alv

i created one custom button in tool bar of alv name COPY.

when user select any row and click copy that row should copy other wise it should through error message like 'select at least one row '.

here while copy i am not changing any data in alv.

for this requirement i wrote code in handle_user_command , if e_ucomm = 'COPY'

i called method get_selected_rows is this is intial then thorough the error .

first time i click on copy with out selecting any row it showing error , if i click copy again it is through out of the screen ,

can any one tell me how to rectify this issue see below my code.

METHOD handle_user_command.

   cl_gui_cfw=>set_new_ok_code( e_ucomm ).

IF e_ucomm EQ 'COPY'.

   DATA : lv_row TYPE lvc_t_row,
         lv_id TYPE   lvc_t_roid,
         lv_id1 LIKE LINE OF lv_id,
         l_valid TYPE char1.
     DATA : i_final2 TYPE TABLE OF t_final,
          w_final2 TYPE t_final,
          lv_index1 TYPE sy-index,
          lv_index2 TYPE sy-index,
          w_final4 TYPE t_final,
          lv_no TYPE i.

data : lo_data_changed type ref to cl_alv_changed_data_protocol,
        ls_outtab          LIKE LINE OF i_final.

   REFRESH lv_id.
   CLEAR : lv_index1 , lv_index2 , lv_no , w_final2 .

     CALL METHOD v_alvgd->get_selected_rows
         et_index_rows = lv_row
         et_row_no     = lv_id.

    READ TABLE lv_id INTO lv_id1 INDEX 1.
    lv_index1 = lv_id1-row_id  .
  IF LV_ID1-ROW_ID NE '0'.
      i_final_temp[] = i_final[].
       REFRESH i_final.
    DESCRIBE TABLE i_final_temp LINES lv_no.

    READ TABLE i_final_temp INTO w_final INDEX lv_index1.
    APPEND w_final TO i_final_temp.  " index lv_index2.
    i_final[] = i_final_temp[].
    REFRESH i_final_temp[].
     i_re_alv-row = 'X'.
     i_re_alv-col = 'X'.

     CALL METHOD v_alvgd->refresh_table_display
         is_stable      =  i_re_alv .
     IF sy-subrc <> 0.
*     Implement suitable error handling here
  ELSE .

message  'select at least one row' type 'E'.

Thanks in advance


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Dec 29, 2014 at 11:44 AM

    Hi Venkat,

         Try once by making that Error into success message like below. Actually i am doing the same in my report. it has worked for me..

    If LV_ID1-ROW_ID NE '0'.

      your funtionality...


      message  'select at least one row' type 'S'  display like 'E'.



       Anyhow it will display like an Error message, but process further internal processing..

       I hope it works.. let me know if you have any concerns..



    Add comment
    10|10000 characters needed characters exceeded

  • Dec 29, 2014 at 05:46 PM



    MESSAGE  'select at least one row' type 'S'  Display like 'E'.

    leave list-processing.

    Hope it helpful.



    Add comment
    10|10000 characters needed characters exceeded