Reusable WebDynpro Component for Export to Excel from Table UI Element. (Generic Method).



Similar documents
Upload Data in Web Dynpro Table from a Text File with Delimiters

Business Scenario Using GP/Web Dynpro with Back and Forth 3 Level Process and Dynamic Approvers in a Loop

Tutorial - Creating Pop Up Window Using New Features in WebDynpro Java CE 7.1 Ehp1

Web Dynpro: Multiple ALV Grids and Layouts in ALV

SAP NetWeaver Developer Studio 7.30 Installation Guide

Table of Contents. Passing Data across Components through Component Controller between Two Value Nodes

SAP CRM System 6.0/7.0. For more information, visit the Customer Relationship Management homepage

Step by Step Guide How to Copy Flat File from Other Application Server to BI and Load through Info Package

Deleting the User Personalization done on Enterprise Portal

Configuration of Enterprise Services using SICF and SOA Manager

Exposing RFC as Web Service and Consuming Web Service in Interactive Forms in ABAP

How to Generate Stack Xml for Ehp4 and Above Upgrade

SAP CRM Campaign Automation

Web Dynpro ABAP: ALV and Table in Popup Window

SAP CRM 7.0 for Newbies: (Part 1) Simple BOL Object Creation for CRM Webclient UI

Restricting Search Operators in any Search View

How to Create an ecatt?

Step by Step Guide for Language Translation Tool

Creating Web Service from Function Modules/BAPIs & Integrating with SAP Interactive Forms

Creating Transaction and Screen Variants

Reverse Transport Mechanism in SAP BI

How to Integrate CRM 2007 WebClient UI with SAP NetWeaver Portal

Step by Step Procedures to Load Master Data (Attribute and Text) from FlatFile in BI 7.0

Configuring HTTPs Connection in SAP PI 7.10

Creating New Unit of Measure in SAP BW

How to Assign Transport Request for Language Translation?

Standard SAP Configuration of SMS through HTTP with Third Party SMS Gateway

LSMW: Upload Master Data using Batch Input Recording

SAP BW - Excel Pivot Chart and Pivot Table report (Excel)

SAP CRM 7.0 E2C Setup: CRM via Toolset

Display Options in Transaction SE16

Process Controlled Workflow SRM 7.0 (Using BRF)

Table of Content. SAP Query creation and transport Procedure in ECC6

Splitting the Custom Container & Display more than one ALV

Quick Viewer: SAP Report Generating Tool

Creating Content Using SO10 Objects and Text Symbols

Creation and Configuration of Business Partners in SAP CRM

Forgot or Lock "Administrator or J2EE_ADMIN" Password

Converting and Exporting Data in XML Format

Data Flow from LBWQ/SMQ1 to RSA7 in ECC and Delta Extraction in BI

Salesforce.com Integration Using SAP PI: A Case Study

This document applies to SAP ECC 6.0, SAP Netweaver 2004s. For more information, visit the Web Dynpro ABAP homepage.

SAP FI - Automatic Payment Program (Configuration and Run)

A Step-by-Step guide on SMTP Configuration and File to Mail Scenario Using Process Integration Scenario in PI 7.1

Deploying Crystal Reports on Top of a SAP BI Query

Step by Step guide of Report-to- Report Interface in BW Reporting

ABAP Debugging Tips and Tricks

Deploying JDBC drivers in PI 7.1x Systems

How to Modify, Create and Delete Table Entries from SE16

Deleting the Requests from the PSA and Change Log Tables in Business Intelligence

BW Performance Monitoring

Understanding BEx Query Designer: Part-2 Structures, Selections and Formulas

ALE Settings, for Communication between a BW System and an SAP System

Step by Step Procedure to Block and Debug a CIF Queue Flowing from R/3 to APO System

Embedding Crystal Reports inside ECC ALV Reports

Order Split Usage in Production Orders

Compounding in Infoobject and Analyzing the Infoobject in a Query

Understanding OLAP Processor and RSRT

BI 7.0 and EP 7.0 Integration using Template Installer

Multi Provider Creation Based on Sales and Planning Info Cubes

