Code: Alles auswählen.
DATA: wa_sflight TYPE sflight,
l_node_text TYPE lvc_value,
ls_out_line TYPE sflight,
relat_key TYPE lvc_nkey,
node_key TYPE lvc_nkey,
lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi,
r_gui_alvtree TYPE REF TO cl_gui_alv_tree,
l_node_text2 TYPE lvc_value,
node2_key TYPE lvc_nkey.
LOOP AT gt_sflight INTO wa_sflight.
l_node_text = wa_sflight-connid.
ON CHANGE OF wa_sflight-connid.
PERFORM add_job USING ls_out_line
relat_key
l_node_text
CHANGING node_key.
ENDON.
ls_out_line-connid = wa_sflight-connid.
ls_item_layout-t_image = icon_order.
ls_item_layout-style = cl_gui_column_tree=>style_intensified.
ls_item_layout-fieldname = r_gui_alvtree->c_hierarchy_column_name.
APPEND ls_item_layout TO lt_item_layout.
PERFORM add_node USING ls_out_line
node_key
l_node_text2
CHANGING node2_key.
ENDLOOP.
Code: Alles auswählen.
FORM add_job USING p_ls_out_line
p_relat_key
p_l_node_text
CHANGING p_node_key.
DATA: r_gui_alvtree TYPE REF TO cl_gui_alv_tree.
CALL METHOD r_gui_alvtree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = p_l_node_text
is_outtab_line = p_ls_out_line
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_job
*&---------------------------------------------------------------------*
*& Form add_node
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_OUT_LINE text
* -->P_NODE_KEY text
* -->P_L_NODE_TEXT2 text
* <--P_NODE2_KEY text
*----------------------------------------------------------------------*
FORM add_node USING p_ls_out_line
p_node_key
p_l_node_text2
CHANGING p_node2_key.
CALL METHOD r_gui_alvtree->add_node
EXPORTING
i_relat_node_key = p_node_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = p_l_node_text2
is_outtab_line = p_ls_out_line
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node2_key.
ENDFORM. " add_node
So behandel ich den FieldcatalogZugriff über 'NULL' Objektreferenz nicht möglich.
Es ist eine Ausnahme aufgetreten, die weiter unten näher erläutert wird
Die Ausnahme, der die Klasse 'CX_SY_REF_IS_INITIAL' zugeordnet ist,
wurde in der Prozedur "ADD_JOB" "(FORM)" weder abgefangen,
noch durch eine RAISING-Klausel propagiert.
Da der Aufrufer der Prozedur nicht mit dem Auftreten der Ausnahme
rechnen konnte, wurde das laufende Programm abgebrochen.
Der Grund für die Ausnahme ist:
Es wurde versucht mit einer 'NULL' Objektreferenz (zeigt auf 'nichts')
auf eine Komponente zuzugreifen (Variable: "R_GUI_ALVTREE").
Eine Objektreferenz muß auf ein Objekt (eine Instanz einer Klasse)
zeigen, bevor man sie zum Zugriff auf Komponenten nutzen kann.
Entweder die Referenz wurde noch nie gesetzt, oder sie wurde mit
einer CLEAR Anweisung auf 'NULL' gesetzt.
Code: Alles auswählen.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'ZJOB'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = p_it_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Code: Alles auswählen.
PERFORM add_a_folder USING node_text
CHANGING l_top_key.
PERFORM add_a_node USING <alv> l_srt01_key l_node_text
CHANGING l_pos_key.
----------------------
FORM add_a_folder USING p_node_text TYPE lvc_value
CHANGING p_new_key TYPE lvc_nkey.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = ''
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = p_node_text
IMPORTING
e_new_node_key = p_new_key.
ENDFORM. "add_a_folder
-----------
FORM add_a_node USING p_it TYPE typ_alv
p_relat_key TYPE lvc_nkey
p_node_text TYPE lvc_value
CHANGING p_new_key TYPE lvc_nkey.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = p_node_text
is_outtab_line = p_it
IMPORTING
e_new_node_key = p_new_key.
ENDFORM. "add_a_node
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Module create_alv_tree OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE create_alv_tree OUTPUT.
data: gt_tbtco type table of tbtco,
wa_tbtco type tbtco.
* create tree
CREATE OBJECT ref_tree
EXPORTING
parent = ref_top_tree
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
EXCEPTIONS
lifetime_error = 1
cntl_system_error = 2
create_error = 3
failed = 4
illegal_node_selection_mode = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* The following function module generates a fieldcatalog according
* to a given structure.
PERFORM create_field_catalog CHANGING gt_fieldcat_tree.
* CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
* EXPORTING
* i_structure_name = 'SFLIGHT'
* i_client_never_display = 'X'
* i_bypassing_buffer = 'X'
* CHANGING
* ct_fieldcat = gt_fieldcat_tree.
* create header
lv_treev_hhdr-t_image = icon_delivery.
lv_treev_hhdr-heading = 'Jobname'.
lv_treev_hhdr-tooltip = 'Jobname'.
lv_treev_hhdr-width = 25.
lv_treev_hhdr-width_pix = 'X'..
* display alv tree
* CALL METHOD r_gui_alvtree->set_table_for_first_display(
ref_tree->set_table_for_first_display(
EXPORTING
is_hierarchy_header = lv_treev_hhdr
CHANGING
it_outtab = gt_tbtco2
it_fieldcatalog = gt_fieldcat_tree ).
************************************************************************
* 3. Knoten erstellen (Jobname)
************************************************************************
select * from tbtco into table gt_tbtco where sdluname = lp_user.
* LOOP AT gt_sflight INTO wa_sflight.
LOOP AT gt_tbtco INTO wa_tbtco.
l_node_text = wa_tbtco-jobname.
ON CHANGE OF wa_tbtco-jobname.
PERFORM add_job USING ls_out_line
relat_key
l_node_text
CHANGING node_key.
ENDON.
ls_item_layout-t_image = icon_order.
ls_item_layout-style = cl_gui_column_tree=>style_intensified.
ls_item_layout-fieldname = ref_tree->c_hierarchy_column_name.
APPEND ls_item_layout TO lt_item_layout.
*
************************************************************************
* 4. Knoten erstellen (Step)
************************************************************************
l_node_text2 = wa_tbtco-jobname.
PERFORM add_node USING ls_out_line
node_key
l_node_text2
CHANGING node2_key.
ENDLOOP.
CALL METHOD REF_TREE->FRONTEND_UPDATE
.
ENDMODULE. " create_alv_tree OUTPUT