‎2007 Feb 22 5:41 AM
Hello All,
Could you please send me some code, to place a traffice lights in ALV output.
Thanks & Regards,
Janardhan
‎2007 Feb 22 5:45 AM
Hi,
Define the output table to be displayed with teh first field as
light TYPE LIGHT.
You can put your conditions here. Based upon the conditions you can
display the lights as Red, Yellow or Green
w_output-light = '1'. Red
w_output-matnr = '000123456'.
w_output-msgty = '1'.
APPEND w_output TO i_output.
w_output-light = '2'. Yellow
w_output-matnr = '000123457'.
w_output-msgty = '1'.
APPEND w_output TO i_output.
w_output-light = '3'. Green
w_output-matnr = '000123458'.
w_output-msgty = '1'.
APPEND w_output TO i_output.Also in layout
w_layout-grid_title = ptitle.
w_layout-zebra = pzebra.
w_layout-sel_mode = pmode.
w_layout-cwidth_opt = pwidth.
w_variant-handle = pvariant.
w_variant-report = sy-repid.w_layout-excp_fname = 'LIGHT'.
Reward if this helps.
‎2007 Feb 22 5:45 AM
Hi,
Define the output table to be displayed with teh first field as
light TYPE LIGHT.
You can put your conditions here. Based upon the conditions you can
display the lights as Red, Yellow or Green
w_output-light = '1'. Red
w_output-matnr = '000123456'.
w_output-msgty = '1'.
APPEND w_output TO i_output.
w_output-light = '2'. Yellow
w_output-matnr = '000123457'.
w_output-msgty = '1'.
APPEND w_output TO i_output.
w_output-light = '3'. Green
w_output-matnr = '000123458'.
w_output-msgty = '1'.
APPEND w_output TO i_output.Also in layout
w_layout-grid_title = ptitle.
w_layout-zebra = pzebra.
w_layout-sel_mode = pmode.
w_layout-cwidth_opt = pwidth.
w_variant-handle = pvariant.
w_variant-report = sy-repid.w_layout-excp_fname = 'LIGHT'.
Reward if this helps.
‎2007 Feb 22 5:47 AM
Hi Jana,
Please try the below Sample codes .It will be helpful in the traficc lights.
<u><b>Sample 1</b></u>
TYPES: BEGIN OF X1,
XX TYPE Y,
YY TYPE X,
traffic_light(1) ,
END OF X1.
DATA: X1 TYPE ITAB OCCURS 0 WITH HEADER LINE.
DATA: ls_layout TYPE slis_layout_alv.
traffic light color display depends on your condition.
itab-traffic_light = 1 or 2 or 3.
ls_layout-lights_fieldname = 'TRAFFIC_LIGHT'.
ls_layout-lights_condense = 'X'.
ls_layout-lights_rollname = 'ZECEP'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = 'YOUR_PRG_NAME'
is_layout = ls_layout
it_fieldcat = it_fieldcat
i_callback_top_of_page = 'TOP_OF_PAGE'
TABLES
t_outtab = ITAB.
-
<u><b>Sample 2</b></u>*
&----
*
*& Report ZALV_DEMO
&----
*&Make an Exception field ( = Traffic lights)
*&There can be defined a column in the grid for display of traffic lights. This field is of type Char 1, and can contain the following values:
*& 1 Red
*& 2 Yellow
*& 3 Green
*&The name of the traffic light field is supplied inh the gs_layout-excp_fname used by method set_table_for_first_display.
*&
&----
report zmdemo_alv_04.
tables: sflight.
type-pools: icon.
types: begin of ty_sflight.
include structure sflight.
types: traffic_light type c,
lights LIKE icon_xml_doc,
lights(4),
icon type icon-id.
types: end of ty_sflight.
*----
G L O B A L I N T E R N A L T A B L E S
*----
data: t_sflight type standard table of ty_sflight.
*----
G L O B A L D A T A
*----
data: ok_code like sy-ucomm,
wa_sflight type ty_sflight.
Declare reference variables to the ALV grid and the container
data:
go_grid type ref to cl_gui_alv_grid,
go_custom_container type ref to cl_gui_custom_container.
data:
t_fcat type lvc_t_fcat,
wa_layout type lvc_s_layo.
*----
S T A R T - O F - S E L E C T I O N.
*----
start-of-selection.
perform build_fieldcat.
perform build_layout.
set screen '100'.
&----
*& Module USER_COMMAND_0100 INPUT
&----
module user_command_0100 input.
case ok_code.
when 'EXIT'.
leave to screen 0.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
&----
*& Module STATUS_0100 OUTPUT
&----
module status_0100 output.
Create objects
if go_custom_container is initial.
create object go_custom_container
exporting container_name = 'ALV_CONTAINER'.
create object go_grid
exporting
i_parent = go_custom_container.
perform load_data_into_grid.
endif.
endmodule. " STATUS_0100 OUTPUT
&----
*& Form load_data_into_grid
&----
form load_data_into_grid.
data l_light type c value '1'.
Read data from table SFLIGHT
select *
from sflight
into table t_sflight.
Condition placing to the traffic_light Field
LOOP AT t_sflight INTO wa_sflight.
wa_sflight-traffic_light = l_light.
MODIFY t_sflight FROM wa_sflight.
*
IF l_light = '3'.
l_light = '1'.
*
ELSE.
l_light = l_light + 1.
ENDIF.
ENDLOOP.
*
Setting the Icon based on the traffic_light field value.
LOOP AT t_sflight INTO wa_sflight.
CASE wa_sflight-traffic_light.
WHEN '1'.
wa_sflight-lights = icon_red_light.
WHEN '2'.
wa_sflight-lights = icon_yellow_light.
WHEN '3'.
wa_sflight-lights = icon_green_light.
ENDCASE.
MODIFY t_sflight FROM wa_sflight.
ENDLOOP.
loop at t_sflight into wa_sflight.
case l_light.
when '1'.
wa_sflight-lights = icon_red_light.
when '2'.
wa_sflight-lights = icon_yellow_light.
when '3'.
wa_sflight-lights = icon_green_light.
endcase.
if l_light = '3'.
l_light = '1'.
else.
l_light = l_light + 1.
endif.
modify t_sflight from wa_sflight.
endloop.
Load data into the grid and display them
call method go_grid->set_table_for_first_display
exporting
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
i_structure_name = 'SFLIGHT'
IS_VARIANT =
i_save = 'A'
I_DEFAULT = 'X'
is_layout = wa_layout
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
changing
it_outtab = t_sflight[]
it_fieldcatalog = t_fcat
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
.
endform. " load_data_into_grid
&----
*& Form build_fieldcat
&----
text
----
--> p1 text
<-- p2 text
----
form build_fieldcat .
data: w_fcat type lvc_s_fcat.
define macro_fcat.
w_fcat-fieldname = &1.
w_fcat-col_pos = &2.
w_fcat-coltext = &3.
append w_fcat to t_fcat.
clear w_fcat.
end-of-definition.
macro_fcat 'CARRID' 1 text-c01 .
macro_fcat 'CONNID' 2 text-c02 .
macro_fcat 'FLDATE' 3 text-c03 .
macro_fcat 'PRICE' 4 text-c04 .
macro_fcat 'SEATSMAX' 5 text-c05 .
macro_fcat 'SEATSOCC' 6 text-c06 .
macro_fcat 'LIGHTS' 7 text-c07 .
endform. " build_fieldcat
&----
*& Form build_layout
&----
text
----
--> p1 text
<-- p2 text
----
form build_layout .
wa_layout-cwidth_opt = 'X'.
wa_layout-excp_fname = 'TRAFFIC_LIGHT'.
wa_layout-excp_group = '1'.
endform. " build_layout
‎2007 Feb 22 5:53 AM
Try this code
REPORT ZJENI_AUTO .
INCLUDE <ICON>.
INCLUDE <SYMBOL>.
TABLES: SFLIGHT.
TYPE-POOLS: SLIS.
DATA: BEGIN OF WA_OUTTAB.
INCLUDE STRUCTURE SFLIGHT.
DATA END OF WA_OUTTAB.
DATA BEGIN OF IT_OUTLET OCCURS 0.
INCLUDE STRUCTURE SFLIGHT.
DATA: LIGHTS,
END OF IT_OUTLET.
*DATA: IT_EVENT TYPE SLIS_T_EVENT,
WA_EVENT LIKE LINE OF IT_EVENT.
*
DATA: IT_OUTTAB LIKE TABLE OF WA_OUTTAB.
*CONSTANTS: FORMNAME_USER_COMMAND TYPE SLIS_FORMNAME VALUE
*'USER_COMMAND'.
*CONSTANTS:ADD TYPE SLIS_FORMNAME VALUE 'USER_COMMAND'
DATA W_LIGNAM TYPE SLIS_FIELDNAME VALUE 'LIGHTS'.
DATA LS_LAYO TYPE SLIS_LAYOUT_ALV. "FOR PASSING LIGHT
SELECTION-SCREEN : BEGIN OF SCREEN 100,
BEGIN OF BLOCK LIGHT WITH FRAME..
PARAMETERS: P_LIGHTS AS CHECKBOX DEFAULT 'X',
P_LIGHTC AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK LIGHT.
SELECTION-SCREEN END OF SCREEN 100.
INITIALIZATION.
CALL SELECTION-SCREEN 100.
WA_REPID = SY-REPID.
AT SELECTION-SCREEN.
SELECT * FROM SFLIGHT INTO TABLE IT_OUTLET .
PERFORM DATA TABLES IT_OUTLET .
PERFORM LAYOUT_BUILD USING LS_LAYO.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
I_BACKGROUND_ID = ' ALV_BACKGROUND'
I_GRID_TITLE = 'AUTOMATION'
I_GRID_SETTINGS =
IS_LAYOUT = LS_LAYO
" WE ARE PASSING THE LIGHT THROUGH THIS LAYOUT ONLY
*
TABLES
T_OUTTAB = IT_OUTLET
"THIS IS THE INTERNAL TABLE FOR OUTPUT
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
***********************************************FOR PRODUCING THE
LIGHT*************************************************
FORM DATA TABLES WA_OUTLET STRUCTURE IT_OUTLET .
LOOP AT WA_OUTLET.
IF SY-TABIX > 15.
WA_OUTLET-LIGHTS = '3'.
ELSEIF SY-TABIX = 1.
WA_OUTLET-LIGHTS = '2'.
ELSE.
WA_OUTLET-LIGHTS = '1'.
ENDIF.
MODIFY IT_OUTLET." FROM WA_OUTLET .
ENDLOOP.
ENDFORM. "data
************************************************************************
******************************************************************
&----
*& Form layout_build
&----
text
----
-->LAYOUT_LS_Ltext
----
***********************************************FOR PASSING THE
LAYOUT********************************************
FORM LAYOUT_BUILD USING LS_LAYO TYPE SLIS_LAYOUT_ALV.
***********HERE LAYOUT_LS_LAYO IS A WORK AREA OF THE INTERNAL TABLE
*SLIS_LAYOUT_ALV
*
IF P_LIGHTS = 'X' OR P_LIGHTC = 'X'.
LS_LAYO-LIGHTS_FIELDNAME = W_LIGNAM.
"SHOULD NOT WRITE IN CODES BECAUSE IT IS A FIELD DONT DO THIS HERE AFTER
".
ELSE.
CLEAR LAYOUT_LS_LAYO-LIGHTS_FIELDNAME.
ENDIF.
ENDFORM. "layout_build
************************************************************************
‎2007 Feb 22 11:00 AM
Hi,
refer this sample program in SE38, BCALV_GRID_04 Trafic Light
Hope this will solve ur problem, please reward and close the thread if this solves ur query.