Vous êtes sur la page 1sur 6

REPORT YALVFACTORY2.

types: begin of t_sflight.


include structure sflight.
types: checkbox type as4flag,
end of t_sflight.
class lcl_handler definition deferred.
DATA: obj_alv TYPE REF TO cl_salv_table,
obj_display TYPE REF TO cl_salv_display_settings,
obj_selections TYPE REF TO cl_salv_selections,
obj_layout TYPE REF TO cl_salv_layout,
obj_functions TYPE REF TO cl_salv_functions_list,
lr_event type ref to cl_salv_events_table,
lr_sorts type ref to cl_salv_sorts,
lr_sort type ref to cl_salv_sort,
gr_container type ref to cl_gui_custom_container,
it_sflight type standard table of t_sflight,
it_temp type table of t_sflight,
wa_t_sflight type t_sflight,
ok_code type sy-ucomm,
lr_column type ref to cl_salv_column_table,
lr_columns type ref to cl_salv_columns_table,
lr_handler type ref to lcl_handler,
wa_sflight type t_sflight,
i_final type table of t_sflight.
data: MANDT_Z type string,
FLDATE_Z type string,
z_string type string,
currency_z type string,
price_z type string,
stofile type string.
class lcl_handler definition.
PUBLIC SECTION.
DATA:
pu_lr_columns type ref to cl_salv_columns_table,
pu_lr_column type ref to cl_salv_column_table.
*** Method for customized Button
METHODS:
on_added_function
FOR EVENT added_function OF cl_salv_events_table
IMPORTING e_salv_function,
*** Method for Clicking the Hotspot column
on_link_click
FOR EVENT link_click of cl_salv_events_table
IMPORTING
row
column.
PRIVATE SECTION.
DATA: pr_message(100) type c.
data: pr_eco type string,
pr_bus type string,
pr_fst type string,
pr_curr type string,
it_scarr type standard table of scarr_tab,
wa_scarr type scarr.

endclass.
class lcl_handler implementation.
METHOD on_added_function.
data: lt_rows type salv_t_row,
l_row
type i,
l_row_string type char128,
l_row_info type char128.
*** Customized Function to re-order columns
IF e_salv_function EQ 'RESEND'.
*** get alv property column
it_temp[] = i_final[].
delete it_temp where checkbox = ' '.
stofile = '/gt/dump/inbound/2012.sto'.
try.
OPEN DATASET stofile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT .
IF sy-subrc ne 0.
write 'error'.
else.
loop at it_temp into wa_sflight.
mandt_z = wa_sflight-mandt.
fldate_z = wa_sflight-fldate.
price_z = wa_sflight-price.
currency_z = wa_sflight-currency.
CONCATENATE MANDT_Z
wa_sflight-carrid
wa_sflight-connid
currency_z
price_z
fldate_z into z_string separated by '|'.
TRANSFER z_string TO stofile.
endloop.
ENDIF.
catch cx_root.
endtry.
CLOSE DATASET stofile.
obj_alv->refresh( ).
ELSEIF e_salv_function EQ 'SELECT'.
wa_sflight-checkbox = 'X'.
modify i_final from wa_sflight transporting checkbox where checkbox NE '
X'.
obj_alv->refresh( ).
ELSEIF e_salv_function EQ 'DESELECT'.
wa_sflight-checkbox = ' '.
modify i_final from wa_sflight transporting checkbox where checkbox NE
' '.
obj_alv->refresh( ).
ENDIF.
ENDMETHOD.

METHOD on_link_click.
if COLUMN = 'CHECKBOX'.
PERFORM f_change_flag USING row.
ENDIF.
ENDMETHOD.
endclass.
START-OF-SELECTION.
"CREATE OBJECT r_handler.
select * from sflight into wa_sflight.
* SELECT * FROM spfli INTO wa_final.
APPEND wa_sflight TO i_final.
ENDSELECT.
call screen 0100.

"*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module STATUS_0100 output.
SET PF-STATUS '100'.
* SET TITLEBAR 'xxx'.
endmodule.
" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module USER_COMMAND_0100 input.
IF ok_code EQ 'BACK'
OR ok_code EQ 'CANCEL'
OR ok_code EQ 'EXIT'.
LEAVE TO SCREEN 0.
ENDIF.
clear ok_code.
endmodule.
" USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*&
Module INITIALIZE_CONTAINER OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
module INITIALIZE_CONTAINER output.
IF gr_container IS INITIAL.
create object gr_container
exporting
container_name = 'CC_ALV'

