Skip to Content
avatar image
Former Member

handling error messages in OOPs ALV

The question below is foolish.But I am a beginner so please excuse.

I have successfully displayed an OOPs ALV which displays the material, batch and plant.

A custom toolbar button(delete batches) has been appended to the standard toolbar.

Now when I do not select any rows from the ALV and click the button(delete batches) I have ensured that an error message flahes at the bottom of the screen.

If I repeat the same procedure without coming out of the program it exits from the program itself. i want to avoid this.

I want to flash the error message continually without coming out of the program till the user commits the mistake. Please note that I have not used any leave screen commands etc.

Can someone please help me..

Thanks in advance

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 07, 2008 at 07:52 AM

    I assume you have the ON TOOLBAR event regiistered and the ENTER event for example.

    method constructor .
    create object grid_container1
    *           container_name = 'CCONTAINER1'.
        container_name = cfname.
        create object  grid1
              i_parent = grid_container1.
        set handler z_object->on_user_command for grid1.
        set handler z_object->on_toolbar for grid1.
        set handler z_object->handle_data_changed for grid1.
        set handler z_object->handle_data_changed_finished for grid1.
        set handler z_object->on_dubbelklik for grid1.
        set handler z_object->on_hotspot for grid1.
        call method grid1->register_edit_event
               i_event_id = cl_gui_alv_grid=>mc_evt_enter.

    So the easy way to do this is in your ON USER COMMAND routine when you can check to see if you selected any rows and the issue a popup warnimg message with the standard SAP MESSAGE statement.

    For example in my TEST function here I call a method to get the selected cell.

    If none are selected you can then issue your message and you will then be returned back to your GRID display after the user presses the OK button on the message popup.

    the grid1 object refers to the class cl_gui_alv_grid.

    in your case call a method that gets selected cells rather than selected cell. Use the standard method in cl_gui_alv_grid.

    If nothing selected then issue your message.

    (Note that your method ON DATA CHANGE / ON DATA CHANGED FINISHED might also be entered as well so insure that you haven't got any coding in these methods that will interfere with processing flow).

    method on_user_command .
    *        FOR EVENT before_user_command OF cl_gui_alv_grid
    *        IMPORTING
    *          e_ucomm
    *          sender
    case e_ucomm.
          when 'EXIT'.
            leave program.
          when 'EXCEL'.
           call method me->download_to_excel.
          when 'SAVE'.
          when 'PROC'.
            call method me->process.
          when 'REFR'.
            call method me->refresh.
            when 'SWITCH'.
            call method me->switch.
           when 'TEST'.
            call method me->get_cell.
    method get_cell .
    break-point 1.
    call method grid1->get_current_cell
    e_row     = ls_row
    e_value   = ls_value
    e_col     = ls_col
    es_row_id = ls_row_id
    es_col_id = ls_col_id
    es_row_no = ls_row_no.



    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 07, 2008 at 08:12 AM

    Hello Srinibas

    I assume you handle the function "Delete batches" in your event handler HANDLE_USER_COMMAND.

    I would recommend the following approach:

    METHOD handle_user_command.
    * define local data
      DATA: lt_rows   TYPE lvc_t_row.
      CALL METHOD sender->get_selected_rows
          et_index_rows = lt_rows.  
      CASE e_ucomm.
        WHEN 'DEL_BATCH'.
          IF ( lt_rows IS INITIAL ).
            MESSAGE 'Please select at least a single row' TYPE 'S'.
            CALL METHOD cl_gui_cfw=>set_new_ok_code
                ok_code = 'DUMMY'.  " triggers PAI of the screen
    " ... delete batches
        WHEN others.

    In your PAI module USER_COMMAND_0100 add the following coding:

      CASE gd_okcde.
        WHEN 'DUMMY'.
        " do nothing -> just triggers PBO without any further action
        WHEN others.
       CLEAR: gd_okcode.  " ok-code field of your screen

    Advantage of this approach: after displaying the message the flow logic is at the very same point when the screen was displayed for the first time. Thus, the user will always get the same behaviour of the ALV list (if no row is selected).



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member


      What if the message is error type only -> as it comes from a standard FM like ENQUE_E_TABLE ?

      Is this program exiting situation anavoidable in the above case ?


      Salil Sonam