Posted: Mon Nov 09, 2009 4:34 pm Post subject: ALV Grid Demo(OO ALV)
Code:
report zbobo_alv_grid_demo .
types: begin of rt_tab,
excp(1) type c,
ebeln type ebeln,
ebelp type ebelp,
matnr type matnr,
bukrs type bukrs,
menge type bstmg,
meins type bstme,
rowc(4) type c,
cc type lvc_t_scol,
detailinit type c,
end of rt_tab.
define set_text.
if &1 is initial.
ls = 'Off'.
else.
ls = 'On'.
endif.
if &3 is initial.
ls = 'Change'.
endif.
call method set_text
exporting:
n = &2 i = 'C2' t = &1 f = &3,
n = &2 i = 'C3' t = ls f = &3.
end-of-definition.
define add_item_detail.
call method add_item_detail
exporting node_key = &1
item_name = 'C1'
class = 2
text = &4.
call method add_item_detail
exporting node_key = &1
item_name = 'C2'
class = 2
text = 'init'.
call method add_item_detail
exporting node_key = &1
item_name = 'C3'
class = &2
text = &3.
end-of-definition.
define refresh_display.
concatenate 'LAYOUT-' &1 into ls.
assign (ls) to <fs>.
if n = &1.
<fs> = c.
call method ref_alv->set_frontend_layout
exporting
is_layout = layout.
call method ref_alv->refresh_table_display.
endif.
end-of-definition.
define set_when.
when &1.
method = 'LAY_CHECKBOX'.
if not checked is initial.
call method set_text
exporting n = &1 i = 'C3' t = 'On' f = 'X'.
call method me->(method)
exporting n = &1 i = 'C3' c = checked.
else.
call method set_text
exporting n = &1 i = 'C3' t = 'Off' f = 'X'.
call method me->(method)
exporting n = &1 i = 'C3' c = checked.
endif.
end-of-definition.
define set_checkbox.
concatenate 'LAYOUT-' &1 into ls.
assign ls to <fs>.
if n = &1.
refresh_display <fs>.
endif.
end-of-definition.
define set_node_when.
when &1.
flag = &1.
length = &2.
call screen 9100 starting at 30 3
ending at 74 13.
if flag = 'Y'.
concatenate 'LAYOUT-' &1 into ls.
assign (ls) to <fs>.
read table is into s index 1.
<fs> = s.
call method ref_alv->set_frontend_layout
exporting
is_layout = layout.
call method ref_alv->refresh_table_display .
endif.
end-of-definition.
define set_flag_when.
when &1.
if text is initial.
create object text
exporting
MAX_NUMBER_CHARS = length
parent = con .
call method text->set_statusbar_mode
EXPORTING
STATUSBAR_MODE = 0.
call method text->set_toolbar_mode
EXPORTING
TOOLBAR_MODE = 0.
else.
call method text->free.
create object text
exporting
MAX_NUMBER_CHARS = length
parent = con .
call method text->set_statusbar_mode
EXPORTING
STATUSBAR_MODE = 0.
call method text->set_toolbar_mode
EXPORTING
TOOLBAR_MODE = 0.
endif.
end-of-definition.
data: con type ref to cl_gui_custom_container.
data: text type ref to cl_gui_textedit.
data: s(255) type c.
data: is like standard table of s.
data: modif type i.
data: flag(20) type c,
length type i.
*---------------------------------------------------------------------*
* CLASS zcl_init_screen DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class zcl_init_screen definition.
public section.
data:
sp_h type ref to cl_gui_splitter_container.
methods:
constructor,
free,
get_alv_con
returning value(c_alv) type ref to cl_gui_container,
get_tree_con
returning value(c_tree) type ref to cl_gui_container.
endclass.
*---------------------------------------------------------------------*
* CLASS zcl_event DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class zcl_event definition.
public section.
data:
event type cntl_simple_event,
events type cntl_simple_events.
data:
layout type lvc_s_layo.
methods:
constructor
importing alv type ref to object
tree type ref to object,
colu_button_click for event button_click
of cl_gui_column_tree
importing node_key item_name sender,
colu_checkbox_change for event checkbox_change
of cl_gui_column_tree
importing node_key item_name checked,
alv_HOTSPOT_CLICK for event HOTSPOT_CLICK
of cl_gui_alv_grid
importing E_ROW_ID E_COLUMN_ID ES_ROW_NO,
add_colu_events,
add_alv_events,
set_handler.
private section.
data:
ref_alv type ref to cl_gui_alv_grid,
ref_tree type ref to cl_gui_column_tree,
ref_colu type ref to cl_gui_column_tree.
methods:
set_text
importing n type any i type any t type any f type c,
lay_checkbox
importing n type any optional
i type any optional
c type c optional.
endclass.
*---------------------------------------------------------------------*
* CLASS zcl_event IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class zcl_event implementation.
method constructor.
if not alv is initial.
ref_alv ?= alv.
endif.
if not tree is initial.
ref_tree ?= tree.
endif.
endmethod.
method alv_HOTSPOT_CLICK.
break-point.
endmethod.
method colu_button_click.
data: ls(30) type c.
data: ltab type rt_tab.
field-symbols: <fs> type any.
case node_key.
when 'F'.
if item_name = 'C2'.
elseif item_name = 'C3'.
endif.
when 'L'.
if item_name = 'C2'.
call method ref_alv->get_frontend_layout
importing
es_layout = layout.
refresh_display:
'CWIDTH_OPT',
'SMALLTITLE',
'NO_HEADERS',
'NO_HGRIDLN',
'NO_MERGING',
'NO_ROWMARK',
'NO_TOOLBAR',
'NO_VGRIDLN',
'EXCP_CONDS',
'EXCP_LED',
'ZEBRA',
'NO_TOTARR',
'NO_TOTEXP',
'NO_TOTLINE',
'NUMC_TOTAL',
'DETAILINIT',
'TOTALS_BEF',
'KEYHOT',
'SGL_CLK_HD',
'DETAILINIT'.
endmethod.
method set_text.
call method ref_tree->item_set_text
exporting
node_key = n
item_name = i
text = t .
check i = 'C3' and f = 'X'.
call method ref_tree->item_set_editable
exporting
node_key = n
item_name = i
editable = 'X'.
endmethod.
method add_alv_events.
* clear:event,events.
* event-eventid = CL_GUI_ALV_GRID=>eventid_link_click.
* event-appl_event = 'X'. "
* append event to events.
endmethod.
method add_colu_events.
clear:event,events.
event-eventid = cl_gui_column_tree=>eventid_link_click.
event-appl_event = 'X'. "
append event to events.
event-eventid = cl_gui_column_tree=>eventid_button_click.
event-appl_event = 'X'.
append event to events.
event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
event-appl_event = 'X'.
append event to events.
endmethod.
method set_handler.
set handler me->colu_button_click for ref_tree.
set handler me->colu_checkbox_change for ref_tree.
endmethod.
endclass.
*---------------------------------------------------------------------*
* CLASS zcl_tree DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class zcl_tree definition.
public section.
data:
l_node_t type treev_ntab,
l_item_t type standard table of mtreeitm with default key,
con type ref to cl_gui_container,
ref_colu type ref to cl_gui_column_tree.
methods:
constructor
importing ref_init type ref to zcl_init_screen,
add_data,
show_data,
free.
private section.
methods:
add_node,
add_item,
add_node_detail
importing node_key type tv_nodekey
relatkey type tv_nodekey optional
relatship type int4 optional
isfolder type as4flag optional,
add_item_detail
importing node_key type tv_nodekey
item_name type tv_itmname
class type int4 optional
text type scrpcha72
t_image type tv_image optional
editable type as4flag optional.
endclass.
*---------------------------------------------------------------------*
* CLASS zcl_tree IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class zcl_tree implementation.
method constructor.
data: hierarchy_header type treev_hhdr.
*---------------------------------------------------------------------*
* CLASS zalv_grid DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class zalv_grid definition inheriting from cl_gui_alv_grid.
public section.
methods:
constructor
importing par type ref to cl_gui_container.
endclass.
*---------------------------------------------------------------------*
* CLASS zalv_grid IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class zalv_grid implementation.
method constructor.
call method super->constructor
exporting i_parent = par.
endmethod.
endclass.
*---------------------------------------------------------------------*
* CLASS zcl_alv DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class zcl_alv definition.
public section.
data: it_tab type standard table of rt_tab,
st_tab type rt_tab.
data:
con type ref to cl_gui_container,
ref_alv type ref to zalv_grid.
data:
it_fieldcat type lvc_t_fcat,
fieldcat type lvc_s_fcat,
layout type lvc_s_layo.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.