06-09-2009 7:10 AM
Hello experts ,
.
can anybody plz tell me How to implement the line selection event in alv ? I want to retrieve value of the filed clicked by the user and query another table with that field value and display that data ....
06-09-2009 9:06 AM
hi Vivek,
first thing what u need to do is to create a event entry so that ur double click[USER_COMMAND] (same as at line selection for list)
event will be called and listened by a subroutine.
for that first u have to create a event entry for ALV.
data : gs_event TYPE slis_alv_event, "work area for event
gt_event TYPE slis_t_event. "internal table for event
*---passing events to event table
gs_event-name = 'USER_COMMAND'. "event name
gs_event-form = 'SUB_FOR_UCOMM'. "any subroutine name of ur wish
APPEND gs_event TO gt_event.
*--normally call ur ALV passing the reqd parameters
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* is_layout = gs_layout
it_fieldcat = gt_fcat
i_default = 'X'
i_save = 'A'
* is_variant = ls_variant
it_events = gt_event "------------------------->here u pass the event table
TABLES
t_outtab = gt_disp
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE gc_s NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
===============================================================
now create a subroutine SUB_FOR_UCOMM which will be called when USER_COMMAND will occur.
FORM sub_usecomm
USING ucomm TYPE sy-ucomm fields TYPE slis_selfield.
CLEAR gs_disp.
READ TABLE gt_disp INTO gs_disp INDEX fields-tabindex.
IF sy-subrc = 0 .
* SET PARAMETER ID gc_paramid FIELD gs_disp-gv_vbeln.
* CALL TRANSACTION gc_tcode AND SKIP FIRST SCREEN.
--------------------------
"do what ever code u need... all value u can get in the structure 'FIELD'
--------------------------------
-----------------------
ENDIF.
ENDFORM.
hope this helps
06-09-2009 7:13 AM
06-09-2009 7:44 AM
Hi,
In user command parameter of REUSE_ALV_GRID_DISPLAY give any input like 'USER_COMMAND_FORM'.
Here USER_COMMAND_FORM is the name of the form.
You write the form like the following in your code.
FORM USER_COMMAND_FORM USING UCO TYPE SY-UCOMM SF TYPE SLIS_SELFIELD.
CASE UCO.
WHEN '&NC1'.
w_matnr = SF-VALUE
ENDCASE.
ENDFORM. "USER_COMMAND
Here SF-VALUE will have the value of the cell which you clicked.
SF-TABINDEX will have the line number which you clicked. So, by line number also you can retrieve the value.
'&NC1' will be set as the sy-ucomm value when you double click a line in an ALV
Thanks and regards,
Venkat
Edited by: VENKAT RAMAN on Jun 9, 2009 12:14 PM
06-09-2009 7:48 AM
hi
In interactive ALV ,Please use the events
DATA :lv_event TYPE slis_t_event,
lv_wae LIKE LINE OF lv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
lv_wae-form = 'TOP-OF-PAGE'.
lv_wae-form = 'USER_COMMANE'.
Thanks
Dharma
06-09-2009 7:50 AM
06-09-2009 7:57 AM
Hi,
Below is the sample code.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = i_FCAT[]
TABLES
T_OUTTAB = i_invoice[]
EXCEPTIONS
PROGRAM_ERROR = 1
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.
FORM user_command USING pv_ucomm TYPE syucomm
ps_selfield TYPE slis_selfield.
----
*Handle the specific user-commands. *
----
CASE pv_ucomm.
----
Or some other GUI-functions *
----
----
Handle double click or hotspot on a specific field. *
These are some examples *
----
WHEN gc_double_click.
CASE ps_selfield-fieldname.
WHEN 'BELNR'.
i_invoice-belnr = g_belnr.
i_invoice-gjahr = g_gjahr.
READ TABLE i_invoice INDEX ps_selfield-tabindex.
IF sy-subrc EQ 0 AND NOT i_invoice-belnr IS INITIAL.
SET PARAMETER ID 'RBN' FIELD i_invoice-belnr.
SET PARAMETER ID 'GJR' FIELD i_invoice-gjahr.
CALL TRANSACTION 'MIR4' AND SKIP FIRST SCREEN.
ENDIF.
WHEN 'EBELN'.
READ TABLE i_invoice INDEX ps_selfield-tabindex.
IF sy-subrc EQ 0 AND NOT i_invoice IS INITIAL.
SET PARAMETER ID 'BES' FIELD i_invoice-ebeln.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDIF.
endcase.
endcase.
endform. "user_command
Regards,
Jayanth G
06-09-2009 9:06 AM
hi Vivek,
first thing what u need to do is to create a event entry so that ur double click[USER_COMMAND] (same as at line selection for list)
event will be called and listened by a subroutine.
for that first u have to create a event entry for ALV.
data : gs_event TYPE slis_alv_event, "work area for event
gt_event TYPE slis_t_event. "internal table for event
*---passing events to event table
gs_event-name = 'USER_COMMAND'. "event name
gs_event-form = 'SUB_FOR_UCOMM'. "any subroutine name of ur wish
APPEND gs_event TO gt_event.
*--normally call ur ALV passing the reqd parameters
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* is_layout = gs_layout
it_fieldcat = gt_fcat
i_default = 'X'
i_save = 'A'
* is_variant = ls_variant
it_events = gt_event "------------------------->here u pass the event table
TABLES
t_outtab = gt_disp
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE gc_s NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
===============================================================
now create a subroutine SUB_FOR_UCOMM which will be called when USER_COMMAND will occur.
FORM sub_usecomm
USING ucomm TYPE sy-ucomm fields TYPE slis_selfield.
CLEAR gs_disp.
READ TABLE gt_disp INTO gs_disp INDEX fields-tabindex.
IF sy-subrc = 0 .
* SET PARAMETER ID gc_paramid FIELD gs_disp-gv_vbeln.
* CALL TRANSACTION gc_tcode AND SKIP FIRST SCREEN.
--------------------------
"do what ever code u need... all value u can get in the structure 'FIELD'
--------------------------------
-----------------------
ENDIF.
ENDFORM.
hope this helps
06-09-2009 11:37 AM
hello soumya,
the solution suggested by you is fine , but can i do the same without calling a transaction ?
Suppose i want to take the field i clicked , as input value for a query and display that the result in a new screen similar to event at line selection for list report. Is this possible?
thanks
vivek
06-09-2009 11:38 AM
ofcoz its possible... u can create a screen and pass these values there...
06-09-2009 11:54 AM
hello somya ,
i am new to this subject , can u plz elaborate on the above answer or show with an example . thanks