10-09-2008 10:21 PM
Hi all,
I have an import parameter declared in a Class method .
in SE38 program i want to retrieve through export parameter .
But i am not able to figure how to defind the type of SENDER parameter . Please suggest if my perception is wrong or the point that i am missing here .
Regards,
Ry.
10-10-2008 2:45 AM
you don't need to give any type for it. in general we use sender parameter incase of even handling.
check this SAP standard demo code.. i just added sender addition to it in the event handler class method.
REPORT demo_class_counter_event.
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS increment_counter.
EVENTS critical_value EXPORTING value(excess) TYPE i.
PRIVATE SECTION.
DATA: count TYPE i,
threshold TYPE i VALUE 10.
ENDCLASS.
CLASS counter IMPLEMENTATION.
METHOD increment_counter.
DATA diff TYPE i.
ADD 1 TO count.
IF count > threshold.
diff = count - threshold.
RAISE EVENT critical_value EXPORTING excess = diff.
ENDIF.
ENDMETHOD.
ENDCLASS.
CLASS handler DEFINITION.
PUBLIC SECTION.
METHODS handle_excess FOR EVENT critical_value OF counter
IMPORTING excess sender. "sender parameter
ENDCLASS.
CLASS handler IMPLEMENTATION.
METHOD handle_excess.
break-point. "check in Debugging sender fills with the object automatically
WRITE: / 'Excess is', excess.
ENDMETHOD.
ENDCLASS.
DATA: r1 TYPE REF TO counter,
h1 TYPE REF TO handler.
START-OF-SELECTION.
CREATE OBJECT: r1, h1.
SET HANDLER h1->handle_excess FOR ALL INSTANCES.
DO 20 TIMES.
CALL METHOD r1->increment_counter.
ENDDO.
10-10-2008 2:45 AM
you don't need to give any type for it. in general we use sender parameter incase of even handling.
check this SAP standard demo code.. i just added sender addition to it in the event handler class method.
REPORT demo_class_counter_event.
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS increment_counter.
EVENTS critical_value EXPORTING value(excess) TYPE i.
PRIVATE SECTION.
DATA: count TYPE i,
threshold TYPE i VALUE 10.
ENDCLASS.
CLASS counter IMPLEMENTATION.
METHOD increment_counter.
DATA diff TYPE i.
ADD 1 TO count.
IF count > threshold.
diff = count - threshold.
RAISE EVENT critical_value EXPORTING excess = diff.
ENDIF.
ENDMETHOD.
ENDCLASS.
CLASS handler DEFINITION.
PUBLIC SECTION.
METHODS handle_excess FOR EVENT critical_value OF counter
IMPORTING excess sender. "sender parameter
ENDCLASS.
CLASS handler IMPLEMENTATION.
METHOD handle_excess.
break-point. "check in Debugging sender fills with the object automatically
WRITE: / 'Excess is', excess.
ENDMETHOD.
ENDCLASS.
DATA: r1 TYPE REF TO counter,
h1 TYPE REF TO handler.
START-OF-SELECTION.
CREATE OBJECT: r1, h1.
SET HANDLER h1->handle_excess FOR ALL INSTANCES.
DO 20 TIMES.
CALL METHOD r1->increment_counter.
ENDDO.
10-10-2008 5:25 PM
Hi Vijay,
Thank you for your reply . the problem i am having is the functionlaity of this report is it displays three grids and when ever i double click on a grid it should identify the particluar grid . i have highlighted in bold where i am encountering the problem. i am enclosing the class details and the report source code. Please suggest after going through it . thanks in advance.
Class details that i have created :
the class has a method handle_double_event with event handler double_click of CL_GUI_ALV_GRID . i have defined this in the method section.
in public section section :
public section.
types GO_GRID1 type ref to CL_GUI_ALV_GRID .
class-methods HANDLE_DOUBLE_CLICK
for event DOUBLE_CLICK of CL_GUI_ALV_GRID
importing
ES_ROW_NO
E_COLUMN
E_ROW
SENDER .
in handle_double_event code :
DATA:
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid,
go_grid3 TYPE REF TO cl_gui_alv_grid.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1,
gt_vbak TYPE STANDARD TABLE OF vbak,
gt_vbap TYPE STANDARD TABLE OF vbap.
define local data
DATA:
ls_knb1 TYPE knb1,
ls_vbak TYPE vbak,
ls_vbap TYPE vbap.
DATA: es_row_no type lvc_s_roid,
e_column type lvc_s_col,
e_row type lvc_s_row.
*CASE sender. - here when i double click on the first grid go_grid1 it should go inside the go_grid1 . but it is not entering .*
WHEN go_grid1.
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
IS_ROW_ID =
IS_COLUMN_ID =
is_row_no = es_row_no.
Triggers PAI of the dynpro with the specified ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code( 'ORDERS' ).
WHEN go_grid2.
READ TABLE gt_vbak INTO ls_vbak INDEX e_row-index.
CHECK ( ls_vbak-vbeln IS NOT INITIAL ).
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
IS_ROW_ID =
IS_COLUMN_ID =
is_row_no = es_row_no.
Triggers PAI of the dynpro with the specified ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code( 'ORDER_DET' ).
WHEN go_grid3.
READ TABLE gt_vbap INTO ls_vbap INDEX e_row-index.
CHECK ( ls_vbap-matnr IS NOT INITIAL ).
SET PARAMETER ID 'MAT' FIELD ls_vbap-matnr.
CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.
WHEN OTHERS.
RETURN.
ENDCASE.
endmethod.
Code for the Report that is accessing the class.
DATA:
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_splitter TYPE REF TO cl_gui_splitter_container,
go_splitter_2 TYPE REF TO cl_gui_splitter_container,
go_cell_top TYPE REF TO cl_gui_container,
go_cell_bottom TYPE REF TO cl_gui_container,
go_cell_left TYPE REF TO cl_gui_container,
go_cell_right TYPE REF TO cl_gui_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid,
go_grid3 TYPE REF TO cl_gui_alv_grid,
list type ref to zcl_eventhandler,
es_row_no type lvc_s_roid,
e_column type lvc_s_col,
e_row type lvc_s_row,
sender(8) type c.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1,
gt_vbak TYPE STANDARD TABLE OF vbak,
gt_vbap TYPE STANDARD TABLE OF vbap.
PARAMETERS : p_bukrs TYPE ekko-bukrs default '1000'.
START-OF-SELECTION.
create object list.
SELECT * FROM knb1 INTO TABLE gt_knb1
WHERE bukrs = p_bukrs.
Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 50
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Create splitter container
CREATE OBJECT go_splitter
EXPORTING
parent = go_docking
rows = 1
columns = 1
NO_AUTODEF_PROGID_DYNNR =
NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Get cell container
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cell_left.
container = go_cell_top.
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = go_cell_right.
Create 2nd splitter container
CREATE OBJECT go_splitter_2
EXPORTING
parent = go_cell_left
parent = go_cell_top
rows = 2
columns = 1
NO_AUTODEF_PROGID_DYNNR =
NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*
Get cell container
CALL METHOD go_splitter_2->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cell_top.
CALL METHOD go_splitter_2->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = go_cell_bottom.
Create ALV grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_cell_top
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT go_grid2
EXPORTING
i_parent = go_cell_bottom
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT go_grid3
EXPORTING
i_parent = go_cell_right
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD ZCL_EVENTHANDLER=>HANDLE_DOUBLE_CLICK
EXPORTING
ES_ROW_NO = ES_ROW_NO
E_COLUMN = E_COLUMN
E_ROW = E_ROW
SENDER.
Set event handler
SET HANDLER: list->handle_double_click FOR go_grid1.
SET HANDLER: list->handle_double_click FOR go_grid2.
SET HANDLER: list->handle_double_click FOR go_grid3.
Display data
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'KNB1'
CHANGING
it_outtab = gt_knb1
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
REFRESH: gt_vbak.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAK'
CHANGING
it_outtab = gt_vbak
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
REFRESH: gt_vbap.
CALL METHOD go_grid3->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAP'
CHANGING
it_outtab = gt_vbap
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
NOTE: dynpro does not contain any elements
CALL SCREEN '0100'.
Flow logic of dynpro:
*
*PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
**
*PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
END-OF-SELECTION.
&----
*& Form CUSTOMER_SHOW_ORDERS
&----
text
----
--> p1 text
<-- p2 text
----
FORM customer_show_orders .
define local data
DATA:
ld_row TYPE i,
ls_knb1 TYPE knb1.
CALL METHOD go_grid1->get_current_cell
IMPORTING
e_row = ld_row.
READ TABLE gt_knb1 INTO ls_knb1 INDEX ld_row.
CHECK ( syst-subrc = 0 ).
SELECT * FROM vbak INTO TABLE gt_vbak
WHERE kunnr = ls_knb1-kunnr.
REFRESH: gt_vbap.
ENDFORM. " CUSTOMER_SHOW_ORDERS
&----
*& Form ORDER_SHOW_DETAILS
&----
text
----
--> p1 text
<-- p2 text
----
FORM order_show_details .
define local data
DATA:
ld_row TYPE i,
ls_vbak TYPE vbak.
CALL METHOD go_grid1->get_current_cell
IMPORTING
e_row = ld_row.
READ TABLE gt_vbak INTO ls_vbak INDEX ld_row.
CHECK ( syst-subrc = 0 ).
SELECT * FROM vbap INTO TABLE gt_vbap
WHERE vbeln = ls_vbak-vbeln.
ENDFORM. " ORDER_SHOW_DETAILS
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "ORDERS"
SET TITLEBAR 'xxx'.
Refresh display of detail ALV list
CALL METHOD go_grid2->refresh_table_display
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
EXCEPTIONS
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Refresh display of detail ALV list
CALL METHOD go_grid3->refresh_table_display
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
EXCEPTIONS
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
MODULE USER_COMMAND_0100 INPUT.
move sy-ucomm to gd_okcode.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
User has pushed button "Display Orders"
WHEN 'ORDERS'.
PERFORM customer_show_orders.
WHEN 'ORDERS_DET'.
PERFORM order_show_details.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
endmodule.
Regards,
Ry
10-10-2008 5:29 PM
why are you defining the hander method as static method, try to change it to instance method and see..
10-10-2008 5:39 PM
Hi Vijay,
i didnt get your point , are you suggesting to change from static to instance in the class . if that is the case i have changed it , but there was no change .
if that is not the case , can you please suggest how to change it in the report program , iam trying to pull around but could not .
Thanks in advance .
Regards,
Ry
10-10-2008 5:59 PM
there is a problem with your code. i changed more of it. just see now
DATA:
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_splitter TYPE REF TO cl_gui_splitter_container,
go_splitter_2 TYPE REF TO cl_gui_splitter_container,
go_cell_top TYPE REF TO cl_gui_container,
go_cell_bottom TYPE REF TO cl_gui_container,
go_cell_left TYPE REF TO cl_gui_container,
go_cell_right TYPE REF TO cl_gui_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid,
go_grid3 TYPE REF TO cl_gui_alv_grid.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1,
gt_vbak TYPE STANDARD TABLE OF vbak,
gt_vbap TYPE STANDARD TABLE OF vbap.
class zcl_eventhandler definition.
PUBLIC SECTION.
* TYPES go_grid1 TYPE REF TO cl_gui_alv_grid .
METHODS handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
es_row_no
e_column
e_row
sender .
endclass.
* define local data
data:
ls_knb1 type knb1,
ls_vbak type vbak,
ls_vbap type vbap.
class zcl_eventhandler implementation.
* - here when i double click on the first grid go_grid1 it
* should go inside the go_grid1 . but it is not entering .*
method handle_double_click.
CASE sender.
when go_grid1.
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
is_row_no = es_row_no.
* triggers pai of the dynpro with the specified ok-code
call method cl_gui_cfw=>set_new_ok_code( 'ORDERS' ).
WHEN go_grid2.
READ TABLE gt_vbak INTO ls_vbak INDEX e_row-index.
CHECK ( ls_vbak-vbeln IS NOT INITIAL ).
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
is_row_no = es_row_no.
* triggers pai of the dynpro with the specified ok-code
call method cl_gui_cfw=>set_new_ok_code( 'ORDER_DET' ).
WHEN go_grid3.
READ TABLE gt_vbap INTO ls_vbap INDEX e_row-index.
CHECK ( ls_vbap-matnr IS NOT INITIAL ).
SET PARAMETER ID 'MAT' FIELD ls_vbap-matnr.
CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.
WHEN OTHERS.
RETURN.
ENDCASE.
ENDMETHOD. "
endclass.
*code for the report that is accessing the class.
PARAMETERS : p_bukrs TYPE ekko-bukrs DEFAULT '1000'.
START-OF-SELECTION.
data: list TYPE REF TO zcl_eventhandler .
CREATE OBJECT list.
i am thinking rest of the code is ok. just remove the code till above and paste this code and see..
10-10-2008 6:06 PM
Hi Vijay,
If i write the class definition and implementation explictly i mean in se38 program it is working fine for me . what i am trying here i am trying to include all the details in a class which i have created through se24 . and access it . when i am using that class it is not identifying . please suggest . Thanks
Regards,
Ry
10-10-2008 6:13 PM
>what i am trying here i am trying to include all the details in a class which i have created through se24 . >and access it . when i am using that class it is not identifying . please suggest . Thanks
you never mentioned this in your posts. in that case the method handle_double_click should be a event handler method to the event double_click of class cl_gui_alv_grid. did you define the class and method in that way..? and supply all the informtion to class when you are creating the object. that means you need to have a constructor method, which take all grids information and all tables information. so that you can access all the information in the method handle_double_click.
10-10-2008 6:31 PM
Vijay , may be my interpretaion was wrong in my first post , yeah i have defined the event handler the same you said and the report i am accessing the class using list as the instance of the class . the report is executing and the ouput is displayed in grid1 , but when i double click on it , it goes into the method handle_double_click , but at case SENDER , it it not retrieving the go_grid1.
Please suggest .
Regards,
Ry