Added by Sandra Rossi , last edited by Sandra Rossi on Nov 04, 2009 (view change) SHOW COMMENT
- Working with files on the application server
- Working with files on presentation server
- Copying from server to frontend or vice versa
- File compression (zip)
- Working with special files
In this article, only general directions are given. You may find snippets here
Files are handled differently when they are on the application server, or on the presentation server
Files may be processed in 2 modes, either text (in a given encoding), or binary (generated by a software like Microsoft Office, Adobe Acrobat, etc.) From ABAP, you may directly write and read text files, while binary files can only be written and read by the software. The mode is chosen when opening the file.
- Transaction code AL11 takes you to the application server in which you find the sap directories and the files inside the directories.
The configure button on the main screen can be used to create and manage links to existing directories.
- Files may be processed in 2 ways, decided in OPEN DATASET statement: either as text files with a given encoding (IN TEXT MODE, ENCODING and CODE PAGE additions), or as binary files (IN BINARY MODE addition).
Use ABAP statements OPEN DATASET with FOR OUTPUT keyword, TRANSFER, CLOSE DATASET.
Use ABAP statements OPEN DATASET with FOR INPUT keyword, READ DATASET and CLOSE DATASET.
- either OCS_GET_FILE_INFO function module
- or "OPEN DATASET" ABAP statement
To read the names of files present in a particular path on the application server we may use SUBST_GET_FILE_LIST or EPS_GET_DIRECTORY_LISTING function modules.
- F4_DXFILENAME_TOPRECURSION function module may be used to display a search help to choose a file
Instead of hardcoding the file names, it is possible to define generic names which are called "logical filenames". They may be defined using FILE transaction code, and used using FILE_GET_NAME function module.
either GUI_DOWNLOAD function module Snippet or CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD method Snippet Note: DOWNLOAD and WS_DOWNLOAD function modules are obsolete
either GUI_UPLOAD function module Snippet or CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD method Note: UPLOAD and WS_UPLOAD function modules are obsolete
either DX_FILE_EXISTENCE_CHECK function module or CL_GUI_FRONTEND_SERVICES=>FILE_EXIST method
either TMP_GUI_DIRECTORY_LIST_FILES function module or CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES method
For selecting a file, you may use:
CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG method (Basis, 4.6 and after): displays list as a popup with title "Open", and returns the name of selected file
CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG method (Basis, 4.6 and after): displays list as a popup with title "Save", and returns the name of selected file
WS_FILENAME_GET function module (Basis, any release)
F4_FILENAME function module (R/3 and ECC only)
For selecting a directory, you may use:
No, this functionality is not supplied because presentation servers may be switched off at any time without guarantee (see Note 7925 - Graphics, Upload, Download do not work in backgrnd). Workarounds may be:
Work with files on application server. The user may copy files from or to the application server when he is connected If you take decisions to make the presentation server work as a server (always the same computer, and it would be switched on), consider it is an RFC server: see SDN article Communication to Presentation Server in Background Mode for more information.
CL_GUI_FRONTEND_SERVICES class provides many other methods about files
CL_GUI_FRONTEND_SERVICES=>FILE_COPY method SAP commander R/3 and ECC: transaction codes CG3Y (from server to frontend) and CG3Z (from frontend to server)
Class CL_ABAP_ZIP may be used to read or write a zipped file. On the application server, OPEN DATASET statement may be used with FILTER addition to compress or uncompress
Note: there is also class CL_ABAP_GZIP, but it can't be used to process files, it may just be used to compress or uncompress data in memory.
See Excel file types (CSV, XML, XSLX, OLE)
When a user is connected to SAP via SAPGUI for Windows, you may use OLE ABAP statements (see ABAP documentation), or Desktop Office Integration framework (it also uses OLE).
It is not possible to use OLE or DOI in a program disconnected from SAPGUI (background job for example).
It is possible to create Office documents using XML files