P. 1
54452229 Tutorial for Creating Totals and Subtotals Using ALV Webdynpro

54452229 Tutorial for Creating Totals and Subtotals Using ALV Webdynpro

|Views: 13|Likes:
Published by Shiva Annaldas
WD
WD

More info:

Published by: Shiva Annaldas on Jul 31, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

11/23/2014

pdf

text

original

Using Totals and Subtotals Feature of ALV Component in WD4A

Applies to:
Web Dynpro for ABAP For more information, visit the Web Dynpro ABAP homepage.

Summary
The tutorial describes how to configure ALV and how to make use of Totals and Subtotals feature provided by ALV component in Web Dynpro for ABAP. Author: Manas Dua

Company: SAP Labs India Pvt. Ltd Created on: 26 June 2009

Author Bio
Author works as a developer for Insurance and Sales Force Management project in Bangalore.

SAP COMMUNITY NETWORK © 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 1

.......................................sdn..............sap..........................................................................6 Testing the Application.......boc...sap.......................................................................................com 2 ........................................................8 Related Content..................................6 Creating Subtotals for ALV .......................................................................................................................com | BPX ...........9 Copyright.........................................................................................................................................................................10 SAP COMMUNITY NETWORK © 2009 SAP AG SDN .......................................................................4 Binding Data to ALV...........................................................................................................com | BOC ..................................Using Totals and Subtotals Feature of ALV Component in WD4A Table of Contents Introduction ...............................................................................................................sap.................................................................................................................3 Creating ALV Component Usage.................................................bpx..........3 Getting Started .........

n. Create a node in component controller named as TABLE_DATA with Dictionary Structure as SFLIGHT and cardinality as 0. Call the method FILL_DATA in WDDOINIT of component controller.com | BOC . In this particular article we’ll see how an ALV can be configured by code to create Total and Subtotal Rows based on user requirements.bpx.sap.. In view ALV_VIEW create a view container UI element and assign a name to it (let’s say ALV_CONT) Create a window (ALV_WINDOW) and embed ALV_VIEW to this window. function.sdn.boc. SAP COMMUNITY NETWORK © 2009 SAP AG SDN . * bind data to node lo_nd_table_data>bind_table( new_items = lt_table_data set_initial_elements = abap_true ). endmethod.com 3 .sap. we have various methods at our disposal to define the appearance. We’ll be using data of SFLIGHT table and we’ll be displaying total of Ticket Prices based on Ticket Currency Getting Started • • • • • • Create a sample web dynpro component (let’s say ZTEST_ALV).sap. DATA lo_nd_table_data TYPE REF TO if_wd_context_node. Following is the code for FILL_DATA method • method FILL_DATA . Add a view to it (ALV_VIEW). * get node reference lo_nd_table_data = wd_context->get_child_node( name = wd_this->wdctx_table_data ). As the developer of the application.com | BPX . One such behavior which most developers have to define is Summing up the numeric columns based on some parameter like Currency.. To fill data we’ve created method FILL_DATA which selects all data from SFLIGHT and then we bind this fetched data to node TABLE_DATA. and run-time behavior of this ALV output. The tool provides common list operations as standard functions and can be enhanced by self-defined options. Transfer all table columns in SFLIGHT so as to create attributes for node.Using Totals and Subtotals Feature of ALV Component in WD4A Introduction SAP List Viewer (ALV) is a flexible tool used to display data in a tabular format. * select all data from SFLIGHT select * from sflight into table lt_table_data. Create a web dynpro application (ZTEST_WDA_ALV) for this newly created component ZTEST_ALV and mention Interface View as ALV_WINDOW and plug name as DEFAULT. DATA lt_table_data TYPE wd_this->Elements_table_data.

