gpt4 book ai didi

abap - CL_SALV_TREE 类的 SET_DATA_ROW 方法是否存在错误?

转载 作者:行者123 更新时间:2023-12-02 10:17:58 24 4
gpt4 key购买 nike

我在使用分层 SALV(类CL_SALV_TREE)时发现了一些非常奇怪的行为。

如果我在创建节点实例后直接使用 set_data_row 方法,那么我会收到正确的层次结构。

REPORT zzy.

CLASS lcl_main DEFINITION FINAL CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS:
main
RAISING cx_salv_msg cx_salv_error.
ENDCLASS.

CLASS lcl_main IMPLEMENTATION.
METHOD main.
DATA: lt_data TYPE STANDARD TABLE OF t000.
cl_salv_tree=>factory(
IMPORTING
r_salv_tree = DATA(lo_salv_tree)
CHANGING
t_table = lt_data
).

DATA(lo_tree_settings) = lo_salv_tree->get_tree_settings( ).
lo_tree_settings->set_hierarchy_header( `Hierarchy` ).
lo_tree_settings->set_hierarchy_size( 30 ).

DATA(lo_nodes) = lo_salv_tree->get_nodes( ).
DATA(lo_root_node) = lo_nodes->add_node(
related_node = space
relationship = if_salv_c_node_relation=>last_child
data_row = VALUE t000( mandt = '100' )
collapsed_icon = '@3S\QStatus: Collapsed@'
expanded_icon = '@3T\QStatus: Expanded@'
row_style = if_salv_c_tree_style=>emphasized_positive
text = '100'
).
lo_root_node->set_data_row( VALUE t000( mandt = '100' ) ).
lo_root_node->get_hierarchy_item( )->set_icon( '@0V\QOK@' ).

DATA(lo_node1) = lo_nodes->add_node(
related_node = lo_root_node->get_key( )
relationship = cl_gui_column_tree=>relat_last_child
text = '200'
).
lo_node1->set_data_row( VALUE t000( mandt = '200' ) ).
DATA(lo_node2) = lo_nodes->add_node(
related_node = lo_node1->get_key( )
relationship = cl_gui_column_tree=>relat_last_child
text = '300'
).
lo_node2->set_data_row( VALUE t000( mandt = '300' ) ).

DATA(lo_node3) = lo_nodes->add_node(
related_node = lo_node2->get_key( )
relationship = cl_gui_column_tree=>relat_last_child
text = '400'
).
lo_node3->set_data_row( VALUE t000( mandt = '400' ) ).

lo_salv_tree->display( ).
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
TRY .
lcl_main=>main( ).
CATCH cx_salv_msg cx_salv_error.
ASSERT 0 = 1.
ENDTRY.

Correct hierarchy

但是,如果我在 main 方法末尾使用 set_data_row 方法,那么结果是完全意想不到的。

REPORT zzy.

CLASS lcl_main DEFINITION FINAL CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS:
main
RAISING cx_salv_msg cx_salv_error.
ENDCLASS.

CLASS lcl_main IMPLEMENTATION.
METHOD main.
DATA: lt_data TYPE STANDARD TABLE OF t000.
cl_salv_tree=>factory(
IMPORTING
r_salv_tree = DATA(lo_salv_tree)
CHANGING
t_table = lt_data
).

DATA(lo_tree_settings) = lo_salv_tree->get_tree_settings( ).
lo_tree_settings->set_hierarchy_header( `Hierarchy` ).
lo_tree_settings->set_hierarchy_size( 30 ).

DATA(lo_nodes) = lo_salv_tree->get_nodes( ).
DATA(lo_root_node) = lo_nodes->add_node(
related_node = space
relationship = if_salv_c_node_relation=>last_child
data_row = VALUE t000( mandt = '100' )
collapsed_icon = '@3S\QStatus: Collapsed@'
expanded_icon = '@3T\QStatus: Expanded@'
row_style = if_salv_c_tree_style=>emphasized_positive
text = '100'
).
lo_root_node->get_hierarchy_item( )->set_icon( '@0V\QOK@' ).

DATA(lo_node1) = lo_nodes->add_node(
related_node = lo_root_node->get_key( )
relationship = cl_gui_column_tree=>relat_last_child
text = '200'
).

DATA(lo_node2) = lo_nodes->add_node(
related_node = lo_node1->get_key( )
relationship = cl_gui_column_tree=>relat_last_child
text = '300'
).

DATA(lo_node3) = lo_nodes->add_node(
related_node = lo_node2->get_key( )
relationship = cl_gui_column_tree=>relat_last_child
text = '400'
).

lo_root_node->set_data_row( VALUE t000( mandt = '100' ) ).
lo_node1->set_data_row( VALUE t000( mandt = '200' ) ).
lo_node2->set_data_row( VALUE t000( mandt = '300' ) ).
lo_node3->set_data_row( VALUE t000( mandt = '400' ) ).

lo_salv_tree->display( ).
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
TRY .
lcl_main=>main( ).
CATCH cx_salv_msg cx_salv_error.
ASSERT 0 = 1.
ENDTRY.

Incorrect hierarchy

这是该组件中的错误吗?我找不到任何文档可以解释这种奇怪的行为。

最佳答案

通过调用set_data_row方法,您将覆盖所有原始数据,包括子关系。

在第一个示例中,您始终先设置mandt,然后再添加节点。如果你反过来做,你也会得到“一层深”的树。

关于abap - CL_SALV_TREE 类的 SET_DATA_ROW 方法是否存在错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36813241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com