10-08-2007 2:33 PM
My requirement contains traffic lights in output. Based on condition, the colour of this traffic light changes. it is OK. But in output I get the corresponding column heading as 'exception'. how to change this column heading.
My logic contains.
LS_LAYOUT-LIGHTS_FIELDNAME = 'LIGHTS'.
LS_LAYOUT-LIGHTS_TABNAME = 'IT_STPO'.
Regards,
Zakir.
10-08-2007 2:35 PM
10-08-2007 2:37 PM
&----
*& Report ZMDEMO_ALV_04
*&
&----
*&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
Eg:2
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.
Please give me reward point If it is useful
Thanks
Murali Poli
10-08-2007 2:44 PM
Hi,
First of all write : INCLUDE <ICON> in ur program.
Declare a field in the internal table used for display for icon display ad ICON-ID.
Pass the values @5C@, @5D@ and @5B@ according to the condition.
In the fieldcatalog make the icon field as X.
(or)
data: result(2).
assign ICON_GREEN_LIGHT to .
if result = 'OK'.
assign ICON_GREEN_LIGHT to .
else.
assign ICON_RED_LIGHT to .
endif.
write: as icon.
The name of the traffic light field is supplied in the layout-excp_fname used by method set_table_for_first_display.
The name of the trafic lights should be filled in field lights_fieldname of is_layout parameter
Reward if helpful.
Regards,
Harini.S
10-08-2007 3:02 PM
hi
good
go through this link,which ll give you complete idea about the traffic light output in alv.
http://sgstocks.tripod.com/alvgrid_control.htm
thanks
mrutyun^