Sie sind auf Seite 1von 6

*&---------------------------------------------------------------------*

*& Report ZBAALVOO


*&
*&---------------------------------------------------------------------*
* Project
: Utilities
*
* Creation Date
: June 2008
*
* Created By
: Sheila Titchener (iconet-ltd.co.uk)
*
* Purpose of the program : ALV OO SKELETON
*
*&---------------------------------------------------------------------*
*
Amendments
*
*&---------------------------------------------------------------------*
report zbaalvoo.
*------------------------------* input file format
*------------------------------types: begin of ty_tab,
carrid type s_carr_id,
connid type s_conn_id,
price type s_price,
currency type s_currcode,
planetype type s_planetye,
end of ty_tab.
*------------------------------* display format
*------------------------------types: begin of ty_display.
include type ty_tab.
types: mess type string,
row_colour type lvc_t_scol,
end of ty_display.
*------------------------------data: i_tab type table of ty_tab,
w_tab type ty_tab,
w_head type ty_tab.
data: w_display type ty_display.
data: i_display type table of ty_display.
*------------------------------* new alv objects
*------------------------------data: gr_table
type ref to cl_salv_table,
gr_selections type ref to cl_salv_selections,
gr_colors type ref to cl_salv_columns_table.
*DATA g_index TYPE sy-tabix.
* test colours
parameters: p_color(1) type n,
p_int(1) type n,
p_inv(1) type n.

* ALV Class definitions................................................


*----------------------------------------------------------------------class lcl_handle_events definition.
*----------------------------------------------------------------------public section.
data:
list_id type i.
methods:
on_user_command
for event added_function of cl_salv_events
importing e_salv_function,
*
on_double_click
for event link_click of cl_salv_events_table
importing row column.
*
.
endclass.
" CLASS LCL_EVENT_HANDLER DEF..
*----------------------------------------------------------------------* ALV Class implementation............................................
* In the Event of a Double Click drill down to the corresponding Document
*----------------------------------------------------------------------class lcl_handle_events implementation.
method on_user_command.
case sy-ucomm.
when 'MYFUNCTION'.
perform process_selected_lines.

*
*
*
*

endcase.
endmethod.
"on_user_command
HOT SPOT processing
method on_double_click.
case column.
when others.
read table i_display index row into w_display.
CHECK NOT w_display-doc_num IS INITIAL.
SET PARAMETER ID 'BLN' FIELD w_display-doc_num.
SET PARAMETER ID 'BUK' FIELD p_bukrs.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
endcase.
endmethod.
" HANDLE_DOUBLE_CLICK

endclass.
data: gr_events

"lcl_handle_events IMPLEMENTATION
type ref to lcl_handle_events.

*&---------------------------------------------------------------------*
start-of-selection.
*&---------------------------------------------------------------------*
select carrid connid price currency planetype
from sflight client specified into table i_tab
where mandt = sy-mandt.
data: ls_colour

type lvc_s_scol.

loop at i_tab into w_tab.


move-corresponding w_tab to w_display.

* set row colour


* set first line red
if sy-tabix = 1.
ls_colour-color-col = 6.
"red
ls_colour-color-int = 0.
"intensified off
ls_colour-nokeycol = 'X'.
"
append ls_colour to w_display-row_colour.
else.
refresh w_display-row_colour.
endif.
* output message
case p_color.
when 1.
w_display-mess = 'Grey/blue'.
when 2.
w_display-mess = 'White/Grey'.
when 3.
w_display-mess = 'Yellow'.
when 4.
w_display-mess = 'Pale Blue'.
when 5.
w_display-mess = 'Green'.
when 6.
w_display-mess = 'Red'.
when 7.
w_display-mess = 'Orange'.
endcase.
append w_display to i_display.
endloop.
*&---------------------------------------------------------------------*
end-of-selection.
*&---------------------------------------------------------------------*
perform display_alv.
*&---------------------------------------------------------------------*
*&
Form DISPLAY_ALV
*&---------------------------------------------------------------------*
*
OO ALV - ( Model SALV_* programs)
*----------------------------------------------------------------------*
form display_alv .
*... 2 create an ALV table
*
2.2 just create an instance and do not set LIST_DISPLAY for
*
displaying the data as a Fullscreen Grid
try.
cl_salv_table=>factory(
importing
r_salv_table = gr_table
changing
t_table
= i_display ).
catch cx_salv_msg.
"#EC NO_HANDLER
endtry.
*... 3 Functions
*... 3.1 activate ALV generic Functions
*... 3.2 include own functions by setting own status
* create a copy of SALV_TEST_TABLE_EVENTS cua SALV_STANDARD and set report
* to sy-repid
gr_table->set_screen_status(

pfstatus
= 'SALV_STANDARD'
report
= 'ZBAALVOO'
set_functions = gr_table->c_functions_all ).
data: lr_column type ref to cl_salv_column_table,
lr_columns type ref to cl_salv_columns.
**... optimize the column widths
try.
lr_columns = gr_table->get_columns( ).
lr_columns->set_optimize( ).
catch cx_salv_not_found.
endtry.

"#EC NO_HANDLER

* highlight/ color certain columns


