Sap Export Table To Excel Se16 Sap

Posted on
Sap Export Table To Excel Se16 Sap 3,6/5 9114 reviews
Skip to end of metadataGo to start of metadata

Submitted by Harini Gopinath, Hexaware Technologies.

Importing from SAP to Excel. Most reports can be downloaded into Excel. Tables can be downloaded from SE16 is you. Then from the display you can export to excel. Feb 28, 2018 - You can also use the abap2xlsx tool described in SDN blog, by Ivan Femia, which generates an XLSX file (available from Excel 2007).

Often we face situations where we need to download internal table contents onto an Excel sheet. We are familiar with the function module WS_DOWNLOAD. Though this function module downloads the contents onto the Excel sheet, there cannot be any column headings or we cannot differentiate the primary keys just by seeing the Excel sheet.
For this purpose, we can use the function module XXL_FULL_API. The Excel sheet which is generated by this function module contains the column headings and the key columns are highlighted with a different color. Other options that are available with this function module are we can swap two columns or supress a field from displaying on the Excel sheet. The simple code for the usage of this function module is given below.

Page:Downloading the program with includes to your PC.
Skip to end of metadataGo to start of metadata

You can also use the abap2xlsx tool described in SDN blog abap2xlsx - Generate your professional Excel spreadsheet from ABAP, by Ivan Femia, which generates an XLSX file (available from Excel 2007). It is much more simple to use.

Exporting data to Excel - XML to the rescue

There is often a requierment to export report data to a Microsoft Excel spreadsheet. If the report is a simple ALV grid then the ALV control can do it automatically, but otherwise ABAP coding is required.

The simplest solution is to download a tab separated file and then open this in Excel. This is fine for simple data, but has lots of problems:

  • no formatting (headings, colours, column widths etc)
  • dates are YYYYMMDD, so are not shown as a date in Excel
  • Only one worksheet can be exported
  • leading zeros are lost
  • numeric fields of more than about 15 digits are truncated

There have traditionally been a few ways around this problem

  • Use SAP function modules to create an XLS file (no customisation possible)
  • Use OLE to start Excel and manipulate the data cell by cell (difficult, not much help, presentation server only)

However, Excel can now read and write xml files. An ABAP program can create an xml file and it can be opened directly into Excel. The advantages and possibilities are endless:

Sap Se16 Purchase Order Tables

  • An xml file is plain text so can be created on the presentation server or application server;
  • alternatively, it can be sent as an attachment to an email, or can be provided as a parameter to a web service;
  • colours, fonts, number formats and so on can be specified;
  • formatting can be applied to rows, columns or single cells;
  • column heights and widths can be specified, or auto-formatted;
  • multiple worksheets can be created;
  • formulas can be entered in cells;

How to proceed

  • Code ABAP to create xml data as a table or string. Possible techniques are

View and analyse xml file created by Excel

Create a new Excel workbook and enter the data you would like to see. Add formatting, headings, sheet names etc, and some data.

Save as an xml file.

Open the xml file in a text editor (eg Notepad).

It should look something like this:

Manual coding

Possibly the simplest way to create the XML is to create an internal table and fill it with the xml tags and data.

This code is from the ABAP forum, by Rudolf Lindenmann

Error rendering macro 'code': Invalid value specified for parameter 'lang'

Html Export Table To Excel

Coding using the xml DOM concept

SAP provides an interface and classes for building up an xml document. This ensures that the xml document is well formed, ie does not contain any syntax errors. There is some overhead in the coding, so it is probably overkill for a really simple export, but it is a much better alternative for anything complex.
There are a number of blogs on creating an xml document using DOM.

Sample code for a report to download any database table to a file on the presentation server.
Column headings are provided from the data dictionary, formatted bold with yellow background, wordwrap.
Numeric fields are formatted with the number of decimal places specified in the data dictionary.
Text fields are formatted as Text rather than General

Error rendering macro 'code': Invalid value specified for parameter 'lang'Sap Export Table To Excel Se16 Sap

Coding using transformations

Table

With ECC5 and later, xml can be created using Transformations. The transformation can be either coded with an ABAP-like syntax, or an XSLT style sheet.
For more information, look the F1 help on CALL TRANSFORMATION

Export the file

Sap Export Table To Excel Se16 Sap

Last but not least, the file needs to be exported. Options include:
Download to presentation server using GUI_DOWNLOAD
Download to application server using OPEN DATASET etc
Send as an attachment to an email
Have the xml table/string as a parameter on a RFC or web service.