2016-04-27 53 views
4

是否可以將用戶定義的函數添加到實例CL_SALV_TREE而不將GUI狀態複製到使用此實例的報表中?是否可以在不復制GUI狀態的情況下將用戶定義的函數添加到CL_SALV_TREE中?

我想要做的是用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 = '@[email protected]' 
     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 = '@[email protected]' 
     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 = '@[email protected]' 
     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

回答

2

簡短的回答 - 不,你不能,你需要一個GUI狀態(CUAD)。您可以在運行時隱藏函數,但不能在運行時添加新函數。

相關問題