gpt4 book ai didi

abap - 是否可以在不复制 GUI 状态的情况下向 CL_SALV_TREE 添加用户定义的函数?

转载 作者:行者123 更新时间:2023-12-02 00:54:40 24 4
gpt4 key购买 nike

是否可以将用户定义的函数添加到 CL_SALV_TREE 实例,而不将 GUI 状态复制到使用该实例的报表?

我想做的是使用 add_function 方法添加自定义函数。

REPORT zzy.

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

CLASS lcl_main IMPLEMENTATION.
METHOD main.
DATA: lt_table TYPE STANDARD TABLE OF t000.
TRY .
cl_salv_tree=>factory(
IMPORTING
r_salv_tree = DATA(lo_salv_tree)
CHANGING
t_table = lt_table
).
DATA(lo_salv_functions) = lo_salv_tree->get_functions( ).
lo_salv_functions->add_function(
name = 'EXPORT_TO_EXCEL'
icon = '@J2@'
tooltip = 'Export as Excel'
position = if_salv_c_function_position=>right_of_salv_functions
).
lo_salv_functions->set_all( abap_true ).

lo_salv_tree->display( ).
CATCH cx_salv_error.
ASSERT 0 = 1.
ENDTRY.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
lcl_main=>main( ).

但是该按钮不会出现。

No button

我记得前段时间我尝试使用 CL_SALV_TABLE 执行此操作,但在使用 add_function 时出现了明确的异常。

我当时尝试的是。

REPORT zzy.

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

CLASS lcl_main IMPLEMENTATION.
METHOD main.
DATA: lt_table TYPE STANDARD TABLE OF t000.
TRY .
cl_salv_table=>factory(
IMPORTING
r_salv_table = DATA(lo_salv_table)
CHANGING
t_table = lt_table
).
DATA(lo_salv_functions) = lo_salv_table->get_functions( ).
lo_salv_functions->add_function(
name = 'EXPORT_TO_EXCEL'
icon = '@J2@'
tooltip = 'Export as Excel file'
position = if_salv_c_function_position=>right_of_salv_functions
).
lo_salv_functions->set_all( abap_true ).

lo_salv_table->display( ).
CATCH cx_salv_error.
ASSERT 0 = 1.
ENDTRY.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
lcl_main=>main( ).

它以未处理的异常 CX_SALV_METHOD_NOT_SUPPORTED 引起的短路转储结束。我在SAP标准代码中看到的是

if lr_controller->r_model->get_display_object( )
ne IF_SALV_C_TABLE_OBJECTS=>GRID
and lr_controller->r_model->get_display_object( )
ne IF_SALV_C_TABLE_OBJECTS=>TREE.
text = text-001.
l_name = name.
raise exception type CX_SALV_METHOD_NOT_SUPPORTED
exporting class = 'CL_SALV_FUNCTIONS'
method = 'ENABLE_FUNCTION'
object = l_name
key = text.
endif.

从这段代码中,我们可以假设可以使用 add_function 方法为对象 IF_SALV_C_TABLE_OBJECTS=>TREE 添加一个新函数。

到目前为止,我使用了以下解决方法。

REPORT zzy.

CLASS lcl_controller DEFINITION FINAL.
PUBLIC SECTION.
INTERFACES:
if_salv_csqt_content_manager.
METHODS:
constructor.
DATA:
mo_salv_tree TYPE REF TO cl_salv_tree,
mt_table TYPE STANDARD TABLE OF t000.
ENDCLASS.

CLASS lcl_controller IMPLEMENTATION.
METHOD constructor.
CALL FUNCTION 'SALV_CSQT_CREATE_CONTAINER'
EXPORTING
r_content_manager = me
title = 'Workaround'.
ENDMETHOD.

METHOD if_salv_csqt_content_manager~fill_container_content.
TRY .
cl_salv_tree=>factory(
EXPORTING
r_container = r_container
IMPORTING
r_salv_tree = DATA(mo_salv_tree)
CHANGING
t_table = mt_table
).
DATA(lo_tree_settings) = mo_salv_tree->get_tree_settings( ).
lo_tree_settings->set_hierarchy_header( `Hierarchy` ).
lo_tree_settings->set_hierarchy_size( 30 ).
lo_tree_settings->set_header( |{ sy-title }| ).

DATA(lo_salv_functions) = mo_salv_tree->get_functions( ).
lo_salv_functions->add_function(
name = 'EXPORT_TO_EXCEL'
icon = '@J2@'
tooltip = 'Export as Excel file'
position = if_salv_c_function_position=>right_of_salv_functions
).
lo_salv_functions->set_all( abap_true ).

DATA(lo_salv_nodes) = mo_salv_tree->get_nodes( ).
DATA(lo_root) = lo_salv_nodes->add_node(
related_node = space
relationship = if_salv_c_node_relation=>last_child
data_row = VALUE t000( mandt = '100' )
text = `Test`
).

lo_salv_nodes->add_node(
related_node = lo_root->get_key( )
relationship = cl_gui_column_tree=>relat_last_child
data_row = VALUE t000( mandt = '200' )
text = `Test2`
).

mo_salv_tree->display( ).
CATCH cx_salv_error.
ASSERT 0 = 1.
ENDTRY.
ENDMETHOD.
ENDCLASS.

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

CLASS lcl_main IMPLEMENTATION.
METHOD main.
DATA(lo_controller) = NEW lcl_controller( ).
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
lcl_main=>main( ).

不幸的是,在这种情况下,按钮出现在不同的位置,直接在树之前,而不是在状态栏中。

Buttons not in the status bar

最佳答案

简短的回答 - 不,你不能,你需要一个 GUI 状态 (CUAD)。您可以在运行时隐藏函数,但不能在运行时添加新函数。

关于abap - 是否可以在不复制 GUI 状态的情况下向 CL_SALV_TREE 添加用户定义的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36893024/

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