2009 Jul 29 9:10 PM
hy masters,
i'm newbye with oo alv,
i need to edit a cell of an alv by call a transaction (cn21).
If the transaction succed the cell is update else there is an error message.
After reading many post i understood that i need to create a methode in the PAI.
and i'm trying this code.
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'EDITA'.
CALL METHOD grid1->get_selected_rows
importing
et_index_rows = lt_rows[].
READ TABLE lt_rows INTO ls_rows INDEX 1.
IF SY-SUBRC = 0.
READ TABLE gt_outtab INTO gs_outtab INDEX ls_rows_index.
IF SY-SUBRC eq 0.
perform call_transaction using
gs_outtab-plnnr
'CN21' .
ENDIF.
ENDIF.
ENDCASE.
ENDMETHOD.I have two questions for you guys.
1) am i on the right direction?
2) how can i set the error message if the cn21 failed?
2009 Jul 30 11:30 AM
Hi,
1) Actually you are not implementing the method in PAI but rather in class which is a handler for particular event on ALV. But I think you already read that.
The question here is when you want this event to fire up:
- when you select option from ALV toolbar? -> for this is used event USER_COMMNAD
- when you change data entry in the cell? -> here is used i.e. event DATA_CHANGED
I think you mean the first, so you write it like:
"first define class which will be an event receiver
CLASS lcl_gui_alv_event_receiver DEFINITION.
PUBLIC SECTION.
"you need method for event user_command
METHODS: handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm sender.
ENDCLASS.
2) in method implementation
CLASS lcl_gui_alv_event_receiver IMPLEMENTATION.
METHOD handle_user_command.
...
"check if transaction failed.
message 'Transaction failed' type 'S' display like 'E'. "will show error message in status bar
ENDMETHOD.
ENDCLASS.
Last thing is to tell the system about your handlers. You do it
DATA: g_alv_event_ref TYPE REF TO lcl_gui_alv_event_receiver.
CREATE OBJECT g_alv_event_ref.
SET HANDLER: g_alv_event_ref->handle_user_command FOR g_alv_grid_ref.
Regards
Marcin
Hi,
1) Actually you are not implementing the method in PAI but rather in class which is a handler for particular event on ALV. But I think you already read that.
The question here is when you want this event to fire up:
- when you select option from ALV toolbar? -> for this is used event USER_COMMNAD
- when you change data entry in the cell? -> here is used i.e. event DATA_CHANGED
I think you mean the first, so you write it like:
"first define class which will be an event receiver
CLASS lcl_gui_alv_event_receiver DEFINITION.
PUBLIC SECTION.
"you need method for event user_command
METHODS: handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm sender.
ENDCLASS.
2) in method implementation
CLASS lcl_gui_alv_event_receiver IMPLEMENTATION.
METHOD handle_user_command.
...
"check if transaction failed.
message 'Transaction failed' type 'S' display like 'E'. "will show error message in status bar
ENDMETHOD.
ENDCLASS.
Last thing is to tell the system about your handlers. You do it
DATA: g_alv_event_ref TYPE REF TO lcl_gui_alv_event_receiver.
CREATE OBJECT g_alv_event_ref.
SET HANDLER: g_alv_event_ref->handle_user_command FOR g_alv_grid_ref.
Regards
Marcin
2009 Jul 30 11:30 AM
Hi,
1) Actually you are not implementing the method in PAI but rather in class which is a handler for particular event on ALV. But I think you already read that.
The question here is when you want this event to fire up:
- when you select option from ALV toolbar? -> for this is used event USER_COMMNAD
- when you change data entry in the cell? -> here is used i.e. event DATA_CHANGED
I think you mean the first, so you write it like:
"first define class which will be an event receiver
CLASS lcl_gui_alv_event_receiver DEFINITION.
PUBLIC SECTION.
"you need method for event user_command
METHODS: handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm sender.
ENDCLASS.
2) in method implementation
CLASS lcl_gui_alv_event_receiver IMPLEMENTATION.
METHOD handle_user_command.
...
"check if transaction failed.
message 'Transaction failed' type 'S' display like 'E'. "will show error message in status bar
ENDMETHOD.
ENDCLASS.
Last thing is to tell the system about your handlers. You do it
DATA: g_alv_event_ref TYPE REF TO lcl_gui_alv_event_receiver.
CREATE OBJECT g_alv_event_ref.
SET HANDLER: g_alv_event_ref->handle_user_command FOR g_alv_grid_ref.
Regards
Marcin
2009 Jul 30 6:38 PM
thanks for your reply.
the scenario is:
the user launch the report and the when the alv comes is allready in edit mode.
the user edit the cell he wants (plnnr).
select the row he edited.
click save ( or edita if i decided to put that button)... let's say there only save, this call the cn21 passing all the row data (with the new value).
i don't know if i'm clearer.
any way i tried this.
DATA: g_event_receiver TYPE REF TO lcl_event_receiver.
DATA: g_verifier TYPE REF TO lcl_event_receiver.
**************************************************************
* LOCAL CLASS Definition
**************************************************************
*§4.Define and implement event handler to handle event DATA_CHANGED.
*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
PRIVATE SECTION.
DATA: error_in_data TYPE c.
* Methods to modularize event handler method HANDLE_DATA_CHANGED:
METHODS: check_plnnr
IMPORTING
ps_good_plnnr TYPE lvc_s_modi
ps_plnnr LIKE gt_outtab
pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
ENDCLASSfor the implemantation i declare.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_data_changed.
* PERFORM data_changed USING er_data_changed.
* ENDMETHOD.
DATA: ls_good TYPE lvc_s_modi.
DATA: ls_good2 TYPE lvc_s_modi.
error_in_data = space.
LOOP AT er_data_changed->mt_good_cells INTO ls_good.
CASE ls_good-fieldname.
WHEN 'PLNNR'.
CALL METHOD check_plnnr
EXPORTING
ps_good_plnnr = ls_good
pr_data_changed = er_data_changed
ps_plnnr = ls_plnnr.
*§7.Display application log if an error has occured.
IF error_in_data EQ 'X'.
CALL METHOD er_data_changed->display_protocol.
ENDIF.
ENDCASE.
ENDLOOP.
ENDMETHOD.
METHOD check_plnnr.
DATA: l_plnnrtype TYPE plnnr.
*Get new cell value to check it.
CALL METHOD pr_data_changed->get_cell_value
EXPORTING i_row_id = ps_good_plnnr-row_id
i_fieldname = ps_good_plnnr-fieldname
IMPORTING e_value = l_plnnrtype.
*modify cell value.
CALL METHOD pr_data_changed->modify_cell
EXPORTING i_row_id = ps_good_plnnr-row_id
i_fieldname = 'PLNNR'
i_value = ls_plnnr-plnnr.
ENDMETHOD.
ENDCLASS.my pbo is like this.
*----
*
MODULE PBO OUTPUT *
*----
*
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container.
CREATE OBJECT grid1
EXPORTING i_parent = g_custom_container.
PERFORM select_data_and_init_style.
*§3.Provide the fieldname of the celltab field by using field
STYLEFNAME of the layout structure.
gs_layout-stylefname = 'CELLTAB'.
set substate of editable cells to deactivated
CALL METHOD grid1->set_ready_for_input
EXPORTING i_ready_for_input = 0.
CALL METHOD grid1->set_table_for_first_display
EXPORTING i_structure_name = 'ZSUBOUTPUT'
is_layout = gs_layout
CHANGING it_outtab = gt_outtab[].
PERFORM switch_edit_mode.
CALL METHOD grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
CREATE OBJECT g_event_receiver.
SET HANDLER g_event_receiver->handle_data_changed FOR grid1.
ENDIF.
ENDMODULE.
my PAI.
*----
*
MODULE PAI INPUT *
*----
*
MODULE pai INPUT.
CALL METHOD grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
CREATE OBJECT g_event_receiver.
SET HANDLER g_event_receiver->handle_data_changed FOR grid1.
DATA:l_valid TYPE c.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN '&DATA_SAVE'.
CALL METHOD grid1->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid = 'X'.
PERFORM call_transaction.
ENDIF.
WHEN OTHERS.
do nothing
ENDCASE.
ENDMODULE.
BUT MY CALL TRANSACTION FAILED because plnnr cell is empty (the saved didn't work).
did i forgot an event????
anyway i'll try to restart using your indication.
2009 Jul 31 9:13 AM
Hi Andre,
I think the problem sits in method check_plnnr :
METHOD check_plnnr.
"this method is called without any condition before, so each time modifies cell value
CALL METHOD pr_data_changed->modify_cell
EXPORTING i_row_id = ps_good_plnnr-row_id
i_fieldname = 'PLNNR'
i_value = ls_plnnr-plnnr. "here you are chaning cell value each time to initial value, LS_PLNNR is nowhere filled with any data
ENDMETHOD.
To fix it would suggest following logic
"Get new cell value to check it.
CALL METHOD pr_data_changed->get_cell_value
EXPORTING i_row_id = ps_good_plnnr-row_id
i_fieldname = ps_good_plnnr-fieldname
IMPORTING e_value = l_plnnrtype.
if l_plnnrtype > some_value. "check if value is the one you allow to enter
CALL METHOD er_data_changed->display_protocol.
"now modify cell value.
CALL METHOD pr_data_changed->modify_cell
EXPORTING i_row_id = ps_good_plnnr-row_id
i_fieldname = 'PLNNR'
i_value = ls_plnnr-plnnr.
endif.
get_cel_value should only be performed if you want to test value which is being entered. modify cell should only be called when you want to change the value user enters.
However you don't have to do that at all. If you agree to any value entered in the cell, then you can just skip the entire data_changed event. Now anything you enter in the cell will automatically reflect in output table.
On triggering save action, data are already in output table, so you can pass them correclty to called transaction.
Hope this helps
Marcin
2009 Jul 31 9:31 AM
ok i don't need to test the value, i only have to pass it and call the transaction, if the value is not good the transaction fails.
i'll try by calling only
CALL METHOD er_data_changed->display_protocol.
"now modify cell value.
CALL METHOD pr_data_changed->modify_cell
EXPORTING i_row_id = ps_good_plnnr-row_id
i_fieldname = 'PLNNR'
i_value = ls_plnnr-plnnr.thanx i'll let you know give points )
2009 Aug 01 9:59 AM
working perfectely, thanx for your help...i'll try to manage the tool bar and the menu.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |