Professional Documents
Culture Documents
DISCOVERING ABAP
Knowledge Base for SAP ABAP Developers
SAP ABAP
In this post you will learn how to read Excel File from Presentation server.
x
Read Excel File from Presentation Server
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 1/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
Below code would upload xlsx file from presentation server i.e. your laptop / desktop. This also
includes example of how to handle date conversion and decimal places for amount.
Sample File
However, in this option we can not read the data from a specific tab and if the file has multiple tabs it
is not possible to manage the data upload using this method.
Advertisements
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 2/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = lv_file
filetype = 'BIN'
IMPORTING
filelength = DATA(lv_file_length)
header = DATA(lv_xstring_header)
CHANGING
data_tab = lt_bin_data
EXCEPTIONS
OTHERS = 99 ).
"CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_file_length
IMPORTING
buffer = lv_xstring_header
TABLES
binary_tab = lt_bin_data
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc = 0.
TRY.
DATA(lo_excel) = NEW cl_fdt_xl_spreadsheet(
document_name = iv_file
xdocument = lv_xstring_header ) .
lo_excel->if_fdt_doc_spreadsheet~get_worksheet_names(
IMPORTING
worksheet_names = DATA(lt_worksheets) ).
DATA(lv_woksheetname) = lt_worksheets[ 1 ]. "Read first sheet
DATA(lo_data_ref) = lo_excel->if_fdt_doc_spreadsheet~get_itab_from_worksheet(
lv_woksheetname ).
ASSIGN lo_data_ref->* TO FIELD-SYMBOL(<lfs_data_tab>).
cl_demo_output=>display( <lfs_data_tab> ).
CATCH cx_fdt_excel_core.
"Error handling
ENDTRY.
ENDIF.
This is a effective method which allows us to read Excel file. However, this comes at a risk. SAP x
suggests to use this class only within BRF+ framework and not outside. See the note below for the
warning.
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 3/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
Advertisements
The solution to this issue is to use the ABAP2XLSX open source project. It can be found on github at
below links.
https://github.com/abap2xlsx/abap2xlsx
Visit ABAP Code Sample : ABAP2XLSX project for tutorial on installing the project.
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 4/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
Published by Jagdish
Jagdish has extensive experience in SAP ABAP, ABAP on HANA, OOABAP, OData
Development in ABAP, and RESTful Application Programming Model in ABAP. He is a
dedicated SAP Developer who is passionate about his work. Additionally, he owns
and is the sole author of the SAP ABAP knowledge-sharing portal,
https://discoveringabap.com/. If you require any assistance with learning ABAP-
related topics, SAP certifications, or ABAP-related issues, feel free to contact
Jagdish. View all posts by Jagdish
← PREVIOUS NEXT →
SAP Conversational AI [1] : Build a Simple Chatbot ABAP Code Samples : Read Excel Files from
Application Server
LEAVE A REPLY
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 5/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
Advertisements
18 Years of Filmora®
Makes It Easy to Create
Stunning Videos on
Windows & Mac.
Free Video Editor for Win/Mac, 800+ Video
Effects, Easy-to-Use, Step By Step Tutorial
Download
Ad
report this ad
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 6/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
report this ad
Quick Links
ABAP Debugger
ABAP Editor
ABAP on HANA
Devtoberfest 2022
Interview Preparation
OData x
OO ABAP
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 7/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
RAP Model
SAP Conversational AI
SAPUI5/Fiori
What's New?
TRENDING POSTS
ABAP 7.4 and beyond [2] : Read Internal Tables with New Syntax
ABAP 7.4 and beyond [9] : FOR LOOP for Internal Tables
x
report this ad
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 8/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 9/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 10/11
5/16/23, 5:11 PM ABAP Code Samples : Read Excel Files from Presentation Server – Discovering ABAP
Advertisements
report this ad
© 2023 DISCOVERING ABAP
https://discoveringabap.com/2022/07/20/abap-code-samples-read-excel-files-from-presentation-server/ 11/11