cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete a dynamically created node using Code

Former Member
0 Kudos
385

Hello All,

I have created a node for filling the ALV dynamically at the press of a button based on the values the user selects.

If I again click the button it says the child node already exists.

How to resolve this.

How can I delete this node.

              • Next, validate which fields you will use as ALV columns *******

DATA: ls_component TYPE cl_abap_structdescr=>component,

lr_type TYPE REF TO cl_abap_datadescr,

lt_components TYPE cl_abap_structdescr=>component_table.

IF stru_param-carrid = 'X'.

lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_CARR_ID' ).

ls_component-name = 'CARRID'.

ls_component-type = lr_type .

APPEND ls_component TO lt_components.

ENDIF.

IF stru_param-connid = 'X'.

lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_CONN_ID' ).

ls_component-name = 'CONNID'.

ls_component-type = lr_type .

APPEND ls_component TO lt_components.

ENDIF.

IF stru_param-fldate = 'X'.

lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_DATE' ).

ls_component-name = 'FLDATE'.

ls_component-type = lr_type .

APPEND ls_component TO lt_components.

ENDIF.

IF stru_param-price = 'X'.

lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_PRICE' ).

ls_component-name = 'PRICE'.

ls_component-type = lr_type .

APPEND ls_component TO lt_components.

ENDIF.

IF stru_param-currency = 'X'.

lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_CURRCODE' ).

ls_component-name = 'CURRENCY'.

ls_component-type = lr_type .

APPEND ls_component TO lt_components.

ENDIF.

              • Next, create a new structure and assign it to a new dynamic

              • context node

DATA: lr_root_info TYPE REF TO if_wd_context_node_info ,

lr_node_info TYPE REF TO if_wd_context_node_info,

lr_structdescr TYPE REF TO cl_abap_structdescr.

call method cl_abap_structdescr=>create

exporting

p_components = lt_components

receiving

p_result = lr_structdescr.

  • Get context node info

lr_root_info = wd_context->get_node_info( ).

  • Generate new node with the dynamic structure

CALL METHOD lr_root_info->add_new_child_node

EXPORTING

name = 'DATA'

is_initialize_lead_selection = abap_false

static_element_rtti = lr_structdescr

is_static = abap_false

RECEIVING

child_node_info = lr_node_info.

  • get instance of new node

DATA: dyn_node TYPE REF TO if_wd_context_node.

dyn_node = wd_context->get_child_node( name = 'DATA' ).

              • Last, Get reference to model *******

DATA: lo_interfacecontroller type ref to iwci_salv_wd_table.

lo_interfacecontroller = wd_this->wd_cpifc_alv( ).

lo_interfacecontroller->set_data( dyn_node ).

View Entire Topic
laurent_touillaud
Contributor
0 Kudos

Hi WDA fans,

Just to complete the post for people who want an additional exemple code when you must do your treatment only in the modifyview method -> creating and deleting nodes and UI dynamic table

ALL IN THE MODIFYVIEW METHOD :

* Delete the UI element content when nodes have been refreshed by a reset/refresh method

TRY.

lr_node = wd_context->get_child_node( 'MY_NODE1' ).

CATCH cx_wd_context. "not yet created

lr_sumpack_cont ?= view->get_element( 'PACKSUMMARIES' ).

lr_sumpack_cont->remove_all_children( ).

ENDTRY.

DATA : l_node TYPE REF TO if_wd_context_node,

l_node_2 TYPE REF TO if_wd_context_node,

l_node_info TYPE REF TO if_wd_context_node_info,

l_table TYPE REF TO cl_wd_table,

nd_list TYPE wdr_context_child_map,

wa_list TYPE wdr_context_child.

* Create a dynamic table of a known structure

DATA: node_info TYPE REF TO if_wd_context_node_info,

comp_tab TYPE cl_abap_structdescr=>component_table,

comp LIKE LINE OF comp_tab,

my_table TYPE REF TO data,

my_row TYPE REF TO data.

FIELD-SYMBOLS: <table> TYPE table,

<row> TYPE data,

<flight> TYPE sflight.

DATA: lo_struct TYPE REF TO cl_abap_structdescr,

lt_comp TYPE cl_abap_structdescr=>component_table,

lo_run_st TYPE REF TO cl_abap_structdescr,

lo_run_tt TYPE REF TO cl_abap_tabledescr,

lo_struc TYPE REF TO data,

lo_ttype TYPE REF TO data.

* fill new node

DATA: ls_gap TYPE zsnc_packing_gap_st.

DATA: lv_node TYPE string.