exceptions
others = 1.
perform display_alv.
ENDIF.
endmodule.
" INITIALIZE_CONTAINER OUTPUT
*&---------------------------------------------------------------------*
*&
Form DISPLAY_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form DISPLAY_ALV .
data: l_icon type string,
l_text type string,
l_tooltip type string.
CALL METHOD cl_salv_table=>factory
exporting
r_container = gr_container
IMPORTING
r_salv_table = obj_alv
CHANGING
t_table
= i_final.
obj_display = obj_alv->get_display_settings( ).
"** SET ALL ALV Generic Buttons (Functions)
obj_functions = obj_alv->get_functions( ).
"obj_functions->set_all( ).
"** Set SELECTION MODE, CELL = Multiple select of
"** Column, rows, cell
obj_selections = obj_alv->get_selections( ).
obj_selections->set_selection_mode(
value = if_salv_c_selection_mode=>cell ).
obj_layout = obj_alv->get_layout( ).
*** Restrict None = User can save his own layout
obj_layout->set_save_restriction(
value = if_salv_c_layout=>restrict_none ).
lr_event = obj_alv->get_event( ).
l_icon = ICON_ORDER.
l_text = 'Resend'.
l_tooltip = 'Resend Line Items'.
obj_functions->add_function(
name = 'RESEND'
icon = l_icon
text = l_text
tooltip = l_tooltip
position = if_salv_c_function_position=>right_of_salv_functions
).
l_icon = ICON_SELECT_ALL.

l_text = 'Select All'.


l_tooltip = 'Select All'.
obj_functions->add_function(
name = 'SELECT'
icon = l_icon
text = l_text
tooltip = l_tooltip
position = if_salv_c_function_position=>right_of_salv_functions
).
l_icon = ICON_DESELECT_ALL.
l_text = 'Deselect All'.
l_tooltip = 'Deselect All'.
obj_functions->add_function(
name = 'DESELECT'
icon = l_icon
text = l_text
tooltip = l_tooltip
position = if_salv_c_function_position=>right_of_salv_functions
).
CREATE OBJECT lr_handler.
SET HANDLER:
lr_handler->on_added_function FOR lr_event,
lr_handler->on_link_click FOR lr_event.
" get alv property column
lr_columns = obj_alv->get_columns( ).
lr_column ?= lr_columns->get_column( columnname = 'CURRENCY' ).
lr_column->set_long_text( 'PESO' ).
"
"lr_column->set_visible( value = if_salv_c_bool_sap=>false ).
"lr_columns = obj_alv->get_columns( ).
lr_column ?= lr_columns->get_column( columnname = 'PRICE' ).
lr_column->set_visible( value = if_salv_c_bool_sap=>false ).
*
*

lr_column ?= lr_columns->get_column( columnname = 'SEATSMAX' ).


lr_column->set_visible( value = if_salv_c_bool_sap=>false ).
"lr_columns = obj_alv->get_columns( ).
lr_column ?= lr_columns->get_column( columnname = 'CHECKBOX' ).

lr_column->set_cell_type( if_salv_c_cell_type=>checkbox_hotspot ).
lr_column->set_output_length( 8 ).
" display length
lr_column->set_long_text( 'CHECKBOX' ).
" Display name in ALV o
utput
lr_columns->set_column_position( columnname = 'CHECKBOX' position = 1 ).
*
lr_sorts->add_sort(
*
columnname = 'CHECKBOX'
*
position = 1 ).
*** Set AUART as invisible
obj_alv->display( ).
endform.
" DISPLAY_ALV
*&---------------------------------------------------------------------*
*&
Form F_CHANGE_FLAG
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_ROW text
*----------------------------------------------------------------------*
form F_CHANGE_FLAG using
p_row.

FIELD-SYMBOLS: <lfs_data> TYPE t_sflight.


READ TABLE i_final ASSIGNING <lfs_data> INDEX p_row.
CHECK sy-subrc IS INITIAL.
IF <lfs_data>-checkBOX IS INITIAL.
<lfs_data>-checkBOX = 'X'.
ELSE.
CLEAR <lfs_data>-checkBOX.
ENDIF.
obj_alv->refresh( ).
" This is for refreshing after screen i.e. if yo
u click the unchecked checkbox, after you click it
endform.
" F_CHANGE_FLAG

Vous aimerez peut-être aussi