XSLT Mapping in SAP PI 7.1

Web Application Designer for Beginners

ABAP Proxy Interfacing

Extractor in R/3 and Delta Queue

Message handling in SAP CRM Web UI

Merge PDF files in ABAP

Step by Step Procedure to Create Broadcasters, to Schedule and to Enhance of SAP- BI Queries from Query Designer

Salesforce Integration Using PI: How to Perform Query and Other DML Operations Using the Enterprise WSDL

Creating Mobile Applications on Top of SAP, Part 1

Understanding DSO (DataStore Object) Part 1: Standard DSO

Currency Conversion using Variables in SAP BI -Reporting

Implementing TinyMCE JavaScript HTML Editor for Web Page Composer (WPC) within the SAP Portal

Consuming Services in SOA Manager

Multi Level Purchase Order Release Strategy

Working with SAP BI 7.0 Data Transfer Process (DTP)

How to Call RFC from Web Dynpro Application

Data Extraction and Retraction in BPC-BI

Mandatory Field Check in Web Dynpro- ABAP

Creating and Scheduling Publications for Dynamic Recipients on SAP Business Objects Enterprise

Using PI to Exchange PGP Encrypted Files in a B2B Scenario

SAP NetWeaver Portal Development Kits for.net and Java

ABAP How To on SQL Trace Analysis

Different Types of Alerts for Process Chains. Table of Content

Using JUnit in SAP NetWeaver Developer Studio

Create Automatic Mail Notification/ Alert for Process Chain Monitoring

Using the Monitoring and Report Viewer Web Services

Query OLAP Cache Optimization in SAP BW

Release Strategy Enhancement in Purchase Order

SAP Business Intelligence Platform Translation Management Tool SDK Developer Guide

SAP BW 7.3: Exploring Semantic Partitioning

Sending an Image File Through XI in a File-to-Mail Scenario

Step By Step Procedure to Create Logical File Path and Logical File Name

Organizational Management- Organizational Structure Creation

APD to Update Marketing Attributes from SAP BI to SAP CRM

Integrated Testing Solution Using SAP Solution Manager, HP-QC/QTP and SAP TAO

SAP CRM Middleware Configurations

SAP Workflow in Plain English

First step to Understand a Payroll Schema

Transfer of GL Master from Source SAP System to a Target SAP System through IDOCS

SAP MM: Purchase Requisition with Classification and Workflow Approval

Transcription:

Reusable WebDynpro Component for Export to Excel from Table UI Element. (Generic Method). Applies to: SAP NetWeaver WebDynpro for Java version NWDS 7.0.13. For more information, visit the User Interface Technology homepage, For more information, visit the Web Dynpro Java homepage. Summary This article deals with creating the Reusable component i.e. Generic method for Export to Excel Download. Author: Company: Abhilasha A Dahare. L & T Infotech. Created on: 8 April 2009 Author Bio Abhilasha Dahare is working as a WebDynpro consultant past 1 year in L&T Infotech. 2009 SAP AG 1

Table of Contents Steps... 3 Creating Reusable Development Components... 3 Steps for creating External Library DC... 3 Steps for referencing external library DC i.e. creating Reusable WebDynpro DC... 6 Steps for using the reusable WebDynpro component... 16 Related Content... 21 Disclaimer and Liability Notice... 22 2009 SAP AG 2

Steps Creating Reusable Development Components We have to create Three Dc s to make a reusable component, one an External Library DC which will contain the open source jars, other Dc which uses as reusable dc in many DC s to export the data into excel the and referencing the external library Dc as used dc, and the other WebDynpro Dc which will make use of this to export data. Steps for creating External Library DC 1) Create an External Library DC (File->New-> Development Component) 2) Local Development My component next 3) Give a project name and caption and select external library project as type and then press finish. 2009 SAP AG 3

4) Add the jar files to the library. (Shown below in the screen shot) poi-scratchpad-3.1-final-20080629.jar poi-3.1-final-20080629.jar poi-contrib-3.1-final-20080629.jar Click on the following links to download respective jar files. Export to excel Jar Copy all jar files and paste it into as follow. 2009 SAP AG 4