DATA: lv_table TYPE string.

DATA: lv_numi TYPE i.

DATA: lv_num(1).

DATA: lv_table_header TYPE string.

DATA: lo_table TYPE REF TO cl_wd_table.

DATA: lo_caption TYPE REF TO cl_wd_caption.

DATA: lt_attributes TYPE wdr_context_attr_info_map.

DATA: ls_deltol TYPE zsnc_del_toleran.

DATA: lv_undertol TYPE string.

DATA: lv_lines TYPE i.

FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,

<fs_line> TYPE any,

<fs_node> TYPE REF TO if_wd_context_node.

* principal table

IF wd_this->lt_gap[] IS NOT INITIAL.

lo_struct ?= cl_abap_structdescr=>describe_by_name( 'ZSNC_PACK_SUMMARY' ).

lt_comp = lo_struct->get_components( ).

lo_run_st = cl_abap_structdescr=>create( lt_comp ).

lo_run_tt ?= cl_abap_tabledescr=>create( p_line_type = lo_run_st ).

* create table for each stock category

lr_sumpack_cont ?= view->get_element( 'PACKSUMMARIES' ).

CREATE DATA lo_ttype TYPE HANDLE lo_run_tt.

ASSIGN lo_ttype->* TO <fs_table>.

CREATE DATA lo_struc TYPE HANDLE lo_run_st.

ASSIGN lo_struc->* TO <fs_line>.

LOOP AT wd_this->lt_gap INTO ls_gap.

MOVE-CORRESPONDING ls_gap TO <fs_line>.

APPEND <fs_line> TO <fs_table>.

AT END OF stock_category. "create one table by stock category

* handle runtime data type by means of generic variables

ADD 1 TO lv_numi. lv_num = lv_numi.

CONCATENATE 'MY_NODE' lv_num INTO lv_node.

CONCATENATE 'MY_TABLE' lv_num INTO lv_table.

* now created the node

TRY.

l_node = wd_context->get_child_node( lv_node ).

CATCH cx_wd_context. "not yet created

node_info = wd_context->get_node_info( ).

l_node_info = node_info->add_new_child_node(

name = lv_node

is_mandatory = abap_true

is_multiple = abap_true

static_element_rtti = lo_run_st

is_initialize_lead_selection = abap_false

is_static = abap_false ).

* attributes = lt_attributes ).

* bind table to node

l_node = wd_context->get_child_node( lv_node ).

l_node->bind_table( <fs_table> )."( new_items = <fs_table> set_initial_elements = abap_true ).

* create the ui element table

l_node_2 = wd_context->get_child_node( lv_node ).

cl_wd_dynamic_tool=>create_table_from_node(

EXPORTING

ui_parent = lr_sumpack_cont

table_id = lv_table

node = l_node_2

RECEIVING

table = lo_table ).

IF lo_table IS BOUND.

CLEAR lv_undertol.

READ TABLE wd_this->lt_deltol INTO ls_deltol

WITH KEY stock_category = ls_gap-stock_category.

IF sy-subrc IS INITIAL.

lv_undertol = ls_deltol-under_tol_perc.

ELSE.

READ TABLE wd_this->lt_deltol INTO ls_deltol

WITH KEY stock_category = space.

IF sy-subrc IS INITIAL.

lv_undertol = ls_deltol-under_tol_perc.

ENDIF.

ENDIF.

CONCATENATE 'PACKING SUMMARY' ls_gap-stock_category lv_undertol

INTO lv_table_header SEPARATED BY space.

lo_caption = cl_wd_caption=>new_caption( text = lv_table_header ).

lo_table->set_header( lo_caption ).

* set visible rows

DESCRIBE TABLE <fs_table> LINES lv_lines.

lo_table->set_visible_row_count( value = lv_lines ).

ENDIF.

FREE : <fs_table>, <fs_line>.

ENDTRY.

ENDAT.

ENDLOOP.

ENDIF.

Reset/refresh method :

node_info = wd_context->get_node_info( ).

DO.

ADD 1 TO lv_numi. lv_num = lv_numi.

CONCATENATE 'MY_NODE' lv_num INTO lv_node.

CONCATENATE 'MY_TABLE' lv_num INTO lv_table.

TRY.

l_node = wd_context->get_child_node( lv_node ).

CATCH cx_wd_context.

EXIT.

ENDTRY.

node_info = node_info->get_child_node( lv_node ). "node to be removed

node_info->remove_dynamic_attributes( ).

node_info = node_info->get_parent( ).

node_info->remove_child_node( lv_node ).

ENDDO.