‎2007 Aug 07 3:51 PM
Hi All,
I have a requirement.
In the ALV grid, IF I select a row and click the Change button... I have to prompt a customized screen which display the selected row values.
For example,
the screen should display as follows
Field1 12345
Field2 XXXX
Field3 hhhh
How to get the selected row values and transfer it to the customized screen.
And If i change any of the values in the screen and click the save button, the values should be updated in the ALV grid.
How to do this... kindly help...
Thanks,
Jaffer Ali.S
‎2007 Aug 08 3:47 AM
Its a little different using the class, First you need to set the selection module before calling the SET_TABLE_FOR_FIRST_DISPLAY method.
data: LAYOUT TYPE LVC_S_LAYO,
LAYOUT-SEL_MODE = 'D'.
CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = LAYOUT
CHANGING
IT_OUTTAB = IALV[]
IT_FIELDCATALOG = FIELDCAT[].
So this will give you the selection box in the ALV output, then you use the method GET_SELECTED_ROWS to determine what rows the user has selected.
DATA: INDEX_ROWS TYPE LVC_T_ROW,
INDEX LIKE LINE OF INDEX_ROWS.
CLEAR INDEX_ROWS. REFRESH INDEX_ROWS.
CALL METHOD ALV_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = INDEX_ROWS.
Do something with those selected rows here
LOOP AT INDEX_ROWS INTO INDEX.
Use the index to read the specific line of ALV which is selected
READ TABLE IALV INDEX INDEX-INDEX.
IF SY-SUBRC = 0.
Now do what ever you need to with the selected line
ENDIF.
ENDLOOP.
‎2007 Aug 07 4:08 PM
HI,
Create a Screen to display a record in edit mode.. in SE51 for the program.
in ALV grid.. use USER_COMMAND and give the name of the subroutine for the interactive functionality..
when 'CHNG'. " remember you will have the complete selected line in the subroutine parameters when dealing with ALV..
&----
*& Form USER_COMMAND
&----
form user_command using p_ucomm like sy-ucomm
p_selfield type slis_selfield.
data : l_index like sy-index,
l_refbn like cooi-refbn.
<b> l_index = p_selfield-tabindex. " holds the selected table index</b>
clear l_refbn.
case p_ucomm.
when 'CHG'.
clear l_refbn.
read table it_outtab index l_index.
if sy-subrc eq 0.
move-corresponding fileds to your screen fields.
call screen <Your screen number>
else.
message e999 with text-014.
endif.
endcase.
endif.
And in the PAI of your screen say modity interntable with this detaisl..
Thanks
Mahesh
‎2007 Aug 08 2:35 AM
Hi Jaffer.
Plz, check this sample code...
===============================================
class lcl_event_receiver definition.
public section.
class-methods:
handle_toolbar
for event toolbar of cl_gui_alv_grid
importing e_object e_interactive,
handle_user_command
for event user_command of cl_gui_alv_grid
importing e_ucomm.
private section.
endclass. "lcl_event_receiver DEFINITION
===============================================
class lcl_event_receiver implementation.
method handle_toolbar.
data: ls_toolbar type stb_button.
*....................................................................
* append a separator to normal toolbar
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
* append an icon
clear ls_toolbar.
move 'REFRESH' to ls_toolbar-function.
move icon_refresh to ls_toolbar-icon.
move 'Refresh' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
* append a separator to normal toolbar
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
* append icons
clear ls_toolbar.
move 'SELTRAN' to ls_toolbar-function.
move icon_select_block to ls_toolbar-icon.
move 'Select only Red or Yellow' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 'TRANS' to ls_toolbar-function.
move icon_copy_object to ls_toolbar-icon.
move 'Transfer only the selected orders' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
endmethod. "handle_toolbar
*-------------------------------------------------------------------
method handle_user_command.
data: lt_row_no type lvc_t_roid. <== (1)selected rows
case e_ucomm.
when 'REFRESH'.
perform make_worder.
perform read_mes_if_log.
perform make_alv_worder.
call method g_grid->refresh_table_display.
when 'SELTRAN'.
perform select_red_yellow_rows.
when 'TRANS'. <== if "change" button
call method g_grid->get_selected_rows <==(2) look at this
importing
et_row_no = lt_row_no.
call method cl_gui_cfw=>flush.
call screen 2000. <== (3) your customized screen
endcase.
endmethod. "handle_user_command
endclass. "lcl_event_receiver IMPLEMENTATION===============================================
‎2007 Aug 08 3:47 AM
Its a little different using the class, First you need to set the selection module before calling the SET_TABLE_FOR_FIRST_DISPLAY method.
data: LAYOUT TYPE LVC_S_LAYO,
LAYOUT-SEL_MODE = 'D'.
CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = LAYOUT
CHANGING
IT_OUTTAB = IALV[]
IT_FIELDCATALOG = FIELDCAT[].
So this will give you the selection box in the ALV output, then you use the method GET_SELECTED_ROWS to determine what rows the user has selected.
DATA: INDEX_ROWS TYPE LVC_T_ROW,
INDEX LIKE LINE OF INDEX_ROWS.
CLEAR INDEX_ROWS. REFRESH INDEX_ROWS.
CALL METHOD ALV_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = INDEX_ROWS.
Do something with those selected rows here
LOOP AT INDEX_ROWS INTO INDEX.
Use the index to read the specific line of ALV which is selected
READ TABLE IALV INDEX INDEX-INDEX.
IF SY-SUBRC = 0.
Now do what ever you need to with the selected line
ENDIF.
ENDLOOP.