5) Define public part for the DC (assembly and compilation). Here we have to make public part for all jar files. Build this DC. 2009 SAP AG 5

Steps for referencing external library DC i.e. creating Reusable WebDynpro DC In this we will create one WebDynpro project which will refer the external library project and can be used as a reusable component to export table data to excel. 1) Create a WebDynpro local development. Give a project name and caption and select WebDynpro as type,next and then click on finish. 2009 SAP AG 6

2) Add External Library project as used dc in newly created WebDynpro project. Finish. 3) Now open component controller and create three methods. Getcellvarient () of type java.lang.string and create two parameters for this method, first parameter as p_row of type HSSFRow and second parameter as p_cell_no of integer. 2009 SAP AG 7

Showpopup () of type void. Create three parameters for this method, first parameter as Resourcetype of type wdwebresourcestype.second parameter as outputstream of type ByteArrayoutputstream and third parameter as title of type java.lang.string. 2009 SAP AG 8

2009 SAP AG 9

Export_to_excel () of type void and create two parameters for this method, one coulmninfo of type java.util.map and the other datanode of type IWDNode. 2009 SAP AG 10

4) Coding Part of the Dc. Create two value attributes, one Resource of type resource and second popupwindow of type IWDWindow. 2009 SAP AG 11

Write the code in the respective methods. Code for Getcellvarient (): public java.lang.string GetcellVarient( org.apache.poi.hssf.usermodel.hssfrow p_row, int p_cell_no ) //@@begin GetcellVarient() String l_value = null ; HSSFCell l_cell = p_row.getcell((short)p_cell_no); if(!(l_cell == null)) if(l_cell.getcelltype() == l_cell.cell_type_string) l_value = l_cell.getstringcellvalue(); else if(l_cell.getcelltype() == l_cell.cell_type_numeric) long l_lng_value = (long)(l_cell.getnumericcellvalue()); l_value = String.valueOf(l_lng_value); return l_value; //@@end 2009 SAP AG 12

Code for showpopup(): public void showpopup( com.sap.tc.webdynpro.services.sal.url.api.wdwebresourcetype resourcetype, java.io.bytearrayoutputstream outputstream, java.lang.string title ) //@@begin showpopup() IWDResource resource = null; resource = WDResourceFactory.createResource(outputstream.toByteArray(),"ExcelSheet",resourcetype ); wdcontext.currentcontextelement().setresources(resource); IWDWindow window; window = wdcomponentapi.getwindowmanager().createnonmodalexternalwindow(resource.geturl( WDFileDownloadBehaviour.AUTO.ordinal()), title); window.setwindowsize(200,150); window.setwindowposition(wdwindowpos.center); window.show(); wdcontext.currentcontextelement().setpopupwindow(window); //@@end Code for export_to_excel (): public void export_to_excel( java.util.map columinfo, com.sap.tc.webdynpro.progmodel.api.iwdnode datanode ) //@@begin export_to_excel() ByteArrayOutputStream outputstream = null; HSSFWorkbook wb = null; HSSFSheet sheet = null; try outputstream = new ByteArrayOutputStream(); wb = new HSSFWorkbook(); sheet = wb.createsheet("table1"); int col = 0; String attributename, trimmedheadertext; HSSFRow row = sheet.createrow(0); for (Iterator iter = columinfo.keyset().iterator(); iter.hasnext();) attributename = (String) iter.next(); trimmedheadertext = (String)columinfo.get(attributeName); columinfo.put(attributename, trimmedheadertext); HSSFCell cell_hed = row.createcell((short)col++); cell_hed.setcelltype(hssfcell.cell_type_string); cell_hed.setcellvalue(trimmedheadertext); for(int x=0; x<datanode.size(); x++) 2009 SAP AG 13