perform highlight_columns using lr_columns.
* remove columns not needed for this type of report(set_technical)
perform remove_columns using lr_columns.
* change descriptions if dictionery values not adequate
perform set_columns_description using lr_columns.
*... 4 set hotspot column - and key columns - if any
try.
lr_column ?= lr_columns->get_column( 'CONNID' ).
lr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
lr_column->set_key( ).
catch cx_salv_not_found.
"#EC NO_HANDLER
endtry.
*
*... 4.2 set the selection mode of the Popup: multiple or single row selection
data: lr_selections type ref to cl_salv_selections.
lr_selections = gr_table->get_selections( ).
lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).
**... 5.2 set the color of a complete row -same method for single cell or whole r
ow
**
if whole row leave out column name
**
(1) register the column in which the color information
**
for the row is held
gr_colors = gr_table->get_columns( ).
try.
gr_colors->set_color_column( 'ROW_COLOUR' ).
gr_colors->set_key_fixation( ).
catch cx_salv_data_error.
"#EC NO_HANDLER
endtry.
*
*... 6 register to the events of cl_salv_table
data: lr_events type ref to cl_salv_events_table.
lr_events = gr_table->get_event( ).
create object gr_events.
*... 6.1 register to the event USER_COMMAND
set handler gr_events->on_user_command for lr_events.
**... 6.4 register to the event DOUBLE_CLICK

set handler gr_events->on_double_click for lr_events.


*... 6.5 register to the event LINK_CLICK
* SET HANDLER gr_events->on_link_click FOR lr_events.
*... set list title
data: lr_display_settings type ref to cl_salv_display_settings,
l_title type lvc_title.
* it is possible to use EITHER set title bar OR method set_list_header.
* l_title = text-t01.
* lr_display_settings = gr_table->get_display_settings( ).
* lr_display_settings->set_list_header( l_title ).
**... - Hide internal Object id - allows for optional inclusion
try.
lr_column ?= lr_columns->get_column( 'PLANETYPE' ).
lr_column->set_visible( if_salv_c_bool_sap=>false ).
catch cx_salv_not_found.
"#EC NO_HANDLER
endtry.
*... 7 display the table
gr_table->display( ).
endform.
" DISPLAY_ALV
*&---------------------------------------------------------------------*
*&
Form SET_COLUMNS_DESCRIPTION
*&---------------------------------------------------------------------*
* Set different text headings where required - and field lengths
* headings & field lengths can be defaulted from the dictionary if suitable
*----------------------------------------------------------------------*
*
-->IR_COLUMNS text
*----------------------------------------------------------------------*
form set_columns_description using p_columns type ref to cl_salv_columns.
data: lr_column type ref to cl_salv_column.
* optimizing at column level doesn't seem to work
* either all columns are optimized or none
* set headings & field lengths
try.
lr_column = p_columns->get_column( 'PRICE' ).
lr_column->set_short_text( 'AirF').
lr_column->set_medium_text( 'Price............').
lr_column->set_long_text( 'Price............' ).
lr_column->set_output_length( '8' ). "overrides optimize
catch cx_salv_not_found.
"#EC NO_HANDLER
endtry.
endform.
"set_columns_description
*&---------------------------------------------------------------------*
*&
Form REMOVE_COLUMNS
*&---------------------------------------------------------------------*
*
permanently remove any columns not required for this display
*----------------------------------------------------------------------*
*
-->ir_columns
*----------------------------------------------------------------------*
form remove_columns using p_columns type ref to cl_salv_columns.
data: lr_column type ref to cl_salv_column.
try.
lr_column = p_columns->get_column( 'CURRENCY' ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found.
"#EC NO_HANDLER
endtry.
endform.
" REMOVE_COLUMNS
*&---------------------------------------------------------------------*
*&
Form HIGHLIGHT_EQUIPMENT
*&---------------------------------------------------------------------*
*
set column colours
*----------------------------------------------------------------------*
* This uses a different class from set_technical and set..text because
* cl_salv_column does not have set_color as a method where-as
* cl_salv_column_table does
* NOTE - you need the ?= to assign the column name in this case??
*
*
-->P_COLUMNS text
*----------------------------------------------------------------------*
form highlight_columns using p_columns type ref to cl_salv_columns.
data:
data:

lr_column type ref to cl_salv_column_table. "<<<<<<<<<<<


l_col
type lvc_s_colo.
"COLOUR

l_col-inv = p_inv. " inverse


l_col-int = p_int. " intensify
* 1 = grey/blue, 2=light grey, 3=yellow, 4=blue/green, 5= green, 6=red, 7=orange
.
l_col-col = p_color. " colour
try.
lr_column ?= p_columns->get_column( 'CARRID' ).
lr_column->set_color( l_col ).
catch cx_salv_not_found.
endtry.
endform.

"#EC NO_HANDLER

" HIGHLIGHT_EQUIPMENT

*&---------------------------------------------------------------------*
*&
Form process_selected_lines
*&---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form process_selected_lines .
data: lr_selections type ref to cl_salv_selections.
data: lt_rows type salv_t_row.
data: l_row

type i.

lr_selections = gr_table->get_selections( ).
lt_rows = lr_selections->get_selected_rows( ).
loop at lt_rows into l_row.
read table i_tab into w_tab index l_row.
* process selected line
message i899(bd) with l_row.
endloop.
endform.

" process_selected_lines

Das könnte Ihnen auch gefallen