Sunday, December 19, 2010

Using an ALV with Dynamic Context Nodes in Web Dynpro

Create a Web Dynpro Component as ZZ_DYNAMIC_CONTEXT

Declare the usage of the ALV component inside component ZZ_DYNAMIC_CONTEXT

Create view MAIN_VIEW

Declare the usage of the ALV component inside view MAIN_VIEW

Create context element and layout for storing DDIC table entry.

In the view MAIN_VIEW create a context node INPUT with an attribute TABLENAME of type string.

Navigate to the layout tab and create the following elements:

  • Group INPUTGROUP with caption text “Your Input”

  • A label and an inputfield for the context attribute TABLENAME.

  • Use text “Name of a DDIC table” for the label

  • Button SHOW with text “Show table” and action SHOW

  • View container UI element CONTAINER

Now Your Layout look like this…

Navigate into the event handler method ONACTIONSHOW of view MAIN_VIEW and write the following code

method ONACTIONSHOW .
DATA:
*Node Info
rootnode_info type ref to if_wd_context_node_info,
*Context Nodes
dyn_node type ref to if_wd_context_node,
tabname_node type ref to if_wd_context_node,
*String (for table name)
tablename type string.
*get node info of context root node
rootnode_info = wd_context->get_node_info( ).
*get the name of the table to be created.
tabname_node = wd_context->get_child_node( name = 'INPUT' ).
tabname_node->get_attribute( Exporting name = 'TABLENAME'
Importing value = tablename ).
translate tablename to upper case.
*create sub node named TEST1 of structure (tablename)
cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
parent_info = rootnode_info
node_name = tablename
structure_name = tablename
is_multiple = abap_true ).
DATA: stru_tab type ref to data.
field-symbols: type table.
*Create Internal Table
create data stru_tab type table of (tablename).
assign stru_tab->* to .
*Get table content
select * from (tablename) into corresponding fields of table .
*get  instance of new node
dyn_node = wd_context->get_child_node( name = tablename ).
*Bind Internal table to context node.
dyn_node->bind_table( ).
*instantiate alv component
data: l_ref_cmp_usage type ref to if_wd_component_usage.
l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
if l_ref_cmp_usage->has_active_component( ) is initial.
l_ref_cmp_usage->create_component( ).
endif.
*pass context node to alv
data: l_ref_interfacecontroller type ref to iwci_salv_wd_table .
l_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).
l_ref_interfacecontroller->set_data( dyn_node ).
endmethod.

Navigate to the window and into tab window and embed view MAIN_VIEW into the window. Thereafter embed view TABLE of the ALV component into the ViewContainerUIelement CONTAINER.

Create a Web Dynpro application for your Web Dynpro component.

Activate your Web Dynpro component and execute.

Output:

No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites