09-25-2008 7:41 AM
Hi,
I need to set HOTSPOT for a field in O/P list using ALV-oops and when clecked should take me to Transaction VA01. Please help....
Thanks,
Prabhu
09-25-2008 8:36 AM
09-25-2008 7:57 AM
09-25-2008 8:14 AM
09-25-2008 8:36 AM
09-25-2008 9:22 AM
09-25-2008 1:23 PM
Hi,
Please go through this code it may help u.
REPORT zcls_alv_oops MESSAGE-ID z1.
TABLES : mara.
\*----
\
\*----
TYPES :
BEGIN OF t_mara,
matnr TYPE matnr,
mtart TYPE mtart,
maktx TYPE maktx,
END OF t_mara,
\*
BEGIN OF t_marc,
matnr TYPE matnr,
werks TYPE werks_d,
mtart TYPE mtart,
maktx TYPE maktx,
END OF t_marc.
\*----
\
\*----
DATA :
i_mara TYPE TABLE OF t_mara,
i_marc TYPE TABLE OF t_marc,
i_fcat1 TYPE lvc_t_fcat,
i_fcat2 TYPE lvc_t_fcat.
\*----
\
\*----
CONSTANTS :
c_cont1 TYPE scrfname VALUE 'CONT1',
c_cont2 TYPE scrfname VALUE 'CONT2'.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS:
s_matnr FOR mara-matnr NO INTERVALS.
SELECTION-SCREEN SKIP 1.
PARAMETERS :
p_hotspt RADIOBUTTON GROUP r1 DEFAULT 'X',
p_bttn RADIOBUTTON GROUP r1.
SELECTION-SCREEN END OF BLOCK b1.
\*
\* Class forward referncing.
CLASS lcl_rcvr_class DEFINITION DEFERRED.
\*----
\-
\* Pointers Declaration..
\*----
\-
DATA :
lp_rcvr TYPE REF TO lcl_rcvr_class,
lp_cont1 TYPE REF TO cl_gui_custom_container,
lp_cont2 TYPE REF TO cl_gui_custom_container,
lp_grid1 TYPE REF TO cl_gui_alv_grid,
lp_grid2 TYPE REF TO cl_gui_alv_grid.
\*----
\-
\* Local Class Definiton.
\*----
\-
CLASS lcl_rcvr_class DEFINITION.
PUBLIC SECTION.
METHODS :
hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id es_row_no,
\*
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column.
ENDCLASS.
\*----
\-
\* Local Class Implementation.
\*----
\-
CLASS lcl_rcvr_class IMPLEMENTATION.
METHOD hotspot_click.
DATA :
wa_mara TYPE t_mara,
wa_marc TYPE t_marc.
\*
DATA :
l_index TYPE sy-tabix.
\*
READ TABLE i_mara INTO wa_mara INDEX e_row_id-index.
IF sy-subrc EQ 0.
REFRESH i_marc.
SELECT matnr
werks
INTO TABLE i_marc
FROM marc
WHERE matnr EQ wa_mara-matnr.
\*
IF sy-subrc EQ 0.
LOOP AT i_marc INTO wa_marc.
l_index = sy-tabix.
wa_marc-mtart = wa_mara-mtart.
wa_marc-maktx = wa_mara-maktx.
MODIFY i_marc FROM wa_marc INDEX l_index
TRANSPORTING mtart maktx.
ENDLOOP.
CALL SCREEN 200.
ELSE.
MESSAGE e121 WITH text-005 wa_mara-matnr.
ENDIF.
ENDIF.
\*
ENDMETHOD.
\*
METHOD handle_double_click.
DATA :
wa_mara TYPE t_mara,
wa_marc TYPE t_marc.
\*
DATA :
l_index TYPE sy-tabix.
\*
READ TABLE i_mara INTO wa_mara INDEX e_row-index.
IF sy-subrc EQ 0.
REFRESH i_marc.
SELECT matnr
werks
INTO TABLE i_marc
FROM marc
WHERE matnr EQ wa_mara-matnr.
\*
IF sy-subrc EQ 0.
LOOP AT i_marc INTO wa_marc.
l_index = sy-tabix.
wa_marc-mtart = wa_mara-mtart.
wa_marc-maktx = wa_mara-maktx.
MODIFY i_marc FROM wa_marc INDEX l_index
TRANSPORTING mtart maktx.
ENDLOOP.
CALL SCREEN 200.
ELSE.
MESSAGE e121 WITH text-005 wa_mara-matnr.
ENDIF.
ENDIF.
\*
ENDMETHOD.
ENDCLASS.
\*----
\-
\* Start of Selection
\*----
\-
START-OF-SELECTION.
\* Extract the Material Master data for the Input Material.
SELECT a~matnr
a~mtart
b~maktx
INTO TABLE i_mara
FROM mara AS a
INNER JOIN makt AS b
ON a~matnr EQ b~matnr
WHERE a~matnr IN s_matnr
AND b~spras EQ sy-langu.
\*
END-OF-SELECTION.
IF NOT i_mara\[\] IS INITIAL.
\* Call Screen to display the Material Master data.
CALL SCREEN 100.
ELSE.
MESSAGE s121 WITH text-006.
ENDIF.
\*&----
\*
\*& Module DISP_GRID OUTPUT
\*&----
\*
\* text
\*----
\*
MODULE disp_grid OUTPUT.
\* Build the Field catelog for Material Master data.
PERFORM build_fcat.
\* Display the Material Master data using ALV.
PERFORM disp_alv.
\*
ENDMODULE. " DISP_GRID OUTPUT
\*&----
\*
\*& Module USER_COMMAND_0100 INPUT
\*&----
\*
\* text
\*----
\*
MODULE user_command_0100 INPUT.
\*
\*when exit or cancel is clicked program has to come out
CASE sy-ucomm.
WHEN 'EXIT' OR 'CANC'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
\*
ENDMODULE. " USER_COMMAND_0100 INPUT
\*&----
\*
\*& Form build_fcat
\*&----
\*
\* text
\*----
\*
\* \--> p1 text
\* <-\- p2 text
\*----
\*
FORM build_fcat.
\*
DATA : ws_fcat TYPE lvc_s_fcat.
\*
ws_fcat-fieldname = 'MATNR'.
ws_fcat-scrtext_m = text-001.
ws_fcat-tabname = 'I_MARA'.
IF p_hotspt EQ 'X'.
ws_fcat-hotspot = 'X'.
ENDIF.
APPEND ws_fcat TO i_fcat1.
CLEAR ws_fcat.
\*
ws_fcat-fieldname = 'MTART'.
ws_fcat-scrtext_m = text-002.
ws_fcat-tabname = 'I_MARA'.
APPEND ws_fcat TO i_fcat1.
CLEAR ws_fcat.
\*
ws_fcat-fieldname = 'MAKTX'.
ws_fcat-scrtext_m = text-003.
ws_fcat-tabname = 'I_MARA'.
APPEND ws_fcat TO i_fcat1.
CLEAR ws_fcat.
\*
ENDFORM. " build_fcat
\*&----
\*
\*& Form disp_alv
\*&----
\*
\* text
\*----
\*
\* \--> p1 text
\* <-\- p2 text
\*----
\*
FORM disp_alv.
\*
IF lp_cont1 IS INITIAL.
\* Create the Container Object of Material Master.
CREATE OBJECT lp_cont1
EXPORTING
container_name = c_cont1
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6 .
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
\* Create the Object for Grid of Material Master.
CREATE OBJECT lp_grid1
EXPORTING
i_parent = lp_cont1
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
\* Dipslay Material Master data by calling method.
CALL METHOD lp_grid1->set_table_for_first_display
CHANGING
it_outtab = i_mara
it_fieldcatalog = i_fcat1
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
\* Set Handler for the Hot Spot Event.
CREATE OBJECT lp_rcvr.
IF p_hotspt EQ 'X'.
SET HANDLER lp_rcvr->hotspot_click FOR lp_grid1.
ELSE.
SET HANDLER lp_rcvr->handle_double_click FOR lp_grid1.
ENDIF.
ENDIF.
\*
ENDIF.
\*
ENDIF.
\*
ENDIF.
\*
ENDFORM. " disp_alv
\*&----
\*
\*& Module STATUS_0100 OUTPUT
\*&----
\*
\* text
\*----
\*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN_STAT'.
SET TITLEBAR 'T_100'.
ENDMODULE. " STATUS_0100 OUTPUT
\*&----
\*
\*& Module STATUS_0200 OUTPUT
\*&----
\*
\* text
\*----
\*
MODULE status_0200 OUTPUT.
SET PF-STATUS 'PLANT_STAT'.
SET TITLEBAR 'T_200'.
ENDMODULE. " STATUS_0200 OUTPUT
\*&----
\*
\*& Module DISP_GRID_plant OUTPUT
\*&----
\*
\* text
\*----
\*
MODULE disp_grid_plant OUTPUT.
\* Build the Field catelog for Material Plant data.
PERFORM build_fcat_plant.
\* Display the Material Master Plant data using ALV.
PERFORM disp_alv_plant.
ENDMODULE. " DISP_GRID_plant OUTPUT
\*&----
\*
\*& Module USER_COMMAND_0200 INPUT
\*&----
\*
\* text
\*----
\*
MODULE user_command_0200 INPUT.
\*
\*when exit or cancel is clicked program has to come out
CASE sy-ucomm.
WHEN 'EXIT' OR 'CANC'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
\*
ENDMODULE. " USER_COMMAND_0200 INPUT
\*&----
\*
\*& Form build_fcat_plant
\*&----
\*
\* text
\*----
\*
\* \--> p1 text
\* <-\- p2 text
\*----
\*
FORM build_fcat_plant.
DATA : ws_fcat TYPE lvc_s_fcat.
\*
ws_fcat-fieldname = 'MATNR'.
ws_fcat-scrtext_m = text-001.
ws_fcat-tabname = 'I_MARC'.
APPEND ws_fcat TO i_fcat2.
CLEAR ws_fcat.
\*
ws_fcat-fieldname = 'WERKS'.
ws_fcat-scrtext_m = text-004.
ws_fcat-tabname = 'I_MARC'.
APPEND ws_fcat TO i_fcat2.
CLEAR ws_fcat.
\*
ws_fcat-fieldname = 'MTART'.
ws_fcat-scrtext_m = text-002.
ws_fcat-tabname = 'I_MARC'.
APPEND ws_fcat TO i_fcat2.
CLEAR ws_fcat.
\*
ws_fcat-fieldname = 'MAKTX'.
ws_fcat-scrtext_m = text-003.
ws_fcat-tabname = 'I_MARC'.
APPEND ws_fcat TO i_fcat2.
CLEAR ws_fcat.
\*
ENDFORM. " build_fcat_plant
\*&----
\*
\*& Form disp_alv_plant
\*&----
\*
\* text
\*----
\*
\* \--> p1 text
\* <-\- p2 text
\*----
\*
FORM disp_alv_plant.
IF lp_cont2 IS INITIAL.
\* Create the Container Object of Material Plant data.
CREATE OBJECT lp_cont2
EXPORTING
container_name = c_cont2
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
\* Create the Object for Grid of Material Plant data.
CREATE OBJECT lp_grid2
EXPORTING
i_parent = lp_cont2
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
\* Dipslay Material Plant data by calling method.
CALL METHOD lp_grid2->set_table_for_first_display
CHANGING
it_outtab = i_marc
it_fieldcatalog = i_fcat2
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
\*
ENDIF.
\*
ENDIF.
\*
ELSE.
\* Call method 'REFRESH_TABLE_DISPLAY' to refresh the grid data.
CALL METHOD lp_grid2->refresh_table_display.
ENDIF.
\*
ENDFORM. " disp_alv_plant
09-25-2008 7:28 PM