Ansicht
Dokumentation

ABAP file interface in R/3 <br />Tip-No.: 27 ( INFO27 )

ABAP file interface in R/3
Tip-No.: 27 ( INFO27 )

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.
SAP E-Book

Short text

ABAP file interface in R/3
Tip-No.: 27

Symptom

In R/3, files can be read, written, and dynamically created online.

Cause

See solution.

Solution

Language elements OPEN, CLOSE, READ DATASET, and TRANSFER
1) OPEN DATASET
Opens the specified file. According to success, SY-SUBRC is set
to either 0 or 8. Without supplement, the file is open for input
in binary mode (see below).
Possible supplements:
FOR OUTPUT
Opens the file for output. If the file already exists, its contents
are deleted if the file was not already open when the call was made.
If it was open, the cursor is positioned at the start of the file.
If the file does not exist, it is generated.
FOR INPUT
Opens an already existing file for read. If the file was already
open, the cursor is positioned at the start of the file.
FOR INPUT does not have to be specified explicitly.
FOR APPENDING
Opens the file for writing at end of file. If the file does not
exist, it is generated. If the file was already open, the cursor
is positioned at the end of the file.
IN BINARY MODE
The contants of the file are not interpreted by read and write
operations READ DATASET and TRANSFER. The data areas specified
with these language elements are directly input or output.
IN BINARY MODE does not need to be specified explicitly.
IN TEXT MODE
If a file is opened with this supplement, it is assumed that the
file is constructed in lines. At each READ DATASET or TRANSFER
call, exactly one line is always input or output. If the data
area to large for the read line (when reading), the rest is filled
with blanks. If it is too small, the rest of the line is lost.
AT POSITION
With this supplement, you can specify an explicit file position in
bytes from the start of the file. The next read or write oper-
ation takes place at this position. You can not position before
the start of the file. This supplement can be used together with
supplement IN TEXT MODE. This is not very logical, however, since
the physical representation of a text file is highly dependent on
the operating system.
TYPE
In the field or literal following TYPE, you can specify further file
attributes. The content of this field is passed on unaltered to
the operating system. No check for correctness takes place.
Possible contents are:
blksize= specification of maximum block length in bytes
lrecl= logical record length in bytes
recfm= record format with =F fixed length
V variable length
FB fixed length, blocked
VB avariable length, blocked
type= with =record File is opened for "record I/O".
The areas for input and output
must then be defined in record
length. The file cannot be
opened in TEXT MODE.
memory File is "in memory" file.
Several of these attributes, separated by commas, can also be
specified. If and when these attributes are used is highly
dependent on the operating system.
Example: generation of an MVS file "QXX.YYY" with the specified
characteristics:
OPEN DATASET '''QXX.YYY'''
TYPE 'lrecl=80, blksize=8000, recfm=F'
FOR OUTPUT.
2) CLOSE DATASET ,file name>.
Closes the specified file. Any errors occurring are ignored.
3) READ DATASET INTO .
Binary mode: Read in the length of field .
Text mode: Read one line.
If the specified file is not open, then READ DATASET attempts to
open the file (IN BINARY MODE FOR INPUT or with the specifications
of the last OPEN command for this file). If the end of file had
already been reached before the read, SY-SUBRC is set to 4. Other-
wise it is set to 0. Errors occuring lead to program abend.
4) TRANSFER TO .
Binary mode: writes in the length of field .
Text mode: writes one line.
If the specified file is not opened, then TRANSFER attempts to open
file FOR OUTPUT (IN BINARY MODE or with the further
specifications from the last OPEN command for this file). In
TRANSFER, occurring errors lead to program abend.
Error messages:
If an error occurs, the OPEN command sets SY-SUBRD to 8.
Further information is not immediately provided. A subsequent
READ DATASET or TRANSFER command internally repeats
the previous faulty OPEN command. If an error occurs now, it leads
to program termination with an output error message.
folgender READ DATASET- oder TRANSFER-Befehl wiederholt intern den
Notes:
- For each mode, a maximum of 4 files can be opened at once.
- When possible, all files are opened for "random access". This
means that both write and read operations are possible.
Switching from read to write (or vice-versa) should be done
via explicit commands OPEN DATASET ... FOR OUTPUT/INPUT (without
previous CLOSE command) in order to reset internal buffer areas.
- For each user dialog, all open files are closed for the operating
system and then reopened in their old condition after the
processing has been resumed. If the file was opened for writing
(OPEN FOR OUTPUT or implicitly via TRANSER), then the SAP System
alone has write authorization, but cannot be kept open via
a user dialog. This is also valid for files in which you
cannot explicitly position (e.g. I/O channels for
terminals, UNIX fifos, etc.).
- Under IMS, open files are closed for the system even in debugging.
This does not occur in other environments.
- Supplement TYPE for the OPEN command is senseless under OS/2 and
other UNIX operating systems.
- A file is not implicitly closed when READ DATASET reaches the end
of the file.
- The current file condition can be displayed in debugging.
Menu display/storage areas and entering DATASETS in the following
screen.






TXBHW - Original Tax Base Amount in Local Currency   BAL Application Log Documentation  
This documentation is copyright by SAP AG.

Length: 6949 Date: 20240426 Time: 123246     sap01-206 ( 30 ms )