05-28-2007 4:05 PM
Hi Friends,
I need to put a pushbutton in ALV List's every row. And then when user click this button, I will get the selected line of list. My application server is 4.6 and I want to implement this using the function call of CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY', not using object oriented programming. How can I put button in alv list and get the selected line when button is clicked?
Thanks.
05-28-2007 4:08 PM
05-28-2007 4:09 PM
05-28-2007 4:13 PM
Hi,
You can show a field as ICON and assign the HOTSPOT option to it.
In this way the field should behave itself like a push button.
Regards,
Ferry Lianto
05-29-2007 2:51 PM
Hi,
How can I put icon in ALV's one column under app. server 4.6?
Thanks.
05-29-2007 3:04 PM
U can not do it by 'Reuse_alv*'. You have to use class for that. Here is the example: I have created a pushbutton 'Download file'.
report z_82235_alv_oops_pustbutton .
tables: mara.
types: begin of t_mara,
matnr type matnr,
mtart type mtart,
matkl type matkl,
meins type meins,
end of t_mara.
data: gt_mara type standard table of t_mara,
gs_mara like line of gt_mara.
class lcl_event_receiver definition deferred.
*-- Global Data defenation for ALV
*---Alv Grid instance referance
data : gr_alvgrid type ref to cl_gui_alv_grid,
event_receiver type ref to lcl_event_receiver.
*---Name of the custom control added on the screen
data gc_custom_control_name type scrfname value 'CC_ALV'
.
*---Custom container instance referance
data: gr_ccontainer type ref to cl_gui_custom_container.
*---Field catalog table
data: gt_fieldcat type lvc_t_fcat,
gs_fieldcat type lvc_s_fcat.
*---Layout structure
data: gs_layout type lvc_s_layo.
data: g_repid like sy-repid.
select matnr
mtart
matkl
meins
from mara into table gt_mara
up to 25 rows.
g_repid = sy-repid.
include <icon>.
*********
* Predefine a local class for event handling to allow the
* declaration of a reference variable before the class is defined.
*
*********
* Set initial dynpro
set screen 100.
****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================
* class lcl_event_receiver: local class to
* define and handle own functions.
*
* Definition:
* ~~~~~~~~~~~
class lcl_event_receiver definition.
public section.
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)
*===============================================================
****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class lcl_event_receiver (Implementation)
*
*
class lcl_event_receiver implementation.
method handle_toolbar.
* § 2.In event handler method for event TOOLBAR: Append own functions
* by using event parameter E_OBJECT.
data: ls_toolbar type stb_button.
*....................................................................
* E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET.
* This class has got one attribute, namly MT_TOOLBAR, which
* is a table of type TTB_BUTTON. One line of this table is
* defined by the Structure STB_BUTTON (see data deklaration above).
*
* A remark to the flag E_INTERACTIVE:
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 'e_interactive' is set, if this event is raised due to
* the call of 'set_toolbar_interactive' by the user.
* You can distinguish this way if the event was raised
* by yourself or by ALV
* (e.g. in method 'refresh_table_display').
* An application of this feature is still unknown... :-)
* 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 to download
clear ls_toolbar.
ls_toolbar-function = 'DOWN'.
ls_toolbar-icon = 'icon_generate'.
ls_toolbar-quickinfo = 'DOWNLOAD FILE'.
ls_toolbar-text = 'DOWNLOAD FILE'.
* MOVE ' ' TO ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
endmethod.
*-------------------------------------------------------------------
method handle_user_command.
* § 3.In event handler method for event USER_COMMAND: Query your
* function codes defined in step 2 and react accordingly.
data: lt_rows type lvc_t_row.
case e_ucomm.
when 'DOWN'.
call function 'GUI_DOWNLOAD'
exporting
* BIN_FILESIZE =
filename = 'D:a.txt'
* FILETYPE = 'ASC'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
tables
data_tab = gt_mara
exceptions
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
others = 22
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endcase.
endmethod. "handle_user_command
*-----------------------------------------------------------------
endclass.
*
* lcl_event_receiver (Implementation)
*===================================================================
*--------------------------------------------------------------------
* S T A R T - O F - S E L E C T I O N.
*--------------------------------------------------------------------
start-of-selection.
set screen '100'.
*&---------------------------------------------------------------------*
*& Module display_alv OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module display_alv output.
if gr_alvgrid is initial.
*---Creating custom container instance
create object gr_ccontainer
exporting
container_name = gc_custom_control_name
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.
*---Creating ALV gris instance
create object gr_alvgrid
exporting
i_parent = gr_ccontainer
i_appl_events = 'X'
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
*---Prepare field catalog
perform prepare_field_catalog tables gt_fieldcat.
*---Prepare layout
perform prepare_layout changing gs_layout.
*---Call ALV grid
call method gr_alvgrid->set_table_for_first_display
exporting
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = 'X'
is_layout = gs_layout
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
changing
it_outtab = gt_mara[]
it_fieldcatalog = gt_fieldcat
* IT_SORT =
* IT_FILTER =
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4
.
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 Object to receive events and link them to handler methods.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
*
create object event_receiver.
set handler event_receiver->handle_user_command for gr_alvgrid.
set handler event_receiver->handle_toolbar for gr_alvgrid.
*
********
* § 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR.
call method gr_alvgrid->set_toolbar_interactive.
* endif. "IF grid1 IS INITIAL
* call method cl_gui_control=>set_focus exporting control = gr_alvgrid.
*--- the instance is present
else .
call method gr_alvgrid->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
exceptions
finished = 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.
endif.
endmodule. " display_alv OUTPUT
*&---------------------------------------------------------------------*
*& Form prepare_field_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FIELDCAT text
*----------------------------------------------------------------------*
form prepare_field_catalog tables gt_fieldcat.
clear : gs_fieldcat.
gs_fieldcat-fieldname = 'MATNR'.
gs_fieldcat-col_pos = 1.
gs_fieldcat-emphasize = 'X'.
gs_fieldcat-outputlen = 10.
gs_fieldcat-coltext = 'Material No'.
gs_fieldcat-edit = 'X'.
append gs_fieldcat to gt_fieldcat.
clear : gs_fieldcat.
gs_fieldcat-fieldname = 'MTART'.
gs_fieldcat-col_pos = 2.
gs_fieldcat-outputlen = 6.
gs_fieldcat-coltext = 'Material Type'.
append gs_fieldcat to gt_fieldcat.
clear : gs_fieldcat.
gs_fieldcat-fieldname = 'MATKL'.
gs_fieldcat-col_pos = 3.
gs_fieldcat-outputlen = 5.
gs_fieldcat-coltext = 'Material Grp'.
append gs_fieldcat to gt_fieldcat.
clear : gs_fieldcat.
gs_fieldcat-fieldname = 'MEINS'.
gs_fieldcat-col_pos = 4.
gs_fieldcat-outputlen = 4.
gs_fieldcat-coltext = 'Unit'.
append gs_fieldcat to gt_fieldcat.
endform. " prepare_field_catalog
*&---------------------------------------------------------------------*
*& Form prepare_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GS_LAYOUT text
*----------------------------------------------------------------------*
form prepare_layout changing p_gs_layout type lvc_s_layo.
p_gs_layout-zebra = 'X'.
p_gs_layout-grid_title = 'Material'.
p_gs_layout-smalltitle = 'X'.
endform. " prepare_layout
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0100 output.
set pf-status 'STATUS1'.
* SET TITLEBAR 'xxx'.
endmodule. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0100 input.
case sy-ucomm.
when 'BACK' or 'UP' or 'CANCEL'.
leave program.
when '&DETAIL'.
leave program.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
06-26-2007 9:44 AM
Hi All
It not true when Abhishek Sarkar say "U can not do it by 'Reuse_alv"
- but his solution can also work.
Best regards