alv with dynamic structure in web dynpro · alv with dynamic structure in web dynpro applies to:...
TRANSCRIPT
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 1
ALV with Dynamic Structure in
Web DynPro
Applies to:
Web DynPro ABAP. For more information, visit the Web Dynpro ABAP homepage.
Summary
Though it’s always better to give all the design to your WDC before running it, sometimes dynamic creation of ALV and the layout can be a good idea. It saves the effort that’d go into creating nodes and modifying the attributes time and again. This manual guides you through the creation of an ALV WebdynPro Component that ‘builds itself up’ even as it runs.
Author: Pushpraj Singh
Company: Infosys technologies Limited
Created on: 09 December 2009
Author Bio
Pushpraj Singh is currently placed as a senior ABAP consultant at Infosys. He has worked on a few Web DynPro developments and find the field very interesting.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 2
Table of Contents
Pre requisite Skills......................................................................................................................................... 3
Steps to create a dynamically structured ALV WebdynPro Application ........................................................... 3
Related Content .......................................................................................................................................... 15
Disclaimer and Liability Notice ..................................................................................................................... 16
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 3
Pre requisite Skills
You should know the ABCs of Web DynPros : node, attribute, view, application, etc are. Having created a ‘static’ ALV WDC before would be really recommended.
Steps to create a dynamically structured ALV WebdynPro Application
1. Go to the transaction SE80 and choose Web Dynpro Comp. / Intf. In the list. Give a name and press Enter.
2. You’d be asked to enter a description. Enter and press enter.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 4
3. Go to the WDC (WebdynPro Component) you just created and add the usage of the ALV component (Component SALV_WD_TABLE)
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 5
4. Now go to the MAIN view and to the Properties tab. (In case your SAPGUI doesn’t create the MAIN view automatically create it manually) Click on the Create Controller Usage button and choose both the ALV component usages from the pop up.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 6
5. Go to the Layout tab of the view and create a group. In this group add a View Container UI Element with the id view_cont.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 7
6. Now go to the Methods tab of the view and write the following code in the method WDDOMODIFYVIEW (Method for Modifying the View Before Rendering).
METHOD wddomodifyview.
"this check avoids the creation of the node 'ALV' again on
"any ALV event and thus prevents dump
IF first_time EQ abap_true.
TYPES : lst_sflight TYPE STANDARD TABLE OF sflight.
DATA : li_sflight TYPE lst_sflight,
lw_sflight TYPE sflight.
"add the fields to be used as ALV columns
DATA : li_comp TYPE cl_abap_structdescr=>component_table.
**********************************************************************
"this is the portion of the code where we can add or remove fields
"to or from the ALV
wd_this->fill_comp(
EXPORTING
fv_name = 'CARRID' " this would be the name of the attribute unde
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 8
r the node 'ALV'
fv_data_element = 'S_CARR_ID' " data element
IMPORTING
fi_comp = li_comp " cl_abap_structdescr=>component_table
).
wd_this->fill_comp(
EXPORTING
fv_name = 'CONNID' " this would be the name of the attribute unde
r the node 'ALV'
fv_data_element = 'S_CONN_ID' " data element
IMPORTING
fi_comp = li_comp " cl_abap_structdescr=>component_table
).
wd_this->fill_comp(
EXPORTING
fv_name = 'FLDATE' " this would be the name of the attribute unde
r the node 'ALV'
fv_data_element = 'S_DATE' " data element
IMPORTING
fi_comp = li_comp " cl_abap_structdescr=>component_table
).
wd_this->fill_comp(
EXPORTING
fv_name = 'PRICE' " this would be the name of the attribute under
the node 'ALV'
fv_data_element = 'S_PRICE' " data element
IMPORTING
fi_comp = li_comp " cl_abap_structdescr=>component_table
).
**********************************************************************
"create the desired structure and assign it to a new dynamic context node
DATA: lo_root_info TYPE REF TO if_wd_context_node_info,
lo_node_info TYPE REF TO if_wd_context_node_info,
lo_structdescr TYPE REF TO cl_abap_structdescr.
CALL METHOD cl_abap_structdescr=>create
EXPORTING
p_components = li_comp
RECEIVING
p_result = lo_structdescr.
* Get context node info
lo_root_info = wd_context->get_node_info( ).
* Generate new node 'ALV' with the dynamic structure
CALL METHOD lo_root_info->add_new_child_node
EXPORTING
name = 'ALV'
is_initialize_lead_selection = abap_false
static_element_rtti = lo_structdescr
is_static = abap_false
RECEIVING
child_node_info = lo_node_info.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 9
* get instance of new node
DATA : lo_dyn_node TYPE REF TO if_wd_context_node.
lo_dyn_node = wd_context->get_child_node( name = 'ALV' ).
"Populate the internal table
SELECT *
FROM sflight
INTO CORRESPONDING FIELDS OF TABLE li_sflight
UP TO 38 ROWS.
"transfer the contents of the internal table to the node
lo_dyn_node->bind_table( li_sflight ).
*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( lo_dyn_node ).
ENDIF.
ENDMETHOD.
Go to the method List of the View and add a method fill_comp.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 10
METHOD fill_comp.
DATA : lw_comp TYPE cl_abap_structdescr=>component,
lv_type TYPE REF TO cl_abap_datadescr.
lw_comp-name = fv_name.
lv_type ?= cl_abap_typedescr=>describe_by_name( p_name = fv_data_element ).
lw_comp-type = lv_type.
APPEND lw_comp TO fi_comp.
ENDMETHOD.
7. In order to show the ALV inside the View, we must embed the Table View of the SALV_WD_TABLE component. Go to the Window and select the View Container UI Element (view_cont) that was created earlier. Right click on it.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 11
8. Choose TABLE of the ALV component.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 12
9. Right Click on the component and create a WebdynPro Application.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 13
10. Activate everything.
11. Execute the WDA.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 14
As we can see, without having to create (or change) the context we can get any structure we want by simply doing a few changes to the code written in the method WDDOMODIFYVIEW.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 15
Related Content
http://www.sdn.sap.com/irj/scn/elearn?rid=/library/uuid/201ddd3b-b4ce-2b10-8883-880ae8147f89
http://www.saptechnical.com/Tutorials/WebDynproABAP/DynamicALV/Demo.htm
?blog=/pub/wlg/2888
For more information, visit the Web Dynpro ABAP homepage.
ALV with Dynamic Structure in Web DynPro
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com
© 2009 SAP AG 16
Disclaimer and Liability Notice
This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not
supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,
and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and
services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this
document.