05-17-2007 11:17 AM
Hi all
I need to add a button/icon at the end of each row of an ALV. When the user clicks on a button it will send a mail.
Can you help me? Specially on the first issue.
Many thanks.
05-17-2007 12:21 PM
hi check this code this is also works as same except the mail part,this will trigger a workflow log .plz go trought he code below and revert back to me for any clarifications.
&----
*& Report yi_amra_yiamraber *
*& *
&----
*& *
*& *
&----
report yi_amra_yiamraber no standard page heading.
tables: yiamra_ber,SWW_WI2OBJ.
include <icon>.
include <symbol>.
type-pools: slis.
class cl_gui_resources definition load.
constants: con_true type char1 value 'X',
con_on type char1 value '1',
con_off type char1 value '0',
con_exit like sy-ucomm value 'EXIT',
con_back like sy-ucomm value 'BACK',
con_canc like sy-ucomm value 'CANC'.
data: g_okcode type sy-ucomm,
g_container_d0100 type ref to cl_gui_custom_container,
g_container_name_d0100 type scrfname value 'D0100_CONTAINER',
g_grid_d0100 type ref to cl_gui_alv_grid.
DATA: objkey LIKE sweinstcou-objkey.
DATA: ls_ibfobject TYPE sibflporb.
data : v_WI_ID type SWW_WI2OBJ-WI_ID.
DATA BEGIN OF GT_yiamra_ber OCCURS 0 .
INCLUDE STRUCTURE yiamra_ber .
DATA cellstyles TYPE lvc_t_styl.
DATA text(28) TYPE c.
DATA printer(10) TYPE c.
DATA workflow(13) TYPE c.
DATA END OF GT_yiamra_ber .
DATA ls_style TYPE lvc_s_styl.
DATA: X_FIELDCAT TYPE LVC_S_FCAT.
DATA:L_POS TYPE I VALUE 1.
data: gs_layout TYPE lvc_s_layo.
SELECT-OPTIONS LFDNR FOR yiamra_ber-LFDNR.
SELECT-OPTIONS POSNR FOR yiamra_ber-POSNR.
SELECT-OPTIONS UNAME FOR yiamra_ber-UNAME.
SELECT-OPTIONS ROLLE FOR yiamra_ber-ROLLE.
SELECT-OPTIONS PRCTR FOR yiamra_ber-PRCTR.
SELECT-OPTIONS PRCTRGRP FOR yiamra_ber-PRCTRGRP.
SELECT-OPTIONS KOSTL FOR yiamra_ber-KOSTL.
SELECT-OPTIONS KOSTLGRP FOR yiamra_ber-KOSTLGRP.
SELECT-OPTIONS ABREC FOR yiamra_ber-ABRECHNST.
SELECT-OPTIONS ANFORD FOR yiamra_ber-ANFORDERER.
SELECT-OPTIONS DATUMU FOR yiamra_ber-DATUMNEU.
SELECT-OPTIONS DATUMA FOR yiamra_ber-DATUMANF.
SELECT-OPTIONS STATUS FOR yiamra_ber-STATUS.
SELECT-OPTIONS DATUM FOR yiamra_ber-DATUMADM.
SELECT-OPTIONS DATUMB FOR yiamra_ber-DATUMBEG.
SELECT-OPTIONS DATUME FOR yiamra_ber-DATUMEND.
***********************************************************************
class Definition.
***********************************************************************
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
*To control button clicks
handle_button_click
FOR EVENT button_click OF cl_gui_alv_grid
IMPORTING es_col_id
es_row_no.
*PRIVATE SECTION.
METHODS:
perform_copy_checks
IMPORTING
er_data_changed TYPE REF TO cl_alv_changed_data_protocol.
ENDCLASS. "lcl_event_handler DEFINITION
&----
*& Class (Implementation) lcl_event_handler
&----
Text
----
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_button_click .
PERFORM handle_button_click USING es_col_id
es_row_no.
ENDMETHOD.
ENDCLASS. "lcl_event_handler
************************************************************************
Display Data
************************************************************************
start-of-selection.
end-of-selection.
call screen 0100.
&----
*& Module d0100_set_status OUTPUT
&----
text
----
module d0100_set_status output.
perform d0100_set_status.
endmodule. " d0100_set_status OUTPUT
&----
*& Module d0100_prepare_container OUTPUT
&----
text
----
module d0100_prepare_container output.
perform d0100_prepare_container.
endmodule. " d0100_prepare_container OUTPUT
&----
*& Module d0100_exit INPUT
&----
text
----
module d0100_exit input.
perform d0100_exit changing g_okcode.
endmodule. " d0100_exit INPUT
&----
*& Module d0100_fcode INPUT
&----
text
----
module d0100_fcode input.
perform d0100_fcode changing g_okcode.
endmodule. " d0100_fcode INPUT
&----
*& Form d0100_set_status
&----
text
----
form d0100_set_status.
set pf-status 'D0100' .
set titlebar 'D0100'.
SELECT * FROM yiamra_ber
INTO corresponding fields of TABLE GT_yiamra_ber
WHERE LFDNR IN LFDNR
AND POSNR IN POSNR
AND UNAME IN UNAME
AND ROLLE In ROLLE
AND PRCTR IN PRCTR
AND PRCTRGRP IN PRCTRGRP
AND KOSTL IN KOSTL
AND KOSTLGRP IN KOSTLGRP
AND ABRECHNST IN ABREC
AND ANFORDERER IN ANFORD
AND DATUMNEU IN DATUMU
AND DATUMANF IN DATUMA
AND STATUS IN STATUS
AND DATUMADM IN DATUM
AND DATUMBEG IN DATUMB
AND DATUMEND IN DATUME.
loop at gt_yiamra_ber.
CONCATENATE GT_yiamra_ber-lfdnr GT_yiamra_ber-posnr INTO objkey.
ls_ibfobject-catid = 'BO'.
ls_ibfobject-typeid = 'YIAMRAROLL'.
ls_ibfobject-instid = objkey.
clear v_WI_ID.
select single WI_ID from SWW_WI2OBJ into v_WI_ID where INSTID = objkey.
IF sy-subrc = 0.
ls_style-fieldname = 'WORKFLOW'.
ls_style-style = cl_gui_alv_grid=>mc_style_button.
INSERT ls_style INTO TABLE GT_yiamra_ber-cellstyles.
GT_yiamra_ber-anfordern = icon_workflow_event_producer.
GT_yiamra_ber-printer = icon_print.
GT_yiamra_ber-workflow = ICON_HISTORY.
endif.
ls_style-fieldname = 'TEXT' .
ls_style-style = cl_gui_alv_grid=>mc_style_button .
INSERT ls_style INTO TABLE gt_yiamra_ber-cellstyles.
GT_yiamra_ber-text = ICON_DISPLAY_TEXT.
MODIFY GT_yiamra_ber
INDEX sy-tabix
TRANSPORTING cellstyles Text workflow.
endloop.
endform. " d0100_set_status
&----
*& Form d0100_prepare_container
&----
text
----
form d0100_prepare_container.
data: ls_vari type disvariant,
lt_fcat type lvc_t_fcat.
DATA gr_event_handler TYPE REF TO lcl_event_handler .
DATA IT_UI_FUNCTIONS TYPE UI_FUNCTIONS.
APPEND '&DETAIL' TO IT_UI_FUNCTIONS.
if g_container_d0100 is initial.
create object g_container_d0100
exporting container_name = g_container_name_d0100.
create object g_grid_d0100
exporting i_parent = g_container_d0100.
CREATE OBJECT gr_event_handler .
SET HANDLER gr_event_handler->handle_button_click FOR g_grid_d0100 .
perform d0100_set_grid_vari changing ls_vari.
perform d0100_set_grid_fcat changing lt_fcat.
perform d0100_set_grid_fcat1 changing lt_fcat.
call method g_grid_d0100->INIT_TOOLBAR
EXPORTING
IT_TOOLBAR_EXCLUDING = IT_UI_FUNCTIONS.
*
call method g_grid_d0100->set_table_for_first_display
EXPORTING
is_layout = gs_layout
IT_TOOLBAR_EXCLUDING = IT_UI_FUNCTIONS
CHANGING
it_outtab = gt_yiamra_ber[]
it_fieldcatalog = lt_fcat.
call method cl_gui_control=>set_focus
EXPORTING
control = g_grid_d0100.
endif.
endform. " d0100_prepare_container
&----
*& Form d0100_exit
&----
text
----
form d0100_exit changing c_okcode type sy-ucomm.
data: l_okcode like sy-ucomm.
l_okcode = c_okcode.
clear c_okcode.
case l_okcode.
when con_exit or con_back or con_canc.
call method g_grid_d0100->free.
call method g_container_d0100->free.
call method cl_gui_cfw=>flush.
clear g_container_d0100.
clear g_grid_d0100.
set screen 0.
leave screen.
endcase.
endform. " d0100_exit
&----
*& Form d0100_fcode
&----
text
----
form d0100_fcode changing c_okcode type sy-ucomm.
data: l_okcode like sy-ucomm.
l_okcode = c_okcode.
clear c_okcode.
call method cl_gui_cfw=>dispatch.
case l_okcode.
when con_exit or con_back or con_canc.
call method g_container_d0100->free.
call method cl_gui_cfw=>flush.
clear g_container_d0100.
clear g_grid_d0100.
set screen 0.
leave screen.
endcase.
endform. " d0100_fcode
&----
*& Form d0100_set_grid_fcat
&----
text
----
form d0100_set_grid_fcat changing ct_fcat type lvc_t_fcat.
data: ls_fcat type lvc_s_fcat.
gs_layout-stylefname = 'CELLSTYLES'.
*+++ STEP 1: retrieve the fieldcatalog
call function 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'YIAMRA_BER'
CHANGING
ct_fieldcat = ct_fcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
others = 3.
if sy-subrc eq 0.
*+++ STEP 2: modify the fieldcatalog.
loop at ct_fcat into ls_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'LFDNR' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'LFDNR' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'POSNR' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'POSNR' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'UNAME' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'UNAME' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'ROLLE' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'ROLLE' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'PRCTR' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'PRCTR' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'PRCTRGRP' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'PRCTRGRP' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'KOSTL' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'KOSTL' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'KOSTLGRP' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'KOSTLGRP' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'ABRECHNST' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'ABRECHNST' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'ANFORDERER' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'ANFORDERER' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMNEU' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMNEU' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMANF' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMANF' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'STATUS' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'STATUS' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMADM' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMADM' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMBEG' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMBEG' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMEND' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMEND' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'WORKFLOW' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'WORKFLOW'.
ls_fcat-icon = 'X'.
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'TEXT' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'TEXT' .
ls_fcat-icon = 'X'.
APPEND LS_FCAT TO CT_FCAT.
modify ct_fcat from ls_fcat.
endloop.
endif.
endform. " d0100_set_grid_fcat
&----
*& Form d0100_set_grid_vari
&----
text
----
form d0100_set_grid_vari changing cs_vari type disvariant.
*+++ allow layout maintenance
*+++ note report is compelling
cs_vari-report = .
cs_vari-handle = .
cs_vari-log_group = .
cs_vari-username = .
cs_vari-variant = .
cs_vari-text = .
cs_vari-dependvars = .
endform. " d0100_set_grid_vari
&----
*& Form handle_button_click
&----
text
----
-->P_ES_COL_ID text
-->P_ES_ROW_NO text
----
FORM handle_button_click USING P_ES_COL_ID TYPE lvc_s_col
P_ES_ROW_NO TYPE lvc_s_roid.
DATA: objkey LIKE sweinstcou-objkey.
DATA: ls_ibfobject TYPE sibflporb.
DATA: BEGIN OF ls_output OCCURS 0 .
INCLUDE STRUCTURE yiamra_ber .
DATA cellstyles TYPE lvc_t_styl.
DATA text(28) TYPE c.
DATA printer(10) TYPE c.
DATA workflow(13) TYPE c.
DATA END OF ls_output.
READ TABLE GT_yiamra_ber INDEX p_es_row_no-row_id INTO ls_output.
IF sy-subrc <> 0.
RETURN.
ENDIF.
case P_ES_COL_ID-fieldname.
when 'TEXT'.
IF GT_yiamra_ber-rolle IS NOT INITIAL.
CALL FUNCTION 'Y_I_AMRA_ROLLE_TEXT'
EXPORTING
i_rolle = GT_yiamra_ber-rolle.
endif.
when 'WORKFLOW'.
clear: objkey.
IF sy-subrc = 0 AND p_es_col_id-fieldname = 'WORKFLOW'.
CONCATENATE ls_output-lfdnr ls_output-posnr INTO objkey.
ls_ibfobject-catid = 'BO'.
ls_ibfobject-typeid = 'YIAMRAROLL'.
ls_ibfobject-instid = objkey.
CALL FUNCTION 'SWI_WF_CONNECTIONS_DISPLAY'
EXPORTING
ibf_object = ls_ibfobject
EXCEPTIONS
not_found = 1
no_authority = 2
no_workflows_found = 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.
endif.
endcase.
ENDFORM. " handle_button_click
05-17-2007 11:20 AM
Hi ,
check below link
http://www.sapfans.com/forums/viewtopic.php?t=88376
http://www.sapfans.com/forums/viewtopic.php?t=40968
http://www.sapfans.com/forums/viewtopic.php?t=6919
Plz reward points if help full.
Regards
Suresh.D
05-17-2007 11:21 AM
Hi,
i dont think u can add the button at the end of each row..
one way u can do....
add a button in th toolbar. and have checkbox in the list.
then user can select the record with check box and then press the button to send mail.
--Patil
05-17-2007 11:23 AM
05-17-2007 11:37 AM
Hi,
Check the program BCALV_TEST_GRID_EVENTS. Run the program while selecting the option BUTTON_CLICK and selecting the field name CARRID. U can use this to send a mail when the user selects the button on CARRID field of a row. Please a break point at method button_click and check the program. Only the method method button_click is required in the program.
05-17-2007 12:09 PM
I run this report and it launches an empty ALV... do you know how I can view this populated?
More sugestions...
05-17-2007 12:21 PM
hi check this code this is also works as same except the mail part,this will trigger a workflow log .plz go trought he code below and revert back to me for any clarifications.
&----
*& Report yi_amra_yiamraber *
*& *
&----
*& *
*& *
&----
report yi_amra_yiamraber no standard page heading.
tables: yiamra_ber,SWW_WI2OBJ.
include <icon>.
include <symbol>.
type-pools: slis.
class cl_gui_resources definition load.
constants: con_true type char1 value 'X',
con_on type char1 value '1',
con_off type char1 value '0',
con_exit like sy-ucomm value 'EXIT',
con_back like sy-ucomm value 'BACK',
con_canc like sy-ucomm value 'CANC'.
data: g_okcode type sy-ucomm,
g_container_d0100 type ref to cl_gui_custom_container,
g_container_name_d0100 type scrfname value 'D0100_CONTAINER',
g_grid_d0100 type ref to cl_gui_alv_grid.
DATA: objkey LIKE sweinstcou-objkey.
DATA: ls_ibfobject TYPE sibflporb.
data : v_WI_ID type SWW_WI2OBJ-WI_ID.
DATA BEGIN OF GT_yiamra_ber OCCURS 0 .
INCLUDE STRUCTURE yiamra_ber .
DATA cellstyles TYPE lvc_t_styl.
DATA text(28) TYPE c.
DATA printer(10) TYPE c.
DATA workflow(13) TYPE c.
DATA END OF GT_yiamra_ber .
DATA ls_style TYPE lvc_s_styl.
DATA: X_FIELDCAT TYPE LVC_S_FCAT.
DATA:L_POS TYPE I VALUE 1.
data: gs_layout TYPE lvc_s_layo.
SELECT-OPTIONS LFDNR FOR yiamra_ber-LFDNR.
SELECT-OPTIONS POSNR FOR yiamra_ber-POSNR.
SELECT-OPTIONS UNAME FOR yiamra_ber-UNAME.
SELECT-OPTIONS ROLLE FOR yiamra_ber-ROLLE.
SELECT-OPTIONS PRCTR FOR yiamra_ber-PRCTR.
SELECT-OPTIONS PRCTRGRP FOR yiamra_ber-PRCTRGRP.
SELECT-OPTIONS KOSTL FOR yiamra_ber-KOSTL.
SELECT-OPTIONS KOSTLGRP FOR yiamra_ber-KOSTLGRP.
SELECT-OPTIONS ABREC FOR yiamra_ber-ABRECHNST.
SELECT-OPTIONS ANFORD FOR yiamra_ber-ANFORDERER.
SELECT-OPTIONS DATUMU FOR yiamra_ber-DATUMNEU.
SELECT-OPTIONS DATUMA FOR yiamra_ber-DATUMANF.
SELECT-OPTIONS STATUS FOR yiamra_ber-STATUS.
SELECT-OPTIONS DATUM FOR yiamra_ber-DATUMADM.
SELECT-OPTIONS DATUMB FOR yiamra_ber-DATUMBEG.
SELECT-OPTIONS DATUME FOR yiamra_ber-DATUMEND.
***********************************************************************
class Definition.
***********************************************************************
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
*To control button clicks
handle_button_click
FOR EVENT button_click OF cl_gui_alv_grid
IMPORTING es_col_id
es_row_no.
*PRIVATE SECTION.
METHODS:
perform_copy_checks
IMPORTING
er_data_changed TYPE REF TO cl_alv_changed_data_protocol.
ENDCLASS. "lcl_event_handler DEFINITION
&----
*& Class (Implementation) lcl_event_handler
&----
Text
----
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_button_click .
PERFORM handle_button_click USING es_col_id
es_row_no.
ENDMETHOD.
ENDCLASS. "lcl_event_handler
************************************************************************
Display Data
************************************************************************
start-of-selection.
end-of-selection.
call screen 0100.
&----
*& Module d0100_set_status OUTPUT
&----
text
----
module d0100_set_status output.
perform d0100_set_status.
endmodule. " d0100_set_status OUTPUT
&----
*& Module d0100_prepare_container OUTPUT
&----
text
----
module d0100_prepare_container output.
perform d0100_prepare_container.
endmodule. " d0100_prepare_container OUTPUT
&----
*& Module d0100_exit INPUT
&----
text
----
module d0100_exit input.
perform d0100_exit changing g_okcode.
endmodule. " d0100_exit INPUT
&----
*& Module d0100_fcode INPUT
&----
text
----
module d0100_fcode input.
perform d0100_fcode changing g_okcode.
endmodule. " d0100_fcode INPUT
&----
*& Form d0100_set_status
&----
text
----
form d0100_set_status.
set pf-status 'D0100' .
set titlebar 'D0100'.
SELECT * FROM yiamra_ber
INTO corresponding fields of TABLE GT_yiamra_ber
WHERE LFDNR IN LFDNR
AND POSNR IN POSNR
AND UNAME IN UNAME
AND ROLLE In ROLLE
AND PRCTR IN PRCTR
AND PRCTRGRP IN PRCTRGRP
AND KOSTL IN KOSTL
AND KOSTLGRP IN KOSTLGRP
AND ABRECHNST IN ABREC
AND ANFORDERER IN ANFORD
AND DATUMNEU IN DATUMU
AND DATUMANF IN DATUMA
AND STATUS IN STATUS
AND DATUMADM IN DATUM
AND DATUMBEG IN DATUMB
AND DATUMEND IN DATUME.
loop at gt_yiamra_ber.
CONCATENATE GT_yiamra_ber-lfdnr GT_yiamra_ber-posnr INTO objkey.
ls_ibfobject-catid = 'BO'.
ls_ibfobject-typeid = 'YIAMRAROLL'.
ls_ibfobject-instid = objkey.
clear v_WI_ID.
select single WI_ID from SWW_WI2OBJ into v_WI_ID where INSTID = objkey.
IF sy-subrc = 0.
ls_style-fieldname = 'WORKFLOW'.
ls_style-style = cl_gui_alv_grid=>mc_style_button.
INSERT ls_style INTO TABLE GT_yiamra_ber-cellstyles.
GT_yiamra_ber-anfordern = icon_workflow_event_producer.
GT_yiamra_ber-printer = icon_print.
GT_yiamra_ber-workflow = ICON_HISTORY.
endif.
ls_style-fieldname = 'TEXT' .
ls_style-style = cl_gui_alv_grid=>mc_style_button .
INSERT ls_style INTO TABLE gt_yiamra_ber-cellstyles.
GT_yiamra_ber-text = ICON_DISPLAY_TEXT.
MODIFY GT_yiamra_ber
INDEX sy-tabix
TRANSPORTING cellstyles Text workflow.
endloop.
endform. " d0100_set_status
&----
*& Form d0100_prepare_container
&----
text
----
form d0100_prepare_container.
data: ls_vari type disvariant,
lt_fcat type lvc_t_fcat.
DATA gr_event_handler TYPE REF TO lcl_event_handler .
DATA IT_UI_FUNCTIONS TYPE UI_FUNCTIONS.
APPEND '&DETAIL' TO IT_UI_FUNCTIONS.
if g_container_d0100 is initial.
create object g_container_d0100
exporting container_name = g_container_name_d0100.
create object g_grid_d0100
exporting i_parent = g_container_d0100.
CREATE OBJECT gr_event_handler .
SET HANDLER gr_event_handler->handle_button_click FOR g_grid_d0100 .
perform d0100_set_grid_vari changing ls_vari.
perform d0100_set_grid_fcat changing lt_fcat.
perform d0100_set_grid_fcat1 changing lt_fcat.
call method g_grid_d0100->INIT_TOOLBAR
EXPORTING
IT_TOOLBAR_EXCLUDING = IT_UI_FUNCTIONS.
*
call method g_grid_d0100->set_table_for_first_display
EXPORTING
is_layout = gs_layout
IT_TOOLBAR_EXCLUDING = IT_UI_FUNCTIONS
CHANGING
it_outtab = gt_yiamra_ber[]
it_fieldcatalog = lt_fcat.
call method cl_gui_control=>set_focus
EXPORTING
control = g_grid_d0100.
endif.
endform. " d0100_prepare_container
&----
*& Form d0100_exit
&----
text
----
form d0100_exit changing c_okcode type sy-ucomm.
data: l_okcode like sy-ucomm.
l_okcode = c_okcode.
clear c_okcode.
case l_okcode.
when con_exit or con_back or con_canc.
call method g_grid_d0100->free.
call method g_container_d0100->free.
call method cl_gui_cfw=>flush.
clear g_container_d0100.
clear g_grid_d0100.
set screen 0.
leave screen.
endcase.
endform. " d0100_exit
&----
*& Form d0100_fcode
&----
text
----
form d0100_fcode changing c_okcode type sy-ucomm.
data: l_okcode like sy-ucomm.
l_okcode = c_okcode.
clear c_okcode.
call method cl_gui_cfw=>dispatch.
case l_okcode.
when con_exit or con_back or con_canc.
call method g_container_d0100->free.
call method cl_gui_cfw=>flush.
clear g_container_d0100.
clear g_grid_d0100.
set screen 0.
leave screen.
endcase.
endform. " d0100_fcode
&----
*& Form d0100_set_grid_fcat
&----
text
----
form d0100_set_grid_fcat changing ct_fcat type lvc_t_fcat.
data: ls_fcat type lvc_s_fcat.
gs_layout-stylefname = 'CELLSTYLES'.
*+++ STEP 1: retrieve the fieldcatalog
call function 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'YIAMRA_BER'
CHANGING
ct_fieldcat = ct_fcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
others = 3.
if sy-subrc eq 0.
*+++ STEP 2: modify the fieldcatalog.
loop at ct_fcat into ls_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'LFDNR' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'LFDNR' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'POSNR' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'POSNR' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'UNAME' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'UNAME' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'ROLLE' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'ROLLE' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'PRCTR' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'PRCTR' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'PRCTRGRP' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'PRCTRGRP' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'KOSTL' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'KOSTL' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'KOSTLGRP' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'KOSTLGRP' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'ABRECHNST' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'ABRECHNST' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'ANFORDERER' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'ANFORDERER' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMNEU' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMNEU' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMANF' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMANF' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'STATUS' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'STATUS' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMADM' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMADM' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMBEG' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMBEG' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'DATUMEND' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'DATUMEND' .
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'WORKFLOW' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'WORKFLOW'.
ls_fcat-icon = 'X'.
APPEND LS_FCAT TO CT_FCAT.
clear ls_fcat.
ls_fcat-fieldname = 'TEXT' .
ls_fcat-outputlen = '10' .
ls_fcat-coltext = 'TEXT' .
ls_fcat-icon = 'X'.
APPEND LS_FCAT TO CT_FCAT.
modify ct_fcat from ls_fcat.
endloop.
endif.
endform. " d0100_set_grid_fcat
&----
*& Form d0100_set_grid_vari
&----
text
----
form d0100_set_grid_vari changing cs_vari type disvariant.
*+++ allow layout maintenance
*+++ note report is compelling
cs_vari-report = .
cs_vari-handle = .
cs_vari-log_group = .
cs_vari-username = .
cs_vari-variant = .
cs_vari-text = .
cs_vari-dependvars = .
endform. " d0100_set_grid_vari
&----
*& Form handle_button_click
&----
text
----
-->P_ES_COL_ID text
-->P_ES_ROW_NO text
----
FORM handle_button_click USING P_ES_COL_ID TYPE lvc_s_col
P_ES_ROW_NO TYPE lvc_s_roid.
DATA: objkey LIKE sweinstcou-objkey.
DATA: ls_ibfobject TYPE sibflporb.
DATA: BEGIN OF ls_output OCCURS 0 .
INCLUDE STRUCTURE yiamra_ber .
DATA cellstyles TYPE lvc_t_styl.
DATA text(28) TYPE c.
DATA printer(10) TYPE c.
DATA workflow(13) TYPE c.
DATA END OF ls_output.
READ TABLE GT_yiamra_ber INDEX p_es_row_no-row_id INTO ls_output.
IF sy-subrc <> 0.
RETURN.
ENDIF.
case P_ES_COL_ID-fieldname.
when 'TEXT'.
IF GT_yiamra_ber-rolle IS NOT INITIAL.
CALL FUNCTION 'Y_I_AMRA_ROLLE_TEXT'
EXPORTING
i_rolle = GT_yiamra_ber-rolle.
endif.
when 'WORKFLOW'.
clear: objkey.
IF sy-subrc = 0 AND p_es_col_id-fieldname = 'WORKFLOW'.
CONCATENATE ls_output-lfdnr ls_output-posnr INTO objkey.
ls_ibfobject-catid = 'BO'.
ls_ibfobject-typeid = 'YIAMRAROLL'.
ls_ibfobject-instid = objkey.
CALL FUNCTION 'SWI_WF_CONNECTIONS_DISPLAY'
EXPORTING
ibf_object = ls_ibfobject
EXCEPTIONS
not_found = 1
no_authority = 2
no_workflows_found = 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.
endif.
endcase.
ENDFORM. " handle_button_click
05-17-2007 12:26 PM
To make a cell to be displayed as a pushbutton, we have two steps. Firstly, insert a new inner table of type LVC_T_STYL into your list data table.
DATA BEGIN OF gt_list OCCURS 0 .
INCLUDE STRUCTURE SFLIGHT .
DATA rowcolor(4) TYPE c .
DATA cellcolors TYPE lvc_t_scol .
DATA carrid_handle TYPE int4 .
DATA connid_handle TYPE int4 .
DATA cellstyles TYPE lvc_t_styl .
DATA END OF gtlist .
Fill this inner table for each field to be displayed as pushbutton.
DATA ls_style TYPE lvc_s_styl .
...
READ TABLE gt_list INDEX 7 .
ls_style-fieldname = 'SEATSMAX' .
ls_style-style = cl_gui_alv_grid=>mc_style_button .
APPEND ls_style TO gt_list-cellstyles .
MODIFY gt_list INDEX 7 .
i think this will solve your problem, and don't forget to reward points
cheers,
05-17-2007 10:00 PM
Hi,
Try with the following example:
&----
*& Report ZALVGRID_WITH_RADIOBUTTONS
*&
&----
*& This program shows how to realize radiobuttons in ALV grid lists
*& using event HOTSPOT_CLICK.
*&
&----
*& Screen 100:
*& - Flow logic
*&
*& PROCESS BEFORE OUTPUT.
*& MODULE PBO.
&
*& PROCESS AFTER INPUT.
*& MODULE PAI.
*&
*& - Screen elements: none
*& - ok-code field -> gd_okcode
*&
*& GUI Status MAIN100:
*& - F3 = 'BACK', Shift+F3 = 'EXIT', F12 = 'CANC'
&----
PROGRAM zalvgrid_with_radiobuttons.
TYPE-POOLS: abap, icon. " INCLUDE <icon>. for releases < 6.20
TYPES: BEGIN OF ty_s_sflight.
INCLUDE TYPE sflight.
TYPES: button1 TYPE iconname.
TYPES: button2 TYPE iconname.
TYPES: button3 TYPE iconname.
TYPES: button4 TYPE iconname.
TYPES: END OF ty_s_sflight.
DATA:
gt_sflight TYPE STANDARD TABLE OF ty_s_sflight,
*
gs_layout TYPE lvc_s_layo,
gt_fcat TYPE lvc_t_fcat.
DATA:
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
----
CLASS lcl_eventhandler DEFINITION
----
*
----
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
----
CLASS lcl_eventhandler IMPLEMENTATION
----
*
----
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_hotspot_click.
define local data
FIELD-SYMBOLS:
<ls_entry> TYPE ty_s_sflight,
<ld_fld> TYPE ANY.
READ TABLE gt_sflight ASSIGNING <ls_entry> INDEX es_row_no-row_id.
CHECK ( <ls_entry> IS ASSIGNED ).
Set all radio buttons "unselected"
<ls_entry>-button1 = icon_wd_radio_button_empty.
<ls_entry>-button2 = icon_wd_radio_button_empty.
<ls_entry>-button3 = icon_wd_radio_button_empty.
<ls_entry>-button4 = icon_wd_radio_button_empty.
ASSIGN COMPONENT e_column_id-fieldname OF STRUCTURE <ls_entry>
TO <ld_fld>.
IF ( <ld_fld> IS ASSIGNED ).
Set selected radio button "selected".
<ld_fld> = icon_wd_radio_button.
ENDIF.
Force PAI followed by refresh of table display in PBO
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFRESH'
IMPORTING
RC =
.
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
----
MAIN *
----
START-OF-SELECTION.
PERFORM select_data.
PERFORM init_controls.
PERFORM build_fieldcatalog.
PERFORM set_layout.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING
it_fieldcatalog = gt_fcat
it_outtab = gt_sflight.
Link docking container to dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
CONTAINER =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
lifetime_dynpro_dynpro_link = 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.
CALL SCREEN 100.
END-OF-SELECTION.
----
MODULE PBO OUTPUT *
----
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
ENDMODULE. "PBO OUTPUT
----
MODULE PAI INPUT *
----
MODULE pai INPUT.
Leave report
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
Refresh table display
WHEN 'REFRESH'.
PERFORM refresh_display.
WHEN OTHERS.
do nothing
ENDCASE.
CLEAR gd_okcode.
ENDMODULE. "PAI INPUT
&----
*& Form BUILD_FIELDCATALOG
&----
text
----
--> p1 text
<-- p2 text
----
FORM build_fieldcatalog .
define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_BUFFER_ACTIVE =
i_structure_name = 'ICON'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
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.
DELETE gt_fcat WHERE ( fieldname <> 'NAME' ).
NOTE: field ICON-NAME has data element ICONNAME.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_BUFFER_ACTIVE =
i_structure_name = 'SFLIGHT'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
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.
READ TABLE gt_fcat INTO ls_fcat
WITH KEY fieldname = 'NAME'.
IF ( syst-subrc = 0 ).
DELETE gt_fcat INDEX syst-tabix.
ENDIF.
ls_fcat-fieldname = 'BUTTON4'.
ls_fcat-coltext = ls_fcat-fieldname.
ls_fcat-icon = 'X'.
ls_fcat-hotspot = 'X'.
INSERT ls_fcat INTO gt_fcat INDEX 5.
*
ls_fcat-fieldname = 'BUTTON3'.
ls_fcat-coltext = ls_fcat-fieldname.
INSERT ls_fcat INTO gt_fcat INDEX 5.
*
ls_fcat-fieldname = 'BUTTON2'.
ls_fcat-coltext = ls_fcat-fieldname.
INSERT ls_fcat INTO gt_fcat INDEX 5.
*
ls_fcat-fieldname = 'BUTTON1'.
ls_fcat-coltext = ls_fcat-fieldname.
INSERT ls_fcat INTO gt_fcat INDEX 5.
Renumbering of the columns
LOOP AT gt_fcat INTO ls_fcat.
ls_fcat-col_pos = syst-tabix.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDLOOP.
ENDFORM. " BUILD_FIELDCATALOG
&----
*& Form SELECT_DATA
&----
text
----
--> p1 text
<-- p2 text
----
FORM select_data .
define local data
DATA:
ls_sflight TYPE ty_s_sflight.
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight.
ls_sflight-button1 = icon_wd_radio_button. " selected radiobutton
ls_sflight-button2 = icon_wd_radio_button_empty.
ls_sflight-button3 = icon_wd_radio_button_empty.
ls_sflight-button4 = icon_wd_radio_button_empty.
Alternatively: create icons using function module 'ICON_CREATE'
on SAP releases where these icons are not available.
MODIFY gt_sflight FROM ls_sflight
TRANSPORTING button1 button2 button3 button4
WHERE ( carrid IS NOT INITIAL ).
ENDFORM. " SELECT_DATA
&----
*& Form INIT_CONTROLS
&----
text
----
--> p1 text
<-- p2 text
----
FORM init_controls .
CHECK ( go_docking IS NOT BOUND ).
Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
REPID =
DYNNR =
SIDE = DOCK_AT_LEFT
EXTENSION = 50
STYLE =
LIFETIME = lifetime_default
CAPTION =
METRIC = 0
ratio = 90
NO_AUTODEF_PROGID_DYNNR =
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.
Size of container = full screen size
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999
EXCEPTIONS
cntl_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.
Create ALV grid instance
CREATE OBJECT go_grid
EXPORTING
I_SHELLSTYLE = 0
I_LIFETIME =
i_parent = go_docking
I_APPL_EVENTS = space
I_PARENTDBG =
I_APPLOGPARENT =
I_GRAPHICSPARENT =
I_NAME =
I_FCAT_COMPLETE = SPACE
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.
Set event handler for event HOTSPOT_CLICK
SET HANDLER:
lcl_eventhandler=>handle_hotspot_click FOR go_grid.
ENDFORM. " INIT_CONTROLS
&----
*& Form REFRESH_DISPLAY
&----
Refresh table display after switching the radiobuttons
----
--> p1 text
<-- p2 text
----
FORM refresh_display .
define local data
DATA:
ls_stable TYPE lvc_s_stbl.
ls_stable-row = abap_true.
ls_stable-col = abap_true.
CALL METHOD go_grid->refresh_table_display
EXPORTING
is_stable = ls_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.
ENDFORM. " REFRESH_DISPLAY
&----
*& Form SET_LAYOUT
&----
Set layout for ALV list
----
--> p1 text
<-- p2 text
----
FORM set_layout .
CLEAR: gs_layout.
gs_layout-cwidth_opt = abap_true. " optimize column width
gs_layout-zebra = abap_true.
ENDFORM. " SET_LAYOUT
Hope its helpfull to you.
Regards,
Bhaskar