• First we’ll be defining a component usage for the ALV component SALV_WD_TABLE in our application component. next step would be to embed the ALV view into window’s view container UI element. Defining Usage of MY_ALV component in View • Once the component use is defined for view. For this click on ALV_VIEW and in Properties tab under Used Controllers/ Components section click on Create button to select entries related to our defined component usage MY_ALV.com | BOC .Using Totals and Subtotals Feature of ALV Component in WD4A Creating ALV Component Usage With basic customizing in place.bpx.sap.sap. Defining Usage of ALV Component • Now we have to define the usage of this component in the properties of our view (ALV_VIEW).sap. For this go to your component ZTEST_ALV and in Used Components tab click on + button to create a component usage for type SALV_WD_TABLE.com 4 .sdn.boc. For this go to Window ALV_WINDOW and right click on view SAP COMMUNITY NETWORK © 2009 SAP AG SDN . next step would be to create a Component Usage for ALV. Give a name to your component usage under Component Use column (let’s say MY_ALV).com | BPX .

sap.Using Totals and Subtotals Feature of ALV Component in WD4A container UI element (ALV_CONT) to embed a view. Select declared ALV component MY_ALV and with View\ Interface View entry as TABLE Embedding the ALV view into View Container SAP COMMUNITY NETWORK © 2009 SAP AG SDN .boc.com | BOC .com | BPX .bpx.sdn.sap.sap.com 5 .

SAP COMMUNITY NETWORK © 2009 SAP AG SDN . Binding Data to ALV Creating Subtotals for ALV Once the data is bound.com | BOC .com | BPX . drag the node TABLE_DATA from component controller and map it to DATA node of ALV context. Inside CREATE_SUBTOTAL we’ll be writing the code for creating subtotal of Price column based on Currency.sdn. This action will map the data from component controller context node to ALV Interface controller context node DATA. To bind the data to ALV. click on Component Usages and select our used ALV component MY_ALV and expand it to view INTERFACECONTROLLER_USAGE node.sap.com 6 . next step is to configure the ALV for creating subtotals.sap. For this create a method named as CREATE_SUBTOTAL and call it inside view WDDOINIT method.Using Totals and Subtotals Feature of ALV Component in WD4A Binding Data to ALV To bind the data to ALV.bpx.boc. Following are the steps performed in CREATE_SUBTOTAL method – • • • • Getting the instance of ALV Getting all columns Looping at columns and declaring aggregation rule for PRICE column.sap. For creating subtotal based on Currency create a sort rule for currency column.

boc. * loop at columns loop at lt_column into ls_column. * for PRICE aggregate field CALL METHOD LR_FUNCTION_SETTINGS->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD EXPORTING FIELDNAME = 'PRICE' RECEIVING VALUE = lr_field_amnt. REF TO iwci_salv_wd_table. *create an instance of ALV component wd_this->wd_cpuse_MY_ALV( ).sap. salv_wd_s_column_ref. * get ALV component lr_salv_wd_table = wd_this->wd_cpifc_MY_ALV( ). when 'CURRENCY'. CALL METHOD LR_FUNCTION_SETTINGS->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD EXPORTING FIELDNAME = 'CURRENCY' RECEIVING VALUE = lr_field_curr. then initialize if lo_cmp_usage->has_active_component( ) is initial. endif. when 'PRICE'. REF TO CL_SALV_WD_AGGR_RULE. * get all columns lt_column = lr_column_settings->get_columns( ).Using Totals and Subtotals Feature of ALV Component in WD4A Following is the code snipped for CREATE_SUBTOTAL method – method CREATE_SUBTOTAL .com | BPX . * get reference to column settings lr_column_settings ?= lr_function_settings. *This method creates subtotal for PRICE based on currency column DATA: lo_cmp_usage DATA: lr_salv_wd_table DATA: lr_column_settings lr_column lt_column ls_column DATA: lr_function_settings DATA: lr_field_settings lr_field_curr lr_field_amnt DATA: lv_aggr_rule DATA: lr_sort_rule lo_cmp_usage = TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE ref to if_wd_component_usage. CASE ls_column-id.sap. REF TO cl_salv_wd_column. lr_function_settings = lr_salv_wd_table->get_model( ). CALL METHOD LR_FIELD_CURR->IF_SALV_WD_SORT~CREATE_SORT_RULE EXPORTING SORT_ORDER = IF_SALV_WD_C_SORT=>SORT_ORDER_ASCENDING GROUP_AGGREGATION = ABAP_TRUE SAP COMMUNITY NETWORK © 2009 SAP AG SDN . REF TO CL_SALV_WD_FIELD. REF TO CL_SALV_WD_CONFIG_TABLE. * create aggregate rule as total CALL METHOD LR_FIELD_AMNT->IF_SALV_WD_AGGR~CREATE_AGGR_RULE EXPORTING AGGREGATION_TYPE = IF_SALV_WD_C_AGGREGATION=>AGGRTYPE_TOTAL RECEIVING VALUE = lv_aggr_rule.com | BOC . REF TO if_salv_wd_column_settings. REF TO IF_SALV_WD_FIELD_SETTINGS.bpx. lo_cmp_usage->create_component( ). * if not initialized. REF TO CL_SALV_WD_SORT_RULE. * sub totals based on contract currency.sdn.com 7 . REF TO CL_SALV_WD_FIELD. salv_wd_t_column_ref.sap.

