Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Applies to:
SAP BW 3.5, BI 7.0. For more information, visit Business Intelligence homepage.
Summary
This document guides the user to generate an ABAP executable program which helps the user to create an
excel file, fill it with necessary data and then place that particular excel formatted file in the path required.
Author Bio
Koundinya Karanam is a SAP BI Consultant working for Mahindra
Satyam. Skill set includes SAP Business Intelligence, SAP IP & Business
Objects.
Table of Contents
Introduction
In SAP BW, using Open Hub, we can generate a CSV formatted file and place that in the required path
(either Application server or local machine). Now by using this ABAP executable program, we can generate a
file in excel format with the required fields and place that particular file in a specified path required. We can
also automate the process of sending the excel file as an attachment in the mail and send it to as many mail
id’s as required.
Business Scenario
In our daily scenario’s, we will be facing the situations like we need to send a report to Top level Management
or Middle Level Management users. To generate the report and perform Export to Excel file and to send the
file to the user mail box, much manual intervention is necessary. So in order to generate a report and export
the same to an excel file automatically and place it in the specified path (either local machine path or
Application server path or Network path) and also to send the excel file as an attachment to different mail
id’s, please go through the below process.
To convey the same, I have considered a two business scenarios. The first scenario specifies to download
the data in the excel sheet and place that in a specified path - the student’s data will be placed retrieving the
necessary data from an ODS and then download or place the excel file in a specified path present in your
local machine. The second scenario is that we will send the same excel file as an attachment without
downloading it to our local machine which will be automated with the help of ABAP Executable program.
Note: The Table or ODS or Infoobject which we are using should be readily available in BW.
• Give the necessary title and the Attributes (Type, Status etc…) as mentioned in the below screen.
• Now it prompts to save this program in a package. Fill the required fields with the package name
which you use in your project.
• Go ahead providing a new Transport request or assign an old transport request if exists and click ok
to move ahead.
• Now the ABAP editor is in front of you. Copy and paste the below code in the ABAP editor and save.
Business Scenario 1:
To download the excel file and place it in a specified path.
CLEAR wa_output2.
**Below is the select statement which fetches the data from active table of an
ODS where the data resides in BW and places the data in an internal table.
SELECT /bic/stu_id /bic/z_marks1 /bic/z_marks2 /bic/z_marks3 FROM /bic/azod_stu0
0 INTO TABLE it_output.
**Now we are calling the function “GUI DOWNLOAD” which transfer the data of an
internal table from the server to a file on your local machine. The module
“Gui_Download” replaces the obsolete modules Ws_Download and Download. The file
dialog of the download module is available in class Cl_Gui_Frontend_Services.
For more info on this, kindly refer to the SAP documentation of this function.
TABLES
data_tab = it_output2
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
ENDIF.
IF sy-subrc <> 0.
ENDIF.
Business Scenario 2:
To send the excel file as an attachment to mail id’s specified without saving the excel file in a path in our local
machine.
PERFORM build_xls_data.
*PERFORM get_recepients.
PERFORM send_mail.
*&---------------------------------------------------------------------*
*& Form build_xls_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM build_xls_data.
CONSTANTS:
con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
lv_sub1 = wa_out-zmarks1.
lv_sub2 = wa_out-zmarks2.
lv_sub3 = wa_out-zmarks3.
CLEAR: wa_attach,
wa_out.
ENDLOOP.
ENDFORM.
"build_xls_data
*&---------------------------------------------------------------------*
*& Form send_mail
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM send_mail.
DATA: lv_document_data TYPE sodocchgi1.
* Body of the mail
DATA: contents TYPE TABLE OF solisti1 WITH HEADER LINE.
* Recepient list.
DATA: lv_receivers TYPE TABLE OF somlreci1,
wa_receivers TYPE somlreci1.
Create the following Text elements and activate. We can also create text elements by double clicking on the
serial number assigned to the text in the program (text-001, text002, text003, text004) which would take us to
the Text elements screen.
*If we need to send this mail in "TO" list, please refer to the below code.
wa_receivers-receiver = 'XXXXXXX@YYYY.com'.
wa_receivers-rec_type = 'U'.
wa_receivers-no_forward = 'X'.
APPEND wa_receivers TO lv_receivers.
*If we need to copy this mail to any of the recepients, please refer to the belo
w code.
wa_receivers-receiver = 'XXXXXXX@YYYY.com'.
wa_receivers-rec_type = 'U'.
wa_receivers-copy = 'X'.
wa_receivers-no_forward = 'X'.
APPEND wa_receivers TO lv_receivers.
ENDFORM. "send_mail
Now ‘Check’, ‘Save’ and ‘Activate’ the program. Check for any Syntax errors and modify the code if
necessary.
Now we can go ahead executing the program to check the functionality of placing the file of Excel format in
the necessary path and also sending the Excel file as an Attachment.
Related Content
Please find below references related to the above content.
Copyright
© Copyright 2009 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.
The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9,
iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server,
PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes,
BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX,
Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated
in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of
Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts
Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by
Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, 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.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and
other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered
trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document
serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP
Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or
omissions with respect to the materials. 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, if any. Nothing herein should be construed as constituting an
additional warranty.