How to Read an Xml File in Abap

Table of contents

Introduction

In this commodity, only general directions are given. You may find snippets here

Files are handled differently when they are on the awarding server, or on the presentation server

Files may be processed in two modes, either text (in a given encoding), or binary (generated past a software similar Microsoft Office, Adobe Acrobat, etc.) From ABAP, you may directly write and read text files, while binary files tin can but be written and read by the software. The style is chosen when opening the file.

Working with files on the application server

  • Transaction code AL11 takes you to the application server in which you find the sap directories and the files within the directories.

    The configure push 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 Lawmaking Page additions), or as binary files (IN BINARY MODE addition).

How to create or write to a file

Apply ABAP statements Open up DATASET with FOR OUTPUT keyword, TRANSFER, CLOSE DATASET.

How to read a file

Use ABAP statements Open up DATASET with FOR INPUT keyword, READ DATASET and Close DATASET.

Checking file existence

  • either OCS_GET_FILE_INFO function module
  • or "Open up DATASET" ABAP argument

How to get list of files in a directory

To read the names of files present in a detail path on the application server we may use SUBST_GET_FILE_LIST or EPS_GET_DIRECTORY_LISTING function modules.

Is there a search help for selecting a file

  • F4_DXFILENAME_TOPRECURSION function module may be used to display a search help to cull a file
  • Snippet

Best practice

Instead of hardcoding the file names, it is possible to define generic names which are called "logical filenames". They may exist defined using FILE transaction lawmaking, and used using FILE_GET_NAME part module.

Miscellaneous

  • sdn contribution : ABAP Server Side File Access, by Thomas Jung (grade ZCL_ES_SERVER_FILE_ACCESS)
  • Note 752859: sapiconv - a tool for converting the encoding of files

Working with files on presentation server

How to create or write a file

  • either GUI_DOWNLOAD function module
    Snippet
  • or CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD method
    Snippet
  • Note: DOWNLOAD and WS_DOWNLOAD function modules are obsolete

How to read a file

  • either GUI_UPLOAD function module
    Snippet
  • or CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD method
  • Notation: UPLOAD and WS_UPLOAD function modules are obsolete

Checking file beingness

  • either DX_FILE_EXISTENCE_CHECK function module
  • or CL_GUI_FRONTEND_SERVICES=>FILE_EXIST method

How to go list of files in a directory

  • either TMP_GUI_DIRECTORY_LIST_FILES office module
  • or CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES method

Is there a search help for selecting a file or directory

For selecting a *file", you may use:

  • CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG method (Footing, 4.6 and afterwards): 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 afterwards): displays list as a popup with title "Salve", and returns the name of selected file
    Snippet
  • WS_FILENAME_GET function module (Footing, whatever release)
  • F4_FILENAME role module (R/3 and ECC merely)

For selecting a directory, yous may utilise:

  • CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE method

Is it possible to piece of work in background?

No, this functionality is not supplied because presentation servers may exist switched off at any time without guarantee (see Note 7925 - Graphics, Upload, Download do not piece of work in backgrnd).
Workarounds may be:

  1. Work with files on application server. The user may copy files from or to the application server when he is continued
  2. If yous 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: meet SDN article Communication to Presentation Server in Groundwork Style for more than data.

Miscellaneous

  • CL_GUI_FRONTEND_SERVICES class provides many other methods about files

Copying from server to frontend or vice versa

  • 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)

File compression (zip)

  • Course CL_ABAP_ZIP may exist used to read or write a zipped file.
  • On the application server, Open DATASET statement may be used with FILTER improver to compress or uncompress

Note: there is too class CL_ABAP_GZIP, only information technology tin't be used to process files, it may just be used to compress or uncompress data in memory.

Working with special files

Excel file types

See Excel file types (CSV, XML, XSLX, OLE)

OLE/DOI for Office native files (Excel, Word, etc.)

  • 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 utilise OLE or DOI in a program asunder from SAPGUI (background job for example).
  • It is possible to create Office documents using XML files

moranmaraver51.blogspot.com

Source: https://wiki.scn.sap.com/wiki/display/ABAP/Working+with+files

0 Response to "How to Read an Xml File in Abap"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel