2006 Jul 11 4:24 PM
Hello,
I am trying to find an event that would be triggered when I select a line in an ALV Grid. Has anyone any experience with that.
I need to handle line selection because I want to mark an appropriate node in an ALV Tree on the left side of the window as soon as a line is selected.
Regards,
Eglese
2006 Jul 11 4:33 PM
hi,
user command is a event which will get trigger when you click a line , if at all you are using your own pf status then check choose insert pick.
regards,
Manohar.
2006 Jul 11 4:33 PM
2006 Jul 11 4:33 PM
hi,
user command is a event which will get trigger when you click a line , if at all you are using your own pf status then check choose insert pick.
regards,
Manohar.
2006 Jul 11 4:46 PM
Hi Manohar,
My alv grid is in a subscreen. I can not use pf status. Is there any other solution without pf status.
Eglese
2006 Jul 11 4:58 PM
As there is no direct event when you select the line, you can add a custom button to the grid's toolbar and have the user click on it after selecting the grid lines. Then you can get the selected rows using the method, GET_SELECTED_ROWS.
Regards,
Ravi
2006 Jul 12 10:11 AM
Hi,
look into this code this may help you
&----
*& Report Z_ALV_TREE_MANOHAR *
*& *
&----
*& *
*& *
&----
report z_alv_tree_manohar .
class cl_gui_cfw definition load.
class cl_gui_column_tree definition load.
data: obj_tree type ref to cl_gui_alv_tree,
obj_custom_container type ref to cl_gui_custom_container.
data: tb_fieldcat type lvc_t_fcat,
g_new_node_key type lvc_nkey.
data: ok_code type sy-ucomm.
data: tb_mara type zmara_mano occurs 0,
tb_mara1 type zmara_mano occurs 0,
x_mara type zmara_mano.
start-of-selection.
end-of-selection.
Calling screen 100
call screen 100.
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
module status_0100 output.
set pf-status 'ZMENU'.
SET TITLEBAR 'xxx'.
perform init_tree.
endmodule. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
module user_command_0100 input.
case ok_code.
when 'BACK' or 'EXIT' or ' CANCEL'.
leave to screen 0.
when others.
call method cl_gui_cfw=>dispatch.
endcase.
clear ok_code.
call method cl_gui_cfw=>flush.
endmodule. " USER_COMMAND_0100 INPUT
&----
*& Form INIT_TREE
&----
text
----
form init_tree .
create fieldcatalog for TB_MARA
perform build_fieldcatalog.
CREATE CUSTOM CONTAINER
create object obj_custom_container
exporting
PARENT =
container_name = 'TREE1'
STYLE =
LIFETIME = lifetime_default
REPID =
DYNNR =
NO_AUTODEF_PROGID_DYNNR =
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
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 TREE
create object obj_tree
exporting
LIFETIME =
parent = obj_custom_container
SHELLSTYLE =
node_selection_mode = cl_gui_column_tree=>node_sel_mode_sinGLE
HIDE_SELECTION =
item_selection = 'X'
NO_TOOLBAR =
NO_HTML_HEADER =
I_PRINT =
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7
others = 8.
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 obj_tree->set_table_for_first_display
EXPORTING
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_HIERARCHY_HEADER =
IS_EXCEPTION_FIELD =
IT_SPECIAL_GROUPS =
IT_LIST_COMMENTARY =
I_LOGO =
I_BACKGROUND_ID =
IT_TOOLBAR_EXCLUDING =
IT_EXCEPT_QINFO =
changing
it_outtab = tb_mara1
IT_FILTER =
it_fieldcatalog = tb_fieldcat
.
expand first level
call method obj_tree->expand_node
exporting
i_node_key = g_new_node_key
I_LEVEL_COUNT = 1
I_EXPAND_SUBTREE =
exceptions
failed = 1
illegal_level_count = 2
cntl_system_error = 3
node_not_found = 4
cannot_expand_leaf = 5
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.
Get data
select matnr
ersda
ernam
mtart
into table tb_mara
from mara
where mtart = 'FERT'.
loop at tb_mara into x_mara.
perform add_mara using x_mara.
endloop.
this method must be called to send the data to the frontend
call method obj_tree->frontend_update.
endform. " INIT_TREE
&----
*& Form build_fieldcatalog
&----
text
----
form build_fieldcatalog .
call function 'LVC_FIELDCATALOG_MERGE'
exporting
I_BUFFER_ACTIVE =
i_structure_name = 'ZMARA_MANO'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME = 'TB_MARA'
changing
ct_fieldcat = tb_fieldcat
exceptions
inconsistent_interface = 1
program_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.
endform. " build_fieldcatalog
&----
*& Form ADD_MARA
&----
text
----
form add_mara using p_mara type zmara_mano.
data: l_node_text type lvc_value.
data: l_mara type zmara_mano.
l_node_text = p_mara-matnr.
call method obj_tree->add_node
exporting
i_relat_node_key = ' '
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = l_mara
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = l_node_text
importing
e_new_node_key = g_new_node_key
exceptions
relat_node_not_found = 1
node_not_found = 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.
call method obj_tree->add_node
exporting
i_relat_node_key = g_new_node_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = x_mara
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = l_node_text
IMPORTING
E_NEW_NODE_KEY = l_new_node_key
exceptions
relat_node_not_found = 1
node_not_found = 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.
endform. " ADD_MARA
reagards,
Manohar.
2006 Jul 11 4:41 PM
REPORT Z_ZYMM_ERR_UTILITY
NO STANDARD PAGE HEADING
MESSAGE-ID Z1
LINE-SIZE 132.
************************************************************************
*
M O D I F I C A T I O N L O G *
************************************************************************
TYPE-POOLS : SLIS.
*-- Tables
************************************************************************
*-- Table for field catalog
DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE .
*-- Work area for Layout
DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
************************************************************************
*-- Variables
************************************************************************
DATA: L_PLANT LIKE MARC-WERKS,
L_STGLOC LIKE MARD-LGORT,
V_TABIX LIKE SY-TABIX,
V_PAC_CNT LIKE SY-TABIX,
V_PO_CNT LIKE SY-TABIX,
V_PO_ERRS LIKE SY-TABIX,
V_IV_ERRS LIKE SY-TABIX,
V_IV_CNT LIKE SY-TABIX,
V_SUCC(1) TYPE C,
V_PO_ITM(6),
V_IV_ITM(6),
V_MODE(1) VALUE 'N',
V_ND_FLAG TYPE C, " No data flag.
V_PONO LIKE EKKO-EBELN, " Purchasing document number
V_INVNO LIKE RBKP-BELNR, " Document number of an invoice
L_BSART LIKE EKKO-BSART, " Order type
V_EMPTY TYPE C, " no data in pac for errors
V_XBLNR LIKE RBKP-XBLNR,
V_INV_SUCC, " Flag-Invoice Success
V_REPID LIKE SY-REPID,
V_UNAME LIKE SY-UNAME,
V_TABLE TYPE SLIS_TABNAME,
V_UN_FLAG TYPE C,
V_DISPO LIKE T024D-DISPO.
************************************************************************
*-- Constants
************************************************************************
***********************************************************************
*-- Selection Screen
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK S WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_INVNO FOR ZYMMTE_SCMPO-Y3INVNO,
S_PO_NO FOR ZYMMTE_SCMPO-Y3PO_NO.
SELECTION-SCREEN END OF BLOCK S.
************************************************************************
*-- Initialization
************************************************************************
INITIALIZATION.
V_REPID = SY-REPID.
V_UNAME = SY-UNAME.
V_TABLE = 'IT_FINAL_SCMPO'.
************************************************************************
*-- Start of selection
************************************************************************
START-OF-SELECTION.
*--Get data from the Error table for PO creation (ASN)
PERFORM GET_ERR_DATA.
*--> Get ASN data to reprocess
IF V_ND_FLAG <> 'X'.
IF NOT IT_ZYMMTE_SCMPO[] IS INITIAL.
PERFORM GET_ASN_DATA.
PERFORM GET_SPQ_PLANCODE.
*--Perform for Field catalog filling
PERFORM FIELD_CATALOG.
PERFORM CHECK_USERNAME.
*-- Get Final data to display on report
PERFORM GET_FINALDATA.
ELSE.
MESSAGE I000 WITH TEXT-003.
ENDIF.
ENDIF.
************************************************************************
*-- End of selection
************************************************************************
END-OF-SELECTION.
*--Display the final ALV Report
PERFORM DISPLAY_ERROR_REPORT .
&----
*& Form GET_ERR_DATA
&----
text
----
FORM GET_ERR_DATA.
CLEAR V_ND_FLAG.
SELECT * FROM ZYMMTE_SCMPO
INTO TABLE IT_ZYMMTE_SCMPO
WHERE Y3INVNO IN S_INVNO AND
Y3PO_NO IN S_PO_NO AND
( FLAG = 'P' OR FLAG = 'C' ).
IF SY-SUBRC <> 0.
V_ND_FLAG = 'X'.
MESSAGE I000 WITH TEXT-002. " No Data exists
STOP.
ENDIF.
ENDFORM. " GET_ERR_DATA
&----
*& Form GET_FINALDATA
&----
text
----
FORM GET_FINALDATA.
CLEAR IT_ZYMMTE_SCMPO.
LOOP AT IT_ZYMMTE_SCMPO.
IT_FINAL_SCMPO-CHECK1 = ' '.
IT_FINAL_SCMPO-CHECK2 = ' '.
IT_FINAL_SCMPO-Y3INVNO = IT_ZYMMTE_SCMPO-Y3INVNO.
IT_FINAL_SCMPO-Y3INVITEM = IT_ZYMMTE_SCMPO-Y3INVITEM.
IT_FINAL_SCMPO-Y3PO_NO = IT_ZYMMTE_SCMPO-Y3PO_NO.
IT_FINAL_SCMPO-Y3POITEM_NO = IT_ZYMMTE_SCMPO-Y3POITEM_NO.
IT_FINAL_SCMPO-Y3INVDT = IT_ZYMMTE_SCMPO-Y3INVDT.
IT_FINAL_SCMPO-FLAG = 'PO'.
IT_FINAL_SCMPO-MESSAGE = IT_ZYMMTE_SCMPO-MESSAGE.
READ TABLE IT_PAC WITH KEY
Y3BUKRS = IT_ZYMMTE_SCMPO-Y3BUKRS
Y3INVNO = IT_ZYMMTE_SCMPO-Y3INVNO
Y3INVITEM = IT_ZYMMTE_SCMPO-Y3INVITEM
Y3PO_NO = IT_ZYMMTE_SCMPO-Y3PO_NO
Y3POITEM_NO = IT_ZYMMTE_SCMPO-Y3POITEM_NO.
IF SY-SUBRC = 0.
READ TABLE IT_SPQ WITH KEY
Y3BUKRS = IT_PAC-Y3BUKRS
Y3INVNO = IT_PAC-Y3INVNO
Y3INVITEM = IT_PAC-Y3INVITEM
Y3REVTYPE = IT_PAC-Y3REVTYPE.
IF SY-SUBRC = 0.
IT_FINAL_SCMPO-AUMNG = IT_SPQ-AUMNG.
ENDIF.
READ TABLE IT_PLANCODE WITH KEY
Y3BUKRS = IT_PAC-Y3BUKRS
Y3INVNO = IT_PAC-Y3INVNO
Y3INVITEM = IT_PAC-Y3INVITEM
Y3REVTYPE = IT_PAC-Y3REVTYPE.
IF SY-SUBRC = 0.
IT_FINAL_SCMPO-DISPO = IT_PLANCODE-DISPO.
ENDIF.
ENDIF.
APPEND IT_FINAL_SCMPO.
CLEAR IT_FINAL_SCMPO.
ENDLOOP.
SORT IT_FINAL_SCMPO BY Y3INVNO Y3INVITEM.
IF V_UN_FLAG <> 'X'.
DELETE IT_FINAL_SCMPO WHERE DISPO <> V_DISPO.
ENDIF.
ENDFORM. " GET_FINALDATA
&----
*& Form FIELD_CATALOG
&----
text
----
FORM FIELD_CATALOG.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = V_REPID
I_INTERNAL_TABNAME = V_TABLE
I_STRUCTURE_NAME =
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = V_REPID
CHANGING
CT_FIELDCAT = IT_FLDCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
WA_LAYOUT-BOX_FIELDNAME = 'CHECK1'.
WA_LAYOUT-BOX_TABNAME = V_TABLE.
WA_LAYOUT-GET_SELINFOS = 'X'.
LOOP AT IT_FLDCAT.
CASE IT_FLDCAT-FIELDNAME.
WHEN 'Y3INVNO'.
IT_FLDCAT-SELTEXT_L = 'Invoice # '.
IT_FLDCAT-COL_POS = 2.
IT_FLDCAT-OUTPUTLEN = 12.
WHEN 'Y3INVITEM'.
IT_FLDCAT-SELTEXT_L = 'Inv Itm'.
IT_FLDCAT-COL_POS = 3.
IT_FLDCAT-OUTPUTLEN = 8.
WHEN 'Y3PO_NO'.
IT_FLDCAT-SELTEXT_L = 'PO #'.
IT_FLDCAT-COL_POS = 4.
IT_FLDCAT-OUTPUTLEN = 11.
WHEN 'Y3POITEM_NO'.
IT_FLDCAT-SELTEXT_L = 'PO Itm'.
IT_FLDCAT-COL_POS = 5.
IT_FLDCAT-OUTPUTLEN = 7.
WHEN 'Y3INVDT'.
IT_FLDCAT-SELTEXT_L = 'Inv Date'.
IT_FLDCAT-COL_POS = 6.
IT_FLDCAT-OUTPUTLEN = 9.
WHEN 'FLAG'.
IT_FLDCAT-SELTEXT_L = 'Error In'.
IT_FLDCAT-COL_POS = 7.
IT_FLDCAT-OUTPUTLEN = 8.
WHEN 'MESSAGE'.
IT_FLDCAT-SELTEXT_L = 'Error Message'.
IT_FLDCAT-COL_POS = 8.
IT_FLDCAT-OUTPUTLEN = 60.
WHEN 'AUMNG'.
IT_FLDCAT-SELTEXT_L = 'Material SPQ'.
IT_FLDCAT-COL_POS = 9.
IT_FLDCAT-OUTPUTLEN = 13.
WHEN 'DISPO'.
IT_FLDCAT-SELTEXT_L = 'Code'.
IT_FLDCAT-COL_POS = 10.
IT_FLDCAT-OUTPUTLEN = 4.
WHEN 'CHECK2'.
IT_FLDCAT-SELTEXT_L = 'Non SPQ'.
IT_FLDCAT-COL_POS = 11.
IT_FLDCAT-OUTPUTLEN = 7.
IT_FLDCAT-KEY = ' '.
IT_FLDCAT-CHECKBOX = 'X'.
IT_FLDCAT-INPUT = 'X'.
ENDCASE.
MODIFY IT_FLDCAT INDEX SY-TABIX.
ENDLOOP.
ENDFORM. " FIELD_CATALOG
*&----
*& Form FRM_USR_COMMAND
*&----
<b>FORM FRM_USR_COMMAND USING R_UCOMM LIKE SY-UCOMM
R_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN 'CREATEPO'.
IF V_EMPTY IS INITIAL.
PERFORM GET_PROCESSDATA.
PERFORM PROCESS_DATA.
LEAVE LIST-PROCESSING.
ENDIF.
WHEN 'EXIT' OR 'CANCEL'.
LEAVE LIST-PROCESSING.
ENDCASE.
ENDFORM.</b>
&----
*& Form DISPLAY_ERROR_REPORT
&----
FORM DISPLAY_ERROR_REPORT.
<b> CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_CALLBACK_PROGRAM = V_REPID
I_CALLBACK_PF_STATUS_SET = 'FRM_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'FRM_USR_COMMAND'
I_STRUCTURE_NAME =
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FLDCAT[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
i_default = 'X'
i_save = 'A'
IS_VARIANT = ' '
it_events =
IT_EVENT_EXIT =
IS_PRINT =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_FINAL_SCMPO
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.
ENDFORM. </b> " DISPLAY_ERROR_REPORT
----
FORM FRM_PF_STATUS *
*
----
<b>FORM FRM_PF_STATUS USING T_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'ZPO' EXCLUDING T_EXTAB .
ENDFORM.</b>
Message was edited by: Ashok Parupalli
2006 Jul 11 4:58 PM
Hi Eglese,
if you are using ALV grid OO, you can use the event user_command:
Definition:
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
Then in the implementation of the method handle_user_command you can obtain the selected row using the method get_selected_rows of class cl_gui_alv_grid.
Implementation:
CALL METHOD alv_grid->get_selected_rows
IMPORTING et_index_rows = lt_rows.
lt_rows contains the index of row selected.
regards,
Alejandro