Using Totals and Subtotals Feature of ALV Component in WD4A RECEIVING VALUE = lr_sort_rule. *hide others when OTHERS. endloop.bpx. endmethod.com | BPX . endcase.sap.sap. ALV with Subtotals of Airfare based on Currency SAP COMMUNITY NETWORK © 2009 SAP AG SDN .com 8 .sdn. ls_column-r_column->set_visible( if_wdl_core=>visibility_none ). Testing the Application Test the application created above ZTEST_WDA_ALV to see the subtotals of Price column based on currency in ALV output.boc.com | BOC .sap.

visit the User Interface Technology homepage.sap.sap. SAP COMMUNITY NETWORK © 2009 SAP AG SDN .sdn.com 9 .boc.bpx.com | BOC .sap. visit the Web Dynpro ABAP homepage.Using Totals and Subtotals Feature of ALV Component in WD4A Related Content For more information. For more information.com | BPX .

WinFrame. System Storage. used under license for technology invented and implemented by Netscape. and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. POWER5.bpx. R/3. Netfinity. Crystal Decisions. OS/2. Nothing herein should be construed as constituting an additional warranty. in the United States and in other countries. POWER6. and MultiWin are trademarks or registered trademarks of Citrix Systems. Linux is the registered trademark of Linus Torvalds in the U. Redbooks. System z10. SAP. Microsoft. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only. Intelligent Miner. X/Open. Xcelsius. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. MetaFrame. Inc. z9. All other product and service names mentioned are the trademarks of their respective companies. OS/390. System x.sap. BladeCenter. S/390 Parallel Enterprise Server. XHTML and W3C are trademarks or registered trademarks of W3C®. RACF. HTML.boc. BusinessObjects.sap. Excel. Duet. zSeries. All rights reserved. PowerPC. Oracle is a registered trademark of Oracle Corporation. SAP Business ByDesign. Outlook. SAP COMMUNITY NETWORK © 2009 SAP AG SDN . No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. Power Architecture. ICA. the Adobe logo. and Motif are registered trademarks of the Open Group. WebSphere. IBM. Crystal Reports. HACMP. System z.sap. POWER. DB2. System z9. xSeries. AIX. BatchPipes. and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.S. pSeries. Massachusetts Institute of Technology. PartnerEdge.sdn.com | BPX . XML. Acrobat. PostScript. SAP NetWeaver. AS/400. POWER5+. Java is a registered trademark of Sun Microsystems. These materials are subject to change without notice. eServer. without representation or warranty of any kind. S/390. i5/OS. RETAIN. VideoFrame. DB2 Universal Database. UNIX. National product specifications may vary. ByDesign. z10.. Inc. Web Intelligence. Citrix. Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.Using Totals and Subtotals Feature of ALV Component in WD4A Copyright © Copyright 2009 SAP AG. z/OS. OSF/1. POWER6+. and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S. GPFS. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services. MVS/ESA. PowerVM. Inc. and other countries. if any. Business Objects is an SAP company.com | BOC . DB2 Connect. OpenPower. Adobe. Windows. System i5. System p5. Data contained in this document serves informational purposes only.A. JavaScript is a registered trademark of Sun Microsystems. System p. Business Objects and the Business Objects logo. The information contained herein may be changed without prior notice. Parallel Sysplex. Program Neighborhood.com 10 . System i. and SAP Group shall not be liable for errors or omissions with respect to the materials. z/VM. World Wide Web Consortium. OS/400. and PowerPoint are registered trademarks of Microsoft Corporation. iSeries.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->