Hi Masters,
i have tried my best to Impliment the TRAFIC LIGHTS in my alv report but i could not succeed.
can i have some input as to how we impliment the TRAFIC LIGHTS CODE in alv report.
your valuble info is highly appriciated.
thank you,
pasala.
Pasala,
check these links
http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP-TrafficSignalsinALVusing+Classes
http://wiki.sdn.sap.com/wiki/display/Snippets/ALVGRIDCOMPLETEEXAMPLEWITHTOOLBARBUTTONSUSINGCLASS.
Thanks
Bala Duvvuri
there are two ways, if u need only one column with traffic lights then use field catalogue filed LIGHT. else use ICON
Hi Pasala,
Have a look at this thread
Re: exception field traffic light
I hope it helps...:)
Regards
Amit
Hello friend,
try following codes:
TYPES: BEGIN OF ty_data, name TYPE string, HP TYPE i, MP TYPE i, DP TYPE i, job TYPE string, exception TYPE c LENGTH 1, counter TYPE i, t_color TYPE lvc_t_scol, END OF ty_data. TYPES: tt_data TYPE STANDARD TABLE OF ty_data. DATA: item TYPE ty_data, lt_data TYPE tt_data, color TYPE lvc_s_scol. item-name = 'A1'. item-HP = 5000. item-MP = 400. item-DP = 300. item-job = 'SOR'. item-exception = '3'. color-FNAME = 'HP'. color-color-col = '4'. APPEND color TO item-t_color. APPEND item TO lt_data. item-HP = 4000. item-MP = 200. item-DP = 600. color-FNAME = 'MP'. color-color-col = '5'. APPEND color TO item-t_color. APPENd item TO lt_data. item-name = 'A2'. item-HP = 3000. item-MP = 600. item-DP = 200. item-job = 'NEC'. item-counter = 2. item-exception = '1'. CLEAR: item-t_color. APPEND item TO lt_data. item-name = 'A3'. item-HP = 2000. item-MP = 800. item-DP = 1000. item-job = 'BAR'. item-counter = 3. color-FNAME = 'DP'. color-color-col = '1'. APPEND color TO item-t_color. item-exception = '2'. APPEND item TO lt_data. DATA: lo_salv_table TYPE REF TO cl_salv_table. TRY. cl_salv_table=>factory( EXPORTING list_display = sy-batch IMPORTING r_salv_table = lo_salv_table CHANGING t_table = lt_data ). CATCH cx_salv_msg. RETURN. ENDTRY. DATA: lo_functions TYPE REF TO cl_salv_functions_list. lo_functions = lo_salv_table->get_functions( ). lo_functions->set_all( abap_true ). DATA: lo_layout TYPE REF TO cl_salv_layout, ls_layout_key TYPE salv_s_layout_key. lo_layout = lo_salv_table->get_layout( ). ls_layout_key-report = sy-repid. lo_layout->set_key( ls_layout_key ). lo_layout->set_default( abap_false ). lo_layout->set_save_restriction( if_salv_c_layout=>restrict_none ). DATA: lo_columns TYPE REF TO cl_salv_columns_table, lo_column TYPE REF TO cl_salv_column_table, lt_column_ref TYPE salv_t_column_ref, ls_column_ref TYPE salv_s_column_ref, lv_column_pos TYPE i. lo_columns = lo_salv_table->get_columns( ). lt_column_ref = lo_columns->get( ). LOOP AT lt_column_ref INTO ls_column_ref. CASE ls_column_ref-columnname. WHEN 'JOB'. ls_column_ref-r_column->set_visible( if_salv_c_bool_sap=>false ). WHEN 'EXCEPTION' OR 'COUNTER' OR 'T_COLOR'. ls_column_ref-r_column->set_technical( if_salv_c_bool_sap=>true ). WHEN 'COUNTER'. " ls_column_ref-r_column->set_technical( if_salv_c_bool_sap=>true ). ls_column_ref-r_column->set_visible( if_salv_c_bool_sap=>false ). * * WHEN OTHERS. * ls_column_ref-r_column->set_visible( if_salv_c_bool_sap=>false ). ENDCASE. ENDLOOP. LOOP AT lt_column_ref INTO ls_column_ref. lo_column ?= ls_column_ref-r_column. CASE ls_column_ref-columnname. WHEN 'HP'. lo_column->set_short_text( space ). lo_column->set_medium_text( space ). lo_column->set_long_text( 'Player Life' ). lo_column->set_tooltip( 'Player Life' ). WHEN 'NAME'. lo_column->set_short_text( space ). lo_column->set_medium_text( space ). lo_column->set_long_text( 'Name' ). lo_column->set_tooltip( 'Name' ). WHEN 'MP'. lo_column->set_short_text( space ). lo_column->set_medium_text( space ). lo_column->set_long_text( 'Player Magic Point' ). lo_column->set_tooltip( 'Player Magic Point' ). WHEN 'DP'. lo_column->set_short_text( space ). lo_column->set_medium_text( space ). lo_column->set_long_text( 'Player Duration Point' ). lo_column->set_tooltip( 'Player Duration Point' ). ENDCASE. ENDLOOP. TRY. lo_columns->set_exception_column( 'EXCEPTION' ). lo_columns->set_count_column( 'COUNTER' ). lo_columns->set_color_column( 'T_COLOR' ). CATCH cx_salv_data_error. "#EC NO_HANDLER ENDTRY. lo_columns->set_key_fixation( abap_true ). lo_columns->set_optimize( abap_true ). DATA: lo_sort TYPE REF TO cl_salv_sorts. lo_sort = lo_salv_table->get_sorts( ). TRY. lo_sort->add_sort( columnname = 'NAME' ). CATCH cx_salv_not_found cx_salv_existing cx_salv_data_error. "#EC NO_HANDLER ENDTRY. lo_salv_table->display( ).
the previous post is the sample code if you want to use ALV via cl_salv_table, but if you want to build ALV using function module REUSE_ALV_GRID_DISPLAY, please try following sample code. It works in my computer. Hope it helps.
types: begin of gs_outtab.
types: lights type char1,
color type i,
tabcol type lvc_t_scol,
id type char25, " Already exist in ICON, Flat Structure
name type icon-name,
symbol type icon-id,
end of gs_outtab.
data: gt_outtab type standard table of gs_outtab.
data: gr_grid type ref to cl_gui_alv_grid.
data: gr_container type ref to cl_gui_custom_container,
gs_layout type lvc_s_layo,
gt_fieldcat type lvc_t_fcat.
data: ls_vari type disvariant.
data: g_okcode type syucomm.
data: gt_exc type table of ALV_S_QINF.
data: text type string.
selection-screen begin of block gen with frame.
parameters:
p_amount type i default 20.
selection-screen end of block gen.
selection-screen begin of block dsp with frame.
parameters:
p_full radiobutton group dsp,
p_grid radiobutton group dsp.
selection-screen end of block dsp.
START-OF-SELECTION.
END-OF-SELECTION.
perform select_data.
IF p_full = 'X'.
perform display_fullscreen.
ELSE.
perform display_grid.
ENDIF.
STEP 1: load data *******************************************
form select_data.
select * from icon into corresponding fields of table gt_outtab
up to p_amount rows.
endform.
STEP2: build full screen **************************************
form display_fullscreen .
data: ls_layout type slis_layout_alv,
lt_fcat type slis_t_fieldcat_alv,
ls_fcat type slis_fieldcat_alv.
ls_layout-lights_tabname = '1'.
ls_layout-lights_fieldname = 'LIGHTS'.
ls_layout-coltab_fieldname = 'TABCOL'.
clear ls_fcat.
ls_fcat-fieldname = 'LIGHTS'.
ls_fcat-inttype = 'C'.
ls_fcat-seltext_l = ls_fcat-seltext_m = ls_fcat-seltext_s = 'Lights'.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'COLOR'.
ls_fcat-inttype = 'I'.
ls_fcat-seltext_l = ls_fcat-seltext_m = ls_fcat-seltext_s = 'Color'.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'ID'.
ls_fcat-inttype = 'C'.
ls_fcat-seltext_l = ls_fcat-seltext_m = ls_fcat-seltext_s = 'Icon'.
ls_fcat-icon = abap_true.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'SYMBOL'.
ls_fcat-inttype = 'C'.
ls_fcat-seltext_l = ls_fcat-seltext_m = ls_fcat-seltext_s = 'Symbol'.
ls_fcat-symbol = abap_true.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'NAME'.
ls_fcat-tech = abap_true.
append ls_fcat to lt_fcat.
perform select_data.
perform set_tooltips.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = ls_layout
IT_FIELDCAT = lt_fcat
IT_EXCEPT_QINFO = gt_exc
TABLES
T_OUTTAB = gt_outtab
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
ASSERT sy-subrc = 0.
endform.
STEP3: display grid ******************************************
form display_grid.
call screen 100.
endform.
STEP4: PBO ***************************************************
module d0100_pbo output.
perform d0100_pbo.
endmodule.
STEP5: PAI ***************************************************
module d0100_pai input.
perform d0100_pai.
endmodule.
STEP6: PBO form ***********************************************
form d0100_pbo .
set pf-status 'D0100'.
if gr_container is not bound.
create object gr_container
exporting
container_name = 'CONTAINER'.
create object gr_grid
exporting i_parent = gr_container.
data: ls_layout type lvc_s_layo,
lt_fcat type lvc_t_fcat,
ls_fcat type lvc_s_fcat.
ls_layout-excp_fname = 'LIGHTS'.
ls_layout-ctab_fname = 'TABCOL'.
clear ls_fcat.
ls_fcat-fieldname = 'LIGHTS'.
ls_fcat-inttype = 'C'.
ls_fcat-scrtext_l = ls_fcat-scrtext_m = ls_fcat-scrtext_s = 'Lights'.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'COLOR'.
ls_fcat-inttype = 'I'.
ls_fcat-scrtext_l = ls_fcat-scrtext_m = ls_fcat-scrtext_s = 'Color'.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'ID'.
ls_fcat-inttype = 'C'.
ls_fcat-scrtext_l = ls_fcat-scrtext_m = ls_fcat-scrtext_s = 'Icon'.
ls_fcat-icon = abap_true.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'SYMBOL'.
ls_fcat-inttype = 'C'.
ls_fcat-scrtext_l = ls_fcat-scrtext_m = ls_fcat-scrtext_s = 'Symbol'.
ls_fcat-symbol = abap_true.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'NAME'.
ls_fcat-tech = abap_true.
append ls_fcat to lt_fcat.
perform select_data.
perform set_tooltips.
data: lt_tooltips type lvc_t_qinf,
lt_toolb type ui_functions,
ls_toolb type UI_FUNC.
ls_toolb = CL_GUI_ALV_GRID=>mc_fc_call_crbatch.
append ls_toolb to lt_toolb.
lt_tooltips = gt_exc.
call method gr_grid->set_table_for_first_display
exporting is_layout = ls_layout
it_except_qinfo = lt_tooltips
it_toolbar_excluding = lt_toolb
changing
it_fieldcatalog = lt_fcat
it_outtab = gt_outtab.
endif.
endform.
STEP7: PAI form ******************************************************
form d0100_pai .
case g_okcode.
when 'BACK' or 'EXIT' or 'CANC'.
set screen 0.
leave screen.
endcase.
endform.
STEP8: Set Tooltip *************************************************
FORM set_tooltips .
field-symbols: <outtab> type gs_outtab.
data: tooltips type ref to cl_salv_tooltips,
settings type ref to cl_salv_functional_settings,
ls_styl type lvc_s_styl,
value type char128,
text type char40,
ls_symbol type icon,
lt_symbol type standard table of icon,
ls_exc type ALV_S_QINF,
tabix type sy-tabix,
col type lvc_s_scol.
loop at gt_outtab assigning <outtab>.
tabix = sy-tabix.
read table lt_symbol index sy-tabix into ls_symbol.
<outtab>-symbol = ls_symbol-id.
value = <outtab>-id(3).
text = <outtab>-name.
concatenate value '\Q' text '@' into value.
<outtab>-id = value.
value = ls_symbol-id.
text = ls_symbol-name.
ls_exc-type = cl_salv_tooltip=>c_type_symbol.
ls_exc-value = value.
ls_exc-text = text.
append ls_exc to gt_exc.
<outtab>-color = tabix mod 7 + 1.
<outtab>-lights = tabix mod 3 + 1.
col-fname = 'COLOR'.
col-color-col = tabix mod 7 + 1.
if tabix ge 7.
col-color-inv = 1.
endif.
if tabix ge 14.
col-color-int = 1.
endif.
append col to <outtab>-tabcol.
endloop.
ENDFORM.
hi Jerry,
thank you so much for the response... however i have done me report where i get the trafic lights at the output...
but the PROBLEM is i dont the the selection screen instead i get the output directly... i have tried to rectify but i dint get where the problem is... can you please tell as where is the problem.. below is my code.
*---> Types
TYPE-POOLS :slis, icon.
*---> Tables
TABLES : zmesg_xml_exept.
*---> Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: so_work FOR zxml_in_store-cont_work_order.
SELECTION-SCREEN END OF BLOCK blk1.
data: alv_container type ref to cl_gui_docking_container.
data: alv_grid type ref to cl_gui_alv_grid.
data: layout type lvc_s_layo.
data: fieldcat type lvc_t_fcat.
types: begin of ty_cust,
error type zmesg_xml_exept-error,
mess_timing type zmesg_xml_exept-mess_timing, "Message creation
cont_work_order type zmesg_xml_exept-cont_work_order,
process_ind type zmesg_xml_exept-process_ind,
lights(1) type c,
end of ty_cust.
data: wt_cust type standard table of ty_cust,
wa_cust type ty_cust.
data: variant type disvariant.
data: repid type sy-repid. repid = sy-repid.
initialization.
start-of-selection.
perform get_details.
form GET_DETAILS .
SELECT mess_timing
process_ind
cont_work_order
error
FROM zmesg_xml_exept
INTO CORRESPONDING FIELDS OF TABLE wt_cust
WHERE process_ind EQ 'D'
OR process_ind EQ 'A'.
endform
hi,
give the code for dispalying screen in PBO of screen.
and call screen in START-OF-SELECTION event this will solve your problem of not displaying selection screen.
Revert for further queries.
Thanks,
Gaurav.
rest of the code ...
perform layout.
form LAYOUT .
loop at wt_cust into wa_cust.
if wa_cust-process_ind = 'D'.
wa_cust-lights = '2'.
elseif wa_cust-process_ind = 'A'.
wa_cust-lights = '1'.
endif.
modify wt_cust from wa_cust transporting lights.
endloop.
layout-excp_fname = 'LIGHTS'.
endform.
perform alvcontainer.
form ALVCONTAINER .
**********************************************************
***Create object alv container
**********************************************************
check alv_container is initial.
create object alv_container
exporting
repid = sy-repid
dynnr = sy-dynnr
side = alv_container->dock_at_left
extension = 1550
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 object alv Grid
*********************************************************
create object alv_grid
exporting
i_parent = alv_container.
***Perform to d3esign field catalog
perform fieldcatatalog.
*********************************************************
**Call method set table for first display
*********************************************************
call method alv_grid->set_table_for_first_display
exporting
i_structure_name = 'WT_CUST'
is_variant = variant
i_save = 'U'
is_layout = layout
changing
it_outtab = wt_cust
it_fieldcatalog = fieldcat
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.
endform. " ALVCONTAINER
****Perform to d3esign field catalog
rest of the code...
perform fieldcatatalog.
form FIELDCATATALOG .
data: ls_fcat type lvc_s_fcat.
refresh: fieldcat.
clear: ls_fcat.
ls_fcat-reptext = 'Signal'.
ls_fcat-fieldname = 'LIGHTS'.
ls_fcat-ref_table = 'WT_CUST'.
ls_fcat-outputlen = '4'.
ls_fcat-col_pos = '1'.
append ls_fcat to fieldcat.
clear: ls_fcat.
clear: ls_fcat.
ls_fcat-reptext = 'Error'.
ls_fcat-fieldname = 'Error'.
ls_fcat-ref_table = 'WT_CUST'.
ls_fcat-outputlen = '4'.
ls_fcat-col_pos = '2'.
append ls_fcat to fieldcat.
clear: ls_fcat.
endform. " FIELDCATATALOG
thank you all