ABAP: Web Dynpro – dynamic context & UI manipulation

A good example of the dynamic modifications can be viewed via Web Dynpro componentĀ DEMODYNAMIC.

Creating new context node
METHOD handlefrom_select_view .

* Get information about selected table
  DATA: lo_nd_tabledata TYPE REF TO if_wd_context_node,
        lo_el_tabledata TYPE REF TO if_wd_context_element,
        ls_tabledata TYPE wd_this->element_tabledata,
        lv_tabname TYPE string.
* navigate from  to  via lead selection
  lo_nd_tabledata = wd_context->get_child_node( name = wd_this->wdctx_tabledata ).
* get element via lead selection
  lo_el_tabledata = lo_nd_tabledata->get_element( ).
* get single attribute
  lo_el_tabledata->get_attribute(
    EXPORTING
      name =  `TABNAME`
    IMPORTING
      value = lv_tabname ).
  TRANSLATE lv_tabname TO UPPER CASE.

* build new context data
  DATA: lo_nd_info_root     TYPE REF TO if_wd_context_node_info,
        lo_nd_info_dbtb     TYPE REF TO if_wd_context_node_info.

  lo_nd_info_root = wd_context->get_node_info( ).
  lo_nd_info_dbtb = lo_nd_info_root->add_new_child_node(
                      name                   = 'DB_TABLE'
                      static_element_type    = lv_tabname
                      is_mandatory           = abap_false
                      is_mandatory_selection = abap_false
                      is_multiple            = abap_true ).

* create a reference to data table
  DATA: lr_db_tab TYPE REF TO data.
  FIELD-SYMBOLS: <fs_db_tab> TYPE ANY TABLE.
  CREATE DATA lr_db_tab TYPE TABLE OF (lv_tabname).
  ASSIGN lr_db_tab->* TO <fs_db_tab>.

* read contents of the database
  SELECT * FROM (lv_tabname)
           INTO CORRESPONDING FIELDS OF TABLE <fs_db_tab>
           UP TO 100 ROWS.

* bind the table to context
  DATA: lo_nd_dyn     TYPE REF TO if_wd_context_node.
  lo_nd_dyn = wd_context->get_child_node( name = 'DB_TABLE' ).
  lo_nd_dyn->bind_table( new_items = <fs_db_tab> ).

ENDMETHOD.

 

Adding a new table based on a dynamically created context node
METHOD wddomodifyview .

  DATA: lo_group TYPE REF TO cl_wd_group,
        lo_table TYPE REF TO cl_wd_table,
        lo_nd_dn TYPE REF TO if_wd_context_node.

  IF first_time EQ abap_true.
    lo_group ?= view->get_element( id = 'GROUP_1' ).
    lo_nd_dn  = wd_context->get_child_node( name = 'DB_TABLE' ).
    lo_table  = cl_wd_dynamic_tool=>create_table_from_node(
                    ui_parent = lo_group
                    table_id  = 'TABLE_DB_TABLE'
                    node      = lo_nd_dn ).

    lo_table->set_visible_row_count( value = 20 ).

  ENDIF.

ENDMETHOD.

Leave a Reply

*

captcha *