05-10-2006 5:29 AM
Hi All,
I have made a report for alv grid. A custom button was added to the toolabar of the alv grid which does a forward function. the user comes in and selects some rows of the alv grid and want to forward it to others. I couldnt catch up the row value that is been selected by the user. Is there any field that stores the selected row value by the user in the internal table of the alv grid. Please help me asap...
Thanks In Advance
Vicky
05-10-2006 6:11 AM
u can easily do that if u use oo alv.
there is a method caled "GET_SLECTED_ROWS".
if u want to do it in normal alv,
the fieldcat should be of LVC type not slis,
and in the layout LVC_S_LaYO, u can see box_fieldname,box_tabname.
if those parameters and
u can use that value as 'X' and get the row values.
Message was edited by: Hymavathi Oruganti
05-10-2006 5:37 AM
Hi vicky,
I assume your are talking about alv grid using FM.
(and not oo concept)
1. In our internal we have to take
on extra field of type c,
which will CAPTURE the selected rows.
Important code has been marked specifically
2. To get a taste of it,
just copy paste this program.
3. It will display alv (t001)
and DOUBLE-CLICK ON any row.
It will TICK ALL THE CHECKBOXES.
4.
REPORT abc.
TYPE-POOLS : slis.
*----
Data
DATA : BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE t001.
<b>DATA : flag tyPE c,</b>
END OF itab.
DATA : alvfc TYPE slis_t_fieldcat_alv.
DATA : alvly TYPE slis_layout_alv.
*----
Select Data
SELECT * FROM t001 INTO TABLE itab.
*------- Field Catalogue
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'ITAB'
i_inclname = sy-repid
CHANGING
ct_fieldcat = alvfc
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
*----
Display
alvly-box_fieldname = 'FLAG'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = alvfc
i_callback_program = sy-repid "<-------Important
i_callback_user_command = 'ITAB_USER_COMMAND' "<------ Important
is_layout = alvly
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
*----
CALL BACK FORM
*----
FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE
slis_selfield.
LOOP AT itab.
itab-flag = 'X'.
MODIFY itab.
ENDLOOP.
*----
IMPORTANT.
WHATROW-REFRESH = 'X'.
ENDFORM. "ITAB_user_command
regards,
amit m.
05-10-2006 5:43 AM
HI
GOOD
I HOPE THERE WONT BE ANY FIELD WHICH WILL STORE THE VALUE OF THE SELECTED ROW ,I THINK YOU HAVE TO USE THE LOGIC THROUGH WHICH YOU CAN CATCH THE PARTICULAR FIELD VALUE FROM THE FIELD CATALOG.
THANKS
MRUTYUN
05-10-2006 5:48 AM
Vicky,
If you are using the class class cl_gui_alv_grid to display the ALV grid, then you can get the selected rows index using the method get_selected_rows of the class cl_gui_alv_grid.
Regards,
Arun.
05-10-2006 5:55 AM
hi vicky,
if you are using OO ALV then you can simply find the selected rows ..
a sample of the same..
FORM set_sel_rows .
DATA lt_selected_rows TYPE lvc_t_roid .
DATA ls_selected_row TYPE lvc_s_roid .
CALL METHOD g_grid->get_selected_rows
IMPORTING
et_row_no = lt_selected_rows.
LOOP AT lt_selected_rows INTO ls_selected_row.
*select the required row from the displayed internal table
READ TABLE it_disp INDEX ls_selected_row-row_id.
* do the required things
ENDLOOP.
regards
satesh
05-10-2006 6:11 AM
u can easily do that if u use oo alv.
there is a method caled "GET_SLECTED_ROWS".
if u want to do it in normal alv,
the fieldcat should be of LVC type not slis,
and in the layout LVC_S_LaYO, u can see box_fieldname,box_tabname.
if those parameters and
u can use that value as 'X' and get the row values.
Message was edited by: Hymavathi Oruganti
05-10-2006 1:34 PM
Hi,
Could u explain me in detail like where to use that type-pool. Can u forward me a sample code if u have one pleaseee..
Thanks And Regards
Vicky
05-10-2006 1:36 PM
Hi again,
1. TYPE-POOLS : slis.
This we use when we have to
develop program for ALV report.
regards,
amit m.
05-10-2006 1:51 PM
Hi VIcky,
check this sample..
REPORT ZTEST_ALV_CHECK message-id zz .
TYPE-POOLS: SLIS.
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
L_LAYOUT type slis_layout_alv,
x_events type slis_alv_event,
it_events type SLIS_T_EVENT.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
CHK(1),
END OF ITAB.
SELECT VBELN
POSNR
FROM VBAP
UP TO 20 ROWS
INTO TABLE ITAB.
X_FIELDCAT-FIELDNAME = 'CHK'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 1.
X_FIELDCAT-INPUT = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-CHECKBOX = 'X'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-SELTEXT_L = 'VBELN'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 2.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-SELTEXT_L = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 3.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_LAYOUT-window_titlebar = 'Popup window'.
x_events-NAME = SLIS_EV_END_OF_PAGE.
x_events-FORM = 'END_OF_PAGE'.
APPEND x_events TO iT_EVENTS.
CLEAR x_events .
x_events-NAME = SLIS_EV_TOP_OF_PAGE.
x_events-FORM = 'TOP_OF_PAGE'.
APPEND x_events TO iT_EVENTS.
CLEAR x_events .
x_events-NAME = 'DATA_CHANGED'.
x_events-FORM = 'DATA_CHANGED'.
APPEND x_events TO iT_EVENTS.
CLEAR x_events .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = L_LAYOUT
I_CALLBACK_PF_STATUS_SET = 'STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = IT_FIELDCAT
it_events = it_events
* I_SCREEN_START_COLUMN = 10
* I_SCREEN_START_LINE = 1
* I_SCREEN_END_COLUMN = 50
* I_SCREEN_END_LINE = 20
TABLES
T_OUTTAB = ITAB
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 TOP_OF_PAGE.
* BREAK-POINT.
WRITE: / 'TOP_OF_PAGE'.
ENDFORM.
FORM END_OF_PAGE.
* BREAK-POINT.
WRITE: / 'END_OF_PAGE'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_EXTAB text
*----------------------------------------------------------------------*
FORM STATUS USING P_EXTAB TYPE SLIS_T_EXTAB.
*- Pf status
SET PF-STATUS 'STATUS'.
ENDFORM. " STATUS
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
case r_ucomm.
when 'BACK' or 'CANC' or 'EXIT'.
leave to screen 0.
when '&IC1'.
"this tabindex will also the same as itab row
message i000 with 'clicked on row' rs_selfield-tabindex.
* set parameter id 'AUN' field rs_selfield-value.
* call transaction 'VA03' and skip first screen.
endcase.
ENDFORM. "USER_COMMAND
Regards
vijay
05-10-2006 6:16 AM
Hi Vicky,
U can use e_row_id,e_row_no which are of type LVC_S_ROID which can be used to pass information abt row index,and e_column_id of type LVC_S_COL which returns the column fieldname at e_column_id-fieldname. Utilizing these parameters you know where the user clicked and trigger your action.
u can use this fields while implementing methods for events (hotspot/double clik)
please check the following implementation of the event hotspot_click
FORM handle_hotspot_click USING i_row_id TYPE lvc_s_row
i_column_id TYPE lvc_s_col
is_row_no TYPE lvc_s_roid.
READ TABLE gt_list INDEX is_row_no-row_id .
IF sy-subrc = 0 AND i_column_id-fieldname = 'SEATSOCC' .
CALL SCREEN 200 . "Details about passenger-seat matching
ENDIF .
ENDFORM .
Regards,
Ranjit Thakur.
Please Mark The Helpful Answer.
05-10-2006 1:47 PM
if u want to capture the value of the entire row the u need to use the following user command
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
RS_SELFIELD-TABINDEX will point the row which you have selected., using that you can read and do what ever you want..
ENDFORM. "USER_COMMAND