Академический Документы
Профессиональный Документы
Культура Документы
Overview
Sequential Files
Local Sequential Files
SAP AG
Objectives
SAP AG
Overview
Sequential Files
SAP AG
Presentation
Application
Database
SAP AG
If you distribute the R/3 System according to the client / server method, the components of the R/3
System extend over a three-level computer hierarchy.
Presentation server:
The R/3 programs offered at this level implement the platform-specific input and output functions of
the R/3 System. The SAP GUI (Graphical User Interface).
Application server:
The R/3 programs offered at this level implement the whole business logic of the R/3 application.
You can select or combine several application servers according to your performance profile for
particular tasks. Several frontends (workstation, PC) can also be connected to each application
server.
Database server:
The database server is installed on a central host. The R/3 update service also runs on this host.
Several application servers can be connected to the database server.
Transferring Files
Local seq.
files
Presentation
Database
SAP AG
The runtime environment is implemented on the application server, which executes the ABAP
programs. ABAP supports the file transfer (data transfer) technique to the application server and the
frontend hosts.
The interface to the file system on the application server is implemented in the form of ABAP
language elements.
You can process sequential files using the statements READ DATASET (read) and TRANSFER
(write).
You implement the file interface on the application server using function modules (function modules
are a special type of subroutine that are stored in a library).
The data is transferred from the application server to the database server using batch input (BI), call
transaction (CT) or direct input (DI). You use a sequential file as the data source. This method
preserves the consistency of the data in the R/3 System.
Overview
Sequential Files
SAP AG
Processing Files
SAP AG
You open a sequential file before you write to or read from it.
The file is closed once it has been processed.
The program calls the file by its absolute file name. The absolute file name consists of the exact path
and the actual (relative) file name, such as '/tmp/file01' (note that file names are case-sensitive) or
'\\hstrnn0\sapmnt\trans' for Windows NT.
The format of file names depends largely on the operating system. You can access portable programs
by using the function module FILE_GET_NAME. This function module returns the physical name
for a given logical file name. You can find the function module description in the Function Builder
(the function module library).
Opening Files
Open Process Close
file file file
REPORT xxx.
:
OPEN DATASET newfile FOR APPENDING.
IF sy-subrc NE 0. EXIT. ENDIF.
:
SAP AG
REPORT xxx.
:
OPEN DATASET newfile FOR APPENDING MESSAGE text.
IF sy-subrc NE 0. EXIT. ENDIF.
:
SAP AG
TRANSFER TRANSFER
ABCABABCD A BC
AB
ABCD
READ DATASET READ DATASET
ABAP ABC ABAP ABC
program program AB
ABA
BCD ABC R
SAP AG
The example above illustrates the difference between binary mode and text mode:
Three fields of different lengths are transferred at any one time. The data is then read into three
fields of the same length.
In text mode, the operating system specific at end of line character is set after every data record.
Blanks at the end of a data record are not suppressed in text mode.
REPORT xxx.
DATA rec LIKE BBKPF.
:
SELECT ...
TRANSFER rec TO demo_file.
ENDSELECT.
SAP AG
REPORT xxx.
DATA rec LIKE BBKPF.
:
DO.
READ DATASET demo_file into rec.
IF sy-subrc NE 0. EXIT. ENDIF.
ENDDO.
SAP AG
Each READ DATASET statement reads one record from a sequential file into a field or structure.
Possible structures are field strings or table work areas.
The execution of the READ DATASET statement depends on the mode:
SAP AG
You use the CLOSE DATASET <file name> statement to close a sequential file explicitly As with
OPEN DATASET, errors are ignored.
In a program, all opened files are implicitly closed each time the screen changes, and then reopened
exactly as they were before when processing resumes.
At the end of a program, all files are closed.
Opening and closing files explicitly aids readability. Also, the advantage of using OPEN DATASET
is that it avoids a program termination if an error occurs when opening the file (SY-SUBRC = 8).
A file is not closed implicitly when READ DATASET reaches the end of a file
You can use the DELETE DATASET <file name> to delete a sequential file explicitly. If this is
successful, SY-SUBRC is set to 0.
You can display the current state of the file in debugging.
PARAMETERS:
oldfile(50) DEFAULT '/tmp/demo_old.txt' LOWER CASE,
sapfile(50) DEFAULT '/tmp/demo_fb01.sap' LOWER CASE,
errfile(50) DEFAULT '/tmp/demo_fb01.err' LOWER CASE,
session(20) DEFAULT 'B420SES01' LOWER CASE,
nodata DEFAULT '/' LOWER CASE.
START-OF-SELECTION.
OPEN DATASET: oldfile FOR INPUT IN TEXT MODE MESSAGE text,
sapfile FOR OUTPUT IN TEXT MODE,
errfile FOR OUTPUT IN TEXT MODE.
PERFORM fill_nodata_bbkpf.
PERFORM fill_nodata_bbseg.
R
SAP AG
The above program reads a sequential file (demo_old.txt) that contains legacy data and stores the
data formatted in the SAP record layout in a new sequential file (demo_fb01.sap).
The program then checks the data, converts it and formats it so that it can be processed by the Data
Transfer Workbench using the SAP standard data transfer method.
If the check determines that a data record is incomplete or incorrect, this record is not processed and
is written to a separate error file (demo_fb01.err).
The SAP record layout for this example is based on the structures:
Record 0 BGR00
Record 1 BBKPF
Record 2 BBSEG
The record layout structure must be initialized before it can be filled. Once the structures have been
filled, they are written to the sequential file.
Write Read
Open file
Transfer
Process data
structure
record?
No
More data End of
Yes records? file?
No Yes
Close file
SAP AG
In a file processing program, you first define the structures required for the data records with the
TABLES or DATA statement. The program uses these structures as internal buffers for the data
records.
You then open the sequential file for reading or writing with the OPEN statement.
When writing to the file, you transfer the filled structures to the file with TRANSFER statements.
When reading the file, you fill the structures set up for the data records with READ DATASET for
further processing in the program.
To close the sequential file, you exit file processing with the CLOSE DATASET statement.
Overview
Sequential Files
SAP AG
File name:
File type:
Convert Convert
according to according to
file type file type
Frontend
SAP AG
The function module DOWNLOAD downloads the contents of an internal table to a local sequential
file.
The function module UPLOAD uploads the contents of a local sequential file to an internal table.
For the local file, specify the file name (the complete path, e.g. '/tmp/myfile' for a UNIX file and or
'C:\ MYFILE.TXT' for a PC file).
The directory must be known to the presentation server.
The choice of suitable file names is the responsibility of the customer.
The system requests the file name and the file type interactively.
The data is converted according to the file type.
IMPORTING
ACT_FILENAME = <File name - entered value>
ACT_FILETYPE = <File type - entered value>
FILESIZE = <Number of bytes downloaded>
TABLES
DATA_TAB = <Transfer file>
R
SAP AG
For the function module DOWNLOAD, you need an internal table for the data transfer. You define
this table according to your data structure at the beginning of the program and then fill it with data.
You use the MODE parameter to define the write mode ('A' to extend a file, ' ' to create a new file).
The specification of default values for the file name, file type and a header for the file dialog is
optional.
The IMPORT parameters specify the values actually entered by the user for the file name, file type
and the number of download bytes.
You only specify a value for the export parameter CODEPAGE when performing a DOWNLOAD to
DOS (the only possible value is 'IBM'). Otherwise, this parameter is not used.
All EXPORTING parameters are optional.
If you want to generate a binary file, you must specify the file length. In this case, the transfer table
must consist of a column of type X.
File Formats
Internal
Internal table
table (ABAP)
(ABAP) Internal
Internal table
table (ABAP)
(ABAP)
F1 F2 F3 F1 F2 F3 ...
A B C A B C ...
D E F D E F ...
. . . G H I ...
. . . . . .
Format
Format DAT
DAT Format
Format WK1
WK1
Spreadsheet
Spreadsheet Spreadsheet
Spreadsheet
SAP AG
With UPLOAD and DOWNLOAD, another format available for conversions apart from ASC
(ASCII) and BIN (binary) is DAT for Excel. With DOWNLOAD, WK1 is also available for Excel
and Lotus.
For the format DAT, table columns are divided by a tabulator character and the table lines by CF
(carriage return) and LF (line feed).
For the format WK1, the data of a table is entered in a WK1-specific spreadsheet.
REPORT sapbc420seqd_download.
SAP AG
The above example uses a SELECT statement to read customer data from table KNA1 and enters
this data into a previously defined internal table.
The function module DOWNLOAD stores the internal table on the presentation server.
EXPORTING
CODEPAGE = <Do not use>
FILENAME = <File name - default value>
FILETYP = <File type - default value>
ITEM = <Header for file dialog>
IMPORTING
FILESIZE = = <File length>
TABLES
DATA_TAB = <Transfer table for file contents>
SAP AG
For the function module UPLOAD, you need an internal table for the data transfer. You define this
table according to your data structure at the beginning of the program.
The specification of default values for the file name, file type and a header for the file dialog is
optional.
You only specify a value for the export parameter CODEPAGE when performing an UPLOAD to
DOS (the only possible value is 'IBM'). Otherwise, this parameter is not used.
LOOP AT itab.
SAP AG
The above example program uses the function module UPLOAD to read a local sequential file from the
presentation server and enters this data in a previously defined internal table.
The internal table is then output with a loop.
Summary
SAP AG