Code: Alles auswählen.
class lcl_tree_events definition deferred.
data:
flights type standard table of sflight,
carriers type standard table of scarr,
tree_control type ref to cl_gui_custom_container,
tree type ref to cl_simple_tree_model,
tree_events type ref to lcl_tree_events,
events type cntl_simple_events.
field-symbols:
<flight> type sflight,
<carrier> type scarr.
class lcl_tree_events definition.
public section.
methods:
on_double_click
for event node_double_click
of cl_simple_tree_model ##NEEDED
importing sender node_key.
endclass.
select * from sflight into table flights.
select * from scarr into table carriers.
create object tree_control
exporting
container_name = 'TREE_CONTAINER'.
create object tree
exporting
node_selection_mode = cl_list_tree_model=>node_sel_mode_single
hide_selection = abap_false.
tree->create_tree_control(
exporting
parent = tree_control
).
append initial line to events assigning field-symbol(<event>).
<event>-eventid = tree->eventid_node_double_click.
<event>-appl_event = abap_true.
tree->set_registered_events( events ).
create object tree_events.
set handler tree_events->on_double_click for tree.
loop at carriers assigning <carrier>.
tree->add_node(
exporting
node_key = 'SCARR' && <carrier>-carrid
isfolder = abap_true
image = '@3P@'
text = 'Carrier'
exceptions
others = 1
).
loop at flights assigning <flight>
where carrid = <carrier>-carrid.
tree->add_node(
exporting
node_key = 'SFLIGHT' && <flight>-carrid && <flight>-connid && <flight>-fldate
isfolder = abap_true
relative_node_key = 'SCARR' && <carrier>-carrid
relationship = cl_simple_tree_model=>relat_last_child
image = '@3P@'
text = 'Fluege'
exceptions
others = 1
).
endloop.
endloop.
call screen 0200.
class lcl_tree_events implementation.
method on_double_click.
types:
begin of fieldline,
fieldname type fieldname,
value type string,
end of fieldline.
data:
fieldname type abap_abstypename,
struct type ref to cl_abap_structdescr,
components type abap_compdescr_tab,
fieldtab type standard table of fieldline,
rec_list type ref to cl_salv_table,
rec_container type ref to cl_gui_custom_container,
tree_container type ref to cl_gui_custom_container,
container_name type c length 50.
field-symbols:
<record> type any,
<feld> type any,
<component> like line of components,
<fieldline> type fieldline.
case node_key(4).
when 'SFLI'.
read table flights assigning <record>
with key carrid = node_key+7(2)
connid = node_key+9(4)
fldate = node_key+13(8).
when 'SCAR'.
read table carriers assigning <record>
with key carrid = node_key+5(2).
when others.
endcase.
do.
assign component sy-index of structure <record> to <feld>.
if sy-subrc ne 0.
exit.
endif.
if <feld> is initial.
continue.
endif.
fieldname = cl_abap_datadescr=>describe_by_data( p_data = <feld> )->absolute_name.
shift fieldname:
up to '=',
by 1 places.
struct ?= cl_abap_structdescr=>describe_by_data( p_data = <record> ).
components = struct->components.
read table components
assigning <component>
index sy-index.
" write fieldname and fieldvalue to SALV table
append initial line to fieldtab assigning <fieldline>.
<fieldline>-fieldname = <component>-name.
<fieldline>-value = <feld>.
enddo.
if rec_container is not bound.
if cl_salv_table=>is_offline( ) eq if_salv_c_bool_sap=>false.
create object rec_container
exporting
container_name = 'RECORD_CONTAINER'
repid = sy-repid
dynnr = sy-dynnr.
endif.
endif.
if rec_list is not bound.
try.
cl_salv_table=>factory(
exporting
r_container = rec_container
container_name = conv #( container_name )
importing
r_salv_table = rec_list
changing
t_table = fieldtab ).
catch cx_salv_msg. "#EC NO_HANDLER
endtry.
endif.
rec_list->display( ).
endmethod.
endclass.
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
ralf.wenzel
Ich habe das Problem schon wieder - jetzt habe ich (weil es eine Klasse ist und kein Programm), die beiden als Klassenattribute deklariert. Kann es sein, dass das nicht reicht?ewx hat geschrieben:Du darfst REC_LIST nicht lokal definieren!
/EDIT: Und FIELDTAB auch nicht.