iter.hasnext();) col=0; for (Iterator iter = columinfo.keyset().iterator(); attributename = (String) iter.next(); HSSFRow row_data_products = sheet.createrow(x+1); IWDNodeElement ele = datanode.getelementat(x); wb.createcellstyle(); HSSFCellStyle cellstle = cellstle.setwraptext(true); cellstle.setalignment(hssfcellstyle.align_center); cellstle.setfillbackgroundcolor(hssfcolor.blue_grey.index); cellstle.setfillforegroundcolor(hssfcolor.blue_grey.index); wb.createfont(); HSSFFont font1 = font1.setcolor(hssfcolor.blue.index); font1.setboldweight(hssffont.boldweight_normal); cellstle.setfont(font1); row_data_products.createcell((short)col++); HSSFCell cell = cell.setcellvalue(ele.getattributevalue(attributename).tostring()); cell.setcellstyle(cellstle); Put"); wb.write(outputstream); showpopup(wdwebresourcetype.xls, outputstream, "XLS Out outputstream.close(); // wdcontext.currentcontextelement().getpopwindow(); // window.close(); catch ( IOException ex ) ex.printstacktrace(); //@@end 2009 SAP AG 14

5) Create Data link Between Component controller and Interface controller and then create method in interface controller call_compcont_excel of type void with two parameters columninfo (java.util.map) and datanode (IWDNode) which will call export to excel method of component controller method. Write a code in interface controller method as follow. public void call_compcont_excel (java.util.map columinfo, com.sap.tc.webdynpro.progmodel.api.iwdnode datanode) //@@begin call_compcont_excel () wdthis.wdgetexcelappcontroller ().export_to_excel (columinfo, datanode); //@@end 6) Create Public part for this Dc, Build and then Deploy. 2009 SAP AG 15

Steps for using the reusable WebDynpro component In this application we are going create a WebDynpro project which will export data that is populated in a table in to ExcelSheet. 1) Create development component of WebDynpro. 2) Add Reusable Export to excel Dc (here reuse_export_to_excel) as used dc. 3) Finish and then add used component. 2009 SAP AG 16

2009 SAP AG 17

4) Open Data modeler and create Data link between used WebDynpro component and view. 5) Create value node to populate data in table as follow. 6) Create table in view by using Apply Template and also create a Button and bind it with a method Export_Data which will call method of reuse_export_to_excel dc interface controller. 2009 SAP AG 18

7) Coding Part for the dc. public void wddoinit() //@@begin wddoinit() for(int i=0;i<=tabledata.length-1;i++) IPrivateTableExcelAppView.ITableNodeElement tab= wdcontext.createtablenodeelement(); //tab=wdcontext.nodetable().getelementat(i); tab.setcust_id(this.tabledata[i][0]); tab.setcust_name(this.tabledata[i][1]); tab.setcust_phn(this.tabledata[i][2]); //@@end wdcontext.nodetablenode().addelement(tab); public void nactionexport_data(com.sap.tc.webdynpro.progmodel.api.iwdcustomevent wdevent ) //@@begin onactionexport_data(serverevent) wdthis.wdgetreuseexcelcompinterface().export_to_excel(getproductcolumninfo s(),wdcontext.nodetablenode()); //@@end //@@begin others private static final String tabledata[][]= "1001","John","9928453632", "1002","Smith","9963582147", "1003","Kerry","9874596321", ; private Map getproductcolumninfos() Map columninfosmap = new HashMap(); 2009 SAP AG 19

columninfosmap.put( IPrivateTableExcelAppView.ITableNodeElement.CUST ID, "CUST ID"); columninfosmap.put( IPrivateTableExcelAppView.ITableNodeElement.CUST NAME, "CUST NAME"); columninfosmap.put( IPrivateTableExcelAppView.ITableNodeElement.CUST PHN, "CUST PHN"); return columninfosmap; //@@end 8) Build and Deploy. 2009 SAP AG 20

Related Content 1) Exporting Context Data into Excel Using the WebDynpro Binary Cache 2) Exporting Data from WebDynpro in Different Formats Using Open Source (POI, JExcel, itext) API s 3) Enhancing Tables in WebDynpro Java Custom built Table Utilities 4) For more information, visit the User Interface Technology homepage, 5) For more information, visit the Web Dynpro Java homepage. 2009 SAP AG 21

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. 2009 SAP AG 22