Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

handling error messages in OOPs ALV

Former Member

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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


method constructor .
create object grid_container1
        exporting
*           container_name = 'CCONTAINER1'.
    container_name = cfname.
    create object  grid1
       exporting
          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
        exporting
           i_event_id = cl_gui_alv_grid=>mc_evt_enter.
  endmethod.
 

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.

       endcase.


method get_cell .
break-point 1.
call method grid1->get_current_cell
importing
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.
endmethod.

cheers

jimbo

9 REPLIES 9

Former Member
0 Kudos

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


method constructor .
create object grid_container1
        exporting
*           container_name = 'CCONTAINER1'.
    container_name = cfname.
    create object  grid1
       exporting
          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
        exporting
           i_event_id = cl_gui_alv_grid=>mc_evt_enter.
  endmethod.
 

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.

       endcase.


method get_cell .
break-point 1.
call method grid1->get_current_cell
importing
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.
endmethod.

cheers

jimbo

uwe_schieferstein
Active Contributor
0 Kudos

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
    IMPORTING
      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
          EXPORTING
            ok_code = 'DUMMY'.  " triggers PAI of the screen

      ELSE.
" ... delete batches
      ENDIF.
    WHEN others.
    ENDCASE.

ENDMETHOD.

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.
   ENDCASE.
   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).

Regards

Uwe

0 Kudos

Hi Uwe

That's basically what I was telling the OP to do --yours makes it a bit clearer especially if the OP is relatively new in "Objects".

My approach doesn't require the PAI again but your logic is clearer for the beginner to work with.

Cheers

Jimbo

0 Kudos

Hi Uwe,

Thanks very much for ur effort.

Your method seems fine .

But the mesaage type u wanted me to send was 'S'.

But i want to send an error message of type 'E'.

Then will the solution u gave work ?

0 Kudos

Hello Srinibas

The situation gets more complicated if you are using an error message (type 'E'). In this case I am not sure if my solution will work.

However, I would recommend to use the 'S' type message because the user needs not to do anything special (like an additional ENTER on a selection-screen to "free" the screen from the error message).

Always try to develop from the perspective of the user, i.e. program user-friendly. If your users do not read the messages in the status bar then this is their problem, not yours.

Regards

Uwe

0 Kudos

Hi Uwe

I've tried both your method and mine in sending an E(rror) type message.

If you send an E(rror) message the program just exits both doing it your way and mine. I haven't debugged any further as it's better to send an infomational message so the user can take corrective action where possible rather than just terminate the program.

Cheers

jimbo

0 Kudos

Hi,

Ya you are right. I have tried with error messages. They do not seem to work.So I agree that it is always better to have an infirmation or a success message in its place.

Thanks a lot folks for all your help..

Regards

Srini

0 Kudos

Yes but this can be achieved through this way.

MESSAGE 'Your message' TYPE 'S' DISPLAY LIKE 'E'.

0 Kudos

@ALL

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 ?

Regards,

Salil Sonam