Sie sind auf Seite 1von 48

0

SAP AG 1999
File Monitor
Sequential Files
Local Sequential Files
Logical File Names
Sequential Files: Contents
SAP AG BC420 7-1

0.2
SAP AG 1999
Use the file monitor to monitor files and
directories
Read and write to sequential files on the
alication ser!er and the resentation ser!er
Maintain and use logical file names
"t the conclusion of this unit# $ou will %e a%le to:
Sequential Files: Unit &%'ecti!es
SAP AG BC420 7-2

0.(
SAP AG 1999
Course &!er!iew )iagram
)aten*%ernahme
)+ ,or-%ench
LSM ,or-%ench
.rinciles of Standard
)ata /ansfer
)
i
r
e
c
t

0
n

u
t
1".0
/
"

R
e
c
o
r
d
e
r
Course &!er!iew
2
1
a
t
c
h

0
n

u
t
C
a
l
l

/
r
a
n
s
a
c
t
i
o
n
(
3)0
1asics
4
5
6
7 80
88
80
9
88
86
8(
82
88
82
8
2
SAP AG BC420 7-3

0.6
SAP AG 1999
&!er!iew of Content : Sequential Files
&!er!iew ; File Monitor
&!er!iew ; File Monitor
Sequential Files
Sequential Files
Local Sequential Files
Local Sequential Files
Logical File Names
Logical File Names
SAP AG BC420 7-4

0.4
SAP AG 1999
R<(
R<(
"lication
.resentation
)ata%ase
"1".
"1".
READ DATASET
TRANSFER
Local
sequential
files
Local
sequential
files
Sequential
files
Sequential
files
File /ransfer
The runtime environment, implemented on the application server, executes the ABAP programs.
ABAP supports file transfer on the application server and on the frontend computers.
The processing of the sequential files on the application server is supported by using ABAP
language elements.
You process sequential files with the ABAP commands P!" #ATA$!T, %!A# #ATA$!T &read
records', T%A"$(!% &write records', and )*$! #ATA$!T.
The file interface on the presentation server is implemented by function modules.
The data is transferred from the application server to the database server with batch input &B+', )all
Transaction &)T' or #irect +nput &#+'.
SAP AG BC420 7-5

0.5
SAP AG 1999
"lication
R<(
Sequential
files
Sequential
files
&ther files in the
alication ser!er
&ther files in the
alication ser!er
3na%les $ou to !iew directories and files in the alication
ser!er
/he data in the alication ser!er cannot %e changed
/he File Monitor ="L88>
The file monitor is a )),$ tool &)omputing )enter ,anagement $ystem'. The administrator can
use the )),$ to monitor and control the %-. server.
/ith the file monitor you can display the %-. directory structure 0 the database directories and files
are excluded here. You could, for example, view the cross0application server transport directory
12trans1, or the instance0specific directories 12wor31, 12data1, 12#4!B,5$...6.
SAP AG BC420 7-6

0.2
SAP AG 1999
78.98.:;;; :<=<8=<> +?: iwdf?9?:
$AP #irectories
...
#+%@!A!)BTAB*! #=2usr2sap2+?:2$Y$2exe2run
DIR_GLOBAL D:\usr\sap\I41\SYS\global
#+%@5%APC@!A! #=2usr2sap2+?:2$Y$2exe2run
#+%@5%APC@*+B #=2usr2sap2+?:2$Y$2exe2run
DIR_O!" D:\usr\sap\I41\D#"B!GS$$\%or&
#+%@%AC,! un3nown
#+%@PA5+"5 #=2usr2sap2+?:2#4!B,5$992data
#+%@P%(+*! #=2usr2sap2+?:2$Y$2profile
#+%@P%TD**$ #=2usr2sap2+?:2#4!B,5$992log
#+%@$B%)! #=2usr2sap2+?:2$Y$2src
#+%@T!,P .
DIR_'RA(S \\i%)*4$41\sap+nt\trans
...
When double-click
directory, see next
slide ...
Global R/3 directory parameters and their
physical directories
)irectories in the File Monitor
DX-WB and !"W
#orkin$ directory
There are two columns on the initial screen of the file monitor=
n the left, the system0internal directory parameters
n the right, the physical directories of these parameters.
1#+%@T%A"$1 represents the global transport directory used for transporting programs and other
obEects between systems in the %-. $ystem landscape.
To go to the directories displayed here, double0clic3 the directory or choose Display.
"ote= the data files for the exercises in this course were placed in the home directory.
SAP AG BC420 7-7

0.7
SAP AG 1999
#irectory 22iwdf?9?:2sapmnt2trans
"ame *ength )reator *ast )hange
0000000000000000000000000000000000000000000000000000000000000000000000
...
B)?79T!$T F;9 Administ :8.98.:;;; :9=<?
B#!T!$T .7?<;9 Administ :8.98.:;;; :9=<?
T!$T(+*! ::79 Administ :8.98.:;;; :9=<?
bin 9 Administ ::.9:.:;;; 9;=::
buffer 9 Administ ::.9:.:;;; 9;=::
cofiles 9 Administ ::.9:.:;;; 9;=::
data 9 Administ ::.9:.:;;; 9;=::
eps 9 Administ ::.9:.:;;; 9;=::
etc 9 Administ ::.9:.:;;; 9;=::
log 9 Administ ::.9:.:;;; 9;=::
......
Double-click on %ile
see next %ile ...
&iles in this directory
'ther sub-directories o% the transport directory
Files in File Monitor ="L88>
..........
..........
..........
You can find *iles and other sub)irectories in the selected transport directory. &bin, buffer, cofiles,
etc.'G double0clic3 again to go to these subdirectories. $ubdirectories have the length specification
191'.
At this level the contents of selected files can be displayed via 6select6 or double clic3.
SAP AG BC420 7-8

0.9
SAP AG 1999
&!er!iew ; File Monitor
&!er!iew ; File Monitor
Sequential Files
Sequential Files
Local Sequential Files
Local Sequential Files
Logical File Names
Logical File Names
&!er!iew of Content : Sequential Files =2>
SAP AG BC420 7-9

0.80
SAP AG 1999
.rocess
file
&en
file
Close
file
File .rocessing
Before data records can be written to a sequential file or read from a file, the file has to be opened.
After processing the file is closed again.
SAP AG BC420 7-10

0.88
SAP AG 1999
&!er!iew )iagram: Read File
No
?es
)efine structure
&en file
Read data record
.rocess data
record
Close file
3nd of file
reached@
A file processing program must define the required structures for the data records using a TAB*!$
or #ATA statement. These structures are used as program0internal wor3 areas for the data records.
The P!" statement is used to begin file processing and open the source and target sequential files
for reading or writing.
Rea)ing: The %!A# #ATA$!T statement is used to rea) the records from the source file into the
data structures for later processing in the program.
,riting: T%A"$(!% statements are used to trans*er the filled structures to the target file.
The )*$! #ATA$!T statement is used to end file processing and close the sequential files.
SAP AG BC420 7-11

0.82
SAP AG 1999
&!er!iew )iagram: ,rite File

No
?es
Fill structure
/ransfer
structure
Close file
More data
records@
&en file
)efine structure
$ee slide 6%ead file6.
SAP AG BC420 7-12

0.8(
SAP AG 1999
REPORT xxx.
:
OPEN DATASET newfile FOR APPENDING.
IF sy-subrc NE 0. EXIT. ENDIF.
:
OPEN DATASET filen!"e#
$FOR %INP&T ' O&TP&T ' APPENDING().
.rocess
file
&en
file
Close
file
F&R 0N.U/ is the default
&en File
You can explicitly open a file using the command P!" #ATA$!T Hfile nameI.
+f the file can be opened, $Y0$BB%) is set to 9, otherwise it is set to >. Any errors are ignored.
/e recommend, for reasons of clarity, that you open the file explicitly. Bsing the P!" #ATA$!T
statement allows you to test whether an error has occurred when you open the file &$Y0$BB%) J
>'. +f you do not explicitly open the file, a %!A# #ATA$!T or T%A"$(!% command will attempt
to open the file using the default mode. +n this case, if an open error occurs, you cannot trap the error
and the program will terminate processing.
Possible additions=
(% +"PBT
pens an existing file to read it. +f the file was already open, the file is read from the beginning.
(% +"PBT is the default.
(% BTPBT
pens the file to write it. +f the file exists already, the contents are deleted. +f the file does not
exist, it is created.
(% APP!"#+"5
pens the file to append records to the end of the file. +f the file does not exist, it is created. +f the
file exists and was already open, the pointer to the next record is moved to the end of the file.
SAP AG BC420 7-13

0.86
SAP AG 1999
REPORT xxx.
:
OPEN DATASET newfile FOR APPENDING *ESSAGE +ex+.
IF sy-subrc NE 0. EXIT. ENDIF.
:
OPEN DATASET filen!"e#
$FOR %INP&T ' O&TP&T ' APPENDING()
$IN %,INAR- *ODE ' TEXT *ODE()
$*ESSAGE fiel.#).
10N"R? M&)3 is the default
.rocess
file
File
oen
Close
file
&en File: "dditions
/hen you open a file, you can choose between B+"A%Y and T!AT mode.
+" B+"A%Y ,#! 0 the length of the data input from a %!A# #ATA$!T or output from a
T%A"$(!% is dependent on the length of the structure being used in the operation.
+" T!AT ,#! 0 the length of the data input from a %!A# #ATA$!T or output is dependent on
the end of record indicator.
/ithout an addition the file in the binary mode is opened.
Th P!" command can also return a message by using the addition ,!$$A5! HfieldI. The
associated operating system message is stored in the field HfieldI, if there is an error opening the
file.
SAP AG BC420 7-14

0.84
SAP AG 1999
R<(
R<(
"1".
rogram
" 1 C
" 1
" 1 C )
"1".
rogram
" 1 C
" 1
" 1 C
/R"NSF3R
R3") )"/"S3/
"1".
rogram
" 1 C
" 1
" 1 C )
/R"NSF3R
"1".
rogram
" 1 C
" 1 "
1 C )
R3") )"/"S3/
Binary mode
Text mode
"1C
"1
"1C)
" 1 C " 1 " 1 C )
.rocess
file
&en
file
Close
file
1inar$ Mode and /eAt Mode
The above diagram helps explain the difference between binary mode and text mode. +n each
example three records of different lengths are transferred. Then the data is imported into three
structures of the same length.
+n the text mode an end of record indicator specific to the operating system is set after each data
record is written. /hen reading the file, the end of record indicator is sued to determine the length
of data to be read.
+n binary mode data is transferred according to the length of the source or target structure.
"ote= Blan3 characters at the end of a data record are not deleted in text mode.
SAP AG BC420 7-15

0.85
SAP AG 1999
R<(
REPORT xxx.
DATA rec /I0E ,,0PF.
:
SE/E1T ...
TRANSFER rec TO .e"23file.
ENDSE/E1T.
TRANSFER fiel.# +2 filen!"e# $/ENGT4 len#).
&ne data record to one file
.rocess
file
&en
file
Close
file
/ransfer )ata Record
The T%A"$(!% command is used to write a data record into a sequential file.
A field or structure would be filled wit data before each T%A"$(!% command.
HfieldI can be a field or a structure.
The execution of the T%A"$(!% command depends on the mode= 0
Binary mode= Appends the length of the field or the structure to the file
Text mode= /rites a new record to the file
+f the specified file is not opened, T%A"$(!% attempts to open the file (% BTPBT &+"
B+"A%Y ,#! or with the further specifications of the last P!" command for this file'. +f this
does not wor3, a runtime error results.
Any errors will result in the program terminating.
The additional parameter *!"5TC HlenI permits an explicit length specification in bytes. +n this
case the exact number of characters specified in HlenI are transferred. +f the structure is shorter, it is
padded &in text mode with blan3 characters and in binary mode with hexadecimal Keros'. +f the
structure is longer, it is truncated.
SAP AG BC420 7-16

0.82
SAP AG 1999
R<(
READ DATASET filen!"e# INTO fiel.# $/ENGT4 len#).
REPORT xxx.
DATA rec /I0E ,,0PF.
:
DO.
READ DATASET .e"23file in+2 rec.
IF sy-subrc NE 0. EXIT. ENDIF.
ENDDO.
&ne data record from one file
.rocess
file
&en
file
Close
file
Read )ata Record
/ith %!A# #ATA$!T you can read a record from a sequential file into a field or structure.
Possible structures are field strings or table wor3 areas.
The execution of the %!A# #ATA$!T command depends on the mode= 0
Binary mode= %eads the structure length
Text mode= %eads one record of data
+f the specified file is not opened, %!A# #ATA$!T attempts to open the file &+" B+"A%Y ,#!
(% +"PBT' or with the additions of the last P!" #ATA$!T command for this file'.
+f the file end has been reached, $Y0$BB%) is set to ?, otherwise it is set to 9. +f the file cannot be
opened, $Y0$BB%) is set to >. Any errors will result in the program terminating.
%!A# #ATA$!T, li3e T%A"$(!%, does not execute any implicit conversions. The data is imported
as it has been written.
The %!A# #ATA$!T command together with the additional parameter *!"5TC HlenI returns the
length of the imported file record into the field HlenI.
SAP AG BC420 7-17

0.87
SAP AG 1999
1/OSE DATASET filen!"e#.
DE/ETE DATASET filen!"e#.
.rocess
file
&en
file
Close
file
Close < )elete File
The command )*$! #ATA$!T Hfile name I closes a sequential file. !rrors are ignored the same
as with P!" #ATA$!T.
/ithin a program when the screen is changed all open files are shut and opened again with their old
status when processing is started again.
All files are closed when the program is exited.
/e recommend, for reasons of clarity, that you open and close the file directly. P!" #ATA$!T has
also the advantage that if an error does occur when you open the file &$Y0$BB%) J >', it will not
result in a termination.
A file is not implicitly closed, if %!A# #ATA$!T reaches the end of the file.
/ith the command #!*!T! #ATA$!T Hfile nameI you can physically delete a sequential file.
The file will then not longer exist in the operating system. nce it has been deleted, $Y0$BB%) is
set to 9.
The current file status can be displayed in debugging.
SAP AG BC420 7-18

0.89
SAP AG 1999
"/" is the NODATA character
... ... < ...
< <
Fields that are ignored in the eAternal data transfer
using S". standard rograms# must %e filled
%eforehand with the N&)"/" character.
/he default character is B<B
/he N&)"/" Character
$AP record layouts must be filled with the "#ATA indicator, before they are described with data.
+f fields in the $AP $ystem are not to be filled with external data, the standard transfer process
expects this special character &"#ATA indicator' for record layout fields. The default special
character is L-L, but it can be redefined in the field B5%990"#ATA. You have to initialiKe the record
layouts with this special character.
SAP AG BC420 7-19

0.20
SAP AG 1999
0nitialiCe record la$outs
through hel structures
0nitialiCe hel structures
&en files
Read eAternal data
to end of file
Close files
Fill record la$outs and
write to target file
End of File
Not
Reached
auArec
%-na8 D auArec
2 1EN"8
Fill %-na8 with )ata
Mr. < ...
< < < < <
< < < < <
0nitialiCing Record La$out Structures
As described on the slide, conversion of external data to the $AP record layout format, which strictly
requires the use of the standard transfer method, includes several steps=
:. pen all files.
7. +nitialiKe help structures with the "#ATA character. These structures are copied to the record
layouts to initialiKe the record layouts.
.. %ead an external data record.
?. +nitialiKe the record layouts with the previously initialiKed help structures.
<. (ill the record layouts with the external data=
(irst the external data is formatted &for example 6MN NB$#N'. The formatted data is then
mapped to the corresponding fields of the record layout.
F. /rite the filled record structures to the target file.
8. *oop bac3 to step . until end of file.
>. )lose the files.
SAP AG BC420 7-20

0.28
SAP AG 1999
REPORT xxx.
DATA !uxrec /I0E bb56f.
...
PERFOR* ini+ usin7 !uxrec 898.
FOR* ini+ 14ANGING 63rec 63n2.!+!.
FIE/D-S-*,O/S f#....
DO.
ASSIGN 1O*PONENT sy-in.ex OF STR&1T&RE 63rec TO f#.
IF sy-subrc # 0. EXIT. ENDIF.
f# : 63n2.!+!.
ENDDO.
ENDFOR*.
Transferred structure
Which character should
be used for the NODATA
character
All fields in the transferred structure
are filled !ith NODATA
0nitialiCing Fel Structures
+nitialiKation of the record layout with the "#ATA character is always executed using the same
procedure.
All structure fields are addressed and initialiKed using the pointer operations 1A$$+5"
),P"!"T ... T HfI. ,4! ... T HfIN.
The form routine +"+T is designed so that all structures can be transferred to the formal interface
parameter P@%!)G all structures will then be initialiKed with the pre0defined "#ATA character.
SAP AG BC420 7-21

0.22
SAP AG 1999
3Aamle of Maing .rogram
REPORT xxx.
...
PERFOR* ini+ &SING b5n003n2.!+!.
...
PERFOR* fill3b7r00.
TRANSFER b7r00 +2 2u+file;.
DO.
READ DATASET infile INTO rec3c2n<er+.
IF sy-subrc # 0. EXIT. ENDIF.
...
*O=E b5n003n2.!+! TO b5n00.
PERFOR* fill3b5n00.
*O=E b5n!;3n2.!+! TO b5n!;.
PERFOR* fill3b5n!;.
...
TRANSFER: b5n00 TO 2u+file;>
b5n!; TO 2u+file;>
b5nb; TO 2u+file;.
...
ENDOO.
Fills session header
"a#s the data
$el# structure for
record layout
b%n&&'init
is filled !ith NODATA
(nitiali)es structure
The code shows the important steps from initialiKing the help structures through to writing the record
layouts.
SAP AG BC420 7-22

0.2(
SAP AG 1999
3Aamle of Formatting
REPORT xxx.
:
FOR* f2r"!+.
1ASE rec3le7!cy-s6r!s.
?4EN 8E8.
Rec3c2n<er+-s6r!s : 8EN8.
?4EN 8D8.
Rec3c2n<er+-s6r!s : 8DE8.
?4EN 8F8.
Rec3c2n<er+-s6r!s : 8FR8.
END1ASE.
... "other conversions
ENDFOR*.
!xample of formatting is converting the language %!)@*!5A)Y0$P%A$ from the old format &e.g.
1!1' into the new $AP format &1!"1'.
The formatted language is assigned to the record layout %!)@)"4!%T0$P%A$.
SAP AG BC420 7-23

0.26
SAP AG 1999
&!er!iew ; File Monitor
&!er!iew ; File Monitor
Sequential Files
Sequential Files
Local Sequential Files
Local Sequential Files
Logical File Names
Logical File Names
&!er!iew of Content : Sequential Files =(>
SAP AG BC420 7-24

0.24
SAP AG 1999
1A// F&N1TION
@DO?N/OAD@
1A// F&N1TION
@DO?N/OAD@
1A// F&N1TION
@&P/OAD@
1A// F&N1TION
@&P/OAD@
Con!ersion
aroriate for
file t$e
Con!ersion
aroriate for
for file t$e
.resentation ser!er
File name:
File t$e:
)ownload and Uload
Bsing the function module #/"*A# you can transfer the contents of an internal table to a local
file.
Bsing the function module BP*A# you can transfer the contents from a local sequential file into
an internal table.
!nter the whole file path and name of the local file &e.g. L-tmp-myfileL for a Bnix file and e.g. L)=2
,Y(+*!.TATL for a P) file'.
The presentation server must 3now the directory.
)ustomers can choose an appropriate file name.
The system as3s you for the file name and file type.
The data is then converted into the appropriate file type.
SAP AG BC420 7-25

0.25
SAP AG 1999
C"LL FUNC/0&N G)&,NL&")G
3+.&R/0NH
10NIF0L3S0J3 D Klength of %inar$ fileL
C&)3."H3 D Kdo not useL
F0L3N"M3 D Kdefault file nameL
F0L3/?.3 D Kdefault file t$eL
0/3M D Ktitle of file dialogL
M&)3 D Kwrite modeL
,E8INIF&RM"/ D K!alue column for ,E8 file t$eL
,E8INIS0J3 D Kwidth of !alue column for ,E8 file t$eL
,E8I/IF&RM"/ D Kformat of teAt column for ,E8 file t$eL
,E8I/IS0J3 D Kwidth of teAt column for ,E8 file t$eL
0M.&R/0NH
"C/IF0L3N"M3 D Kfile name : !alue enteredL
"C/IF0L3/?.3 D Kfile t$e : !alue enteredL
F0L3S0J3 D KNum%er of %$tes transferredL
/"1L3S
)"/"I/"1 D K/ransfer ta%le with file contentsL
)&,NL&") Function Module
(or the function module #/"*A# you need an internal table for the data transfer. You can
define this table to fit your data structure and then fill it with your data.
/ith the parameter ,#! you can decide which write mode is used &LAL for extend file, L L for create
new file'.
+f you want, you can specify default values for the file name and file type and enter a title for the file
dialog.
The +,P%T parameters specify the actual values entered by the user for the file name and file type
and also the number of bytes transferred.
+f the function module #/"*A# stores a file under #$, the export parameter )#!PA5!
must be set to L+B,O. The parameter has no other meaning.
All !AP%T+"5 parameters are optional.
+f a binary file is to be created, the file length must be specified. +n this case the transfer table must
consist of one column of type A &hexadecimal numbers'.
SAP AG BC420 7-26

0.22
SAP AG 1999
REPORT s!6bcAB03seC.3.2wnl2!..
T-PES:,EGIN OF rec+y6e>
5unnr /I0E 5n!;-5unnr>
l!n.; /I0E 5n!;-l!n.;>
n!"e; /I0E 5n!;-n!"e;>
s+r!s /I0E 5n!;-s+r!s>
2r+0; /I0E 5n!;-2r+0;>
6s+lD /I0E 5n!;-6s+lD>
END OF rec+y6e.
DATA: i+!b T-PE STANDARD TA,/E OF rec+y6e
?IT4 0E- 5unnr ?IT4 4EADER /INE.
SE/E1T 5unnr l!n.; n!"e; s+r!s 2r+0; 6s+lD
FRO* 5n!; INTO 1ORRESPONDING FIE/DS OF TA,/E i+!b.
1A// F&N1TION 8DO?N/OAD8
TA,/ES
.!+!3+!b : i+!b.
...
3Aamle: )&,NL&")
+n the coding example the $!*!)T commands reads customer data from table D"A: and puts it into
an internal table that has already been defined.
Then the function module #/"*A# stores the internal table on the presentation server.
SAP AG BC420 7-27

0.27
SAP AG 1999
C"LL FUNC/0&N GU.L&")G
3+.&R/0NH
C&)3."H3 D Kdo not useL
F0L3N"M3 D Kdefault file nameL
F0L3/?. D Kdefault file t$eL
0/3M D Ktitle of file dialogL

0M.&R/0NH
F0L3S0J3D D Kfile lengthL

/"1L3S
)"/"I/"1 D K/ransfer ta%le with file contentsL
U.L&") Function Module
(or the function module BP*A# you need an internal table for the data transfer. You can define
this table to fit your data structure at the start of the program.
+f you want, you can specify default values for the file name and file type and enter a title for the file
dialog.
+f the function module BP*A# stores a file under #$, the export parameter )#!PA5! must be
set to L+B,O. The parameter has no other meaning.
SAP AG BC420 7-28

0.29
SAP AG 1999
REPORT s!6bcAB03seC.3u6l2!..
T-PES: ,EGIN OF rec+y6e>
5unnr /I0E 5n!;-5unnr>
l!n.; /I0E 5n!;-l!n.;>
n!"e; /I0E 5n!;-n!"e;>
s+r!s /I0E 5n!;-s+r!s>
2r+0; /I0E 5n!;-2r+0;>
6s+lD /I0E 5n!;-6s+lD>
END OF rec+y6e.
DATA: i+!b +y6e s+!n.!r. +!ble 2f rec+y6e
wi+E 5ey 5unnr.
1A// F&N1TION 8&P/OAD8
TA,/ES
.!+!3+!b : i+!b.
...

/OOP AT i+!b.
?RITE: 9 i+!b-5unnr> i+!b-l!n.;> i+!b-n!"e;FG0H>
i+!b-s+r!sFG0H> i+!b-6s+lD> i+!b-2r+0;FG0H.
END/OOP.
3Aamle: U.L&")
+n the coding example the function module BP*A# reads a local sequential file from the
presentation server and puts it in an internal table that has already been defined.
Then the internal table is output using *P.
SAP AG BC420 7-29

0.(0
SAP AG 1999
&!er!iew ; File Monitor
&!er!iew ; File Monitor
Sequential Files
Sequential Files
Local Sequential Files
Local Sequential Files
Logical File Names
Logical File Names
&!er!iew of Content : Sequential Files =6>
SAP AG BC420 7-30

0.(8
SAP AG 1999
*N(+
NT
,,,
Logical
file name
.h$sical
file name
/usr<sa<trans<BC420_newfile_19990927.txt
):MusrMsaMtransMBC420_newfile_19990927.txt
NJIfileN
In Customizing
Assignment see
transaction FILE
o$ical %ile name
CustomiCing Logical File Name
A common use of logical file names is when archiving of %-. application data using the transaction
1$A%A1. Cowever, logical file names can also be useful for external data transfer programs.
Bsing the platform0independent, logical file name you can specify the file name and menu path
under which files are to be created. According to the operating system used, the physical paths and
file names specified in )ustomiKing &transaction 1(+*!1' are used.
The portability of programs can be implemented using a function module &(+*!@5!T@"A,!'.
SAP AG BC420 7-31

0.(2
SAP AG 1999
Logical .ath and Logical File
8.> )efinition of logical ath
-'.AT$
Demo for lo/, #ath
2.> "ssignment logOcal ath :L h$sical ath
(.> )efinition of logical file
S$ntaA Hrou
h$sical ath
)efinition
.h$sical file
Logical ath
Name
)efinition
Name
W(NDOW0 NT
1trans1mnt12filename3
B456&,txt
-'.AT$
Demo for lo/ical file
-'F(7E
Results with N/ ser!er: 1trans1mnt1B456&,txt
You can create logical paths and files using the )ustomiKing transaction 1(+*!1.
Platform0specific physical path must contain the reserved word H(+*!"A,!I as the placeholder
for the file name. +t may also contain other reserved words 0 see the documentation &(: help'.
SAP AG BC420 7-32

0.((
SAP AG 1999
Reser!ed ,ords
DATE#
-EAR#
*ONT4#
DA-#
3Aamles of reser!ed words=
.h$sical file
Logical ath
)efinition
Name
B456&'2DATE3,txt
-'.AT$
Demo for lo/ical file !ith date
-'F(7E'DATE
Results with N/ Ser!er: 1trans1mnt1B456&'6&&&&689,txt
/hese fields are set
%$ the current
s$stem date
You can used reserved words that are replaced at runtime by current values. These reserved words
are always contained within angle brac3ets.
You can see an overview of all the reserved words in the documentation about logical file names &(:
help'.
SAP AG BC420 7-33

0.(6
SAP AG 1999
DATA: file li5e filen!"e-filein+ern.
...
1A// F&N1TION 8FI/E3GET3NA*E8
EXPORTING
l27ic!l3filen!"e : IJ3FI/E8
I*PORTING
FI/E3NA*E : file
EX1EPTIONS
FI/E3NOT3FO&ND : ;
OT4ERS : B.
IF sy-subrc # 0.
?ri+e: 9 8file n2+ f2un.8. EXIT.
E/SE.
?ri+e: 9 86Eysic!l file isI> file.
ENDIF.
...
(he lo$ical %ile is an
import parameter o% the
%unction module
Dependin$ on the operatin$
system the physical %ile
name is returned
F0L3IH3/IN"M3 Function Module
The file name form is dependent on the operating system. Portable programs can be implemented by
using the function module -IL"_G"'_(A!". This function module provides the physical file
name associated with a specified logical file name. You can find a description of the function module
in the documentation for the (unction Builder &*ibrary of function modules'.
SAP AG BC420 7-34

0.(4
SAP AG 1999
Use the file monitor to monitor files and
directories on the alication ser!er
Use the R3") and /R"NSF3R statements to read
and write to sequential files
Use the uload and download function modules to
read and write to internal ta%les as local
sequential files on the resentation ser!er
Create logical files in CustomiCing and call them
in "1". rograms through the function module
F0L3IH3/IN"M3
?ou are now a%le to:
Sequential Files: Unit Summar$
SAP AG BC420 7-35

".ercise 1
/nit: Se0uential -iles
'opic: 1op2ing a Se0uential *ile *ro+ t3e Application
Server to t3e 4resentation Server
/rite a program that reads a sequential file containing external data
from the application server and writes it to the presentation server
&P)'.
4rogra+: J,1AB03KK31OP-3DE,3TO3P1
Solution: SAP,1AB03SELS31OP-3DE,3TO3P1
/rite ZBC420_##_COPY_DEB_TO_PC to copy source file BC420_DEBI.LEG from the
application server to the presentation server. &e.g. to )=2temp2B)?79@PP@#!B+.*!5'.
The source file containing debtor data can be found in the #+%@C,! directory on the
application server.
)reate the program in the development class ZBC420-##. Bse the function module Download.
The file name of the source file and the target file should be specified as the parameters on the
selection screen.
The parameter for the function module must have a specific data type &see function module
interface'.
The structure of the source file REC_LEGACY can be included into the program using the
include SAPBC420_SEI_DEBI_LEGACYS!R"C.
Tip=
/hen you define the file within the program, the path details may be omitted as the
#+%@C,! directory is automatically used.
SAP AG BC420 7-36

Solution 1
/nit: Se0uential -iles
Solution SA4B145$_S"6S_1O4Y_D"B_'O_41
*&---------------------------------------------------------------------*
*& Report SAPBC420_SEQS_COPY_DEB_TO_PC
*&---------------------------------------------------------------------*
*& Downloads !le "le#a$% de&!tors' to PC *
*&---------------------------------------------------------------------*
REPORT SAPBC420_SEQS_COPY_DEB_TO_PC(
* le#a$% de&!tor - str)$t)re
*+C,-DE sap&$420_se.!_de&!_le#a$%str)$(
* /le w!t0 le#a$% data
para1eters2 as/le"300' t%pe $ de4a)lt 5&$420_de&!(le#56
p$/le t%pe R,7RAP-*,E+A8E de4a)lt
5C29Te1p9BC420_::_DEB*(,E75 lower $ase(
* *nternal ta&le 4or lo$al dataset de/ned w!t0 Ta&le /elds
DATA2 !ta& l!;e STA+DARD TAB,E O REC_,E7ACY
<*T= >EY ;)nnr <*T= =EADER ,*+E(
open dataset as/le !n te?t 1ode(
!4 s%-s)&r$ @A 0(
wr!te2 B 5ERROR2 $o)ld not open /le 56 as/le(
end!4(
* read le#a$% data 4ro1 Appl(-SerCer and download to PC
do(
read dataset as/le !nto re$_le#a$%(
!4 s%-s)&r$ @A 0( e?!t( end!4(
append re$_le#a$% to !ta&(
enddo(
SAP AG BC420 7-37

$lose dataset as/le(
* D)st $0e$; !4 !ta& !s o;a% E
loop at !ta& !nto re$_le#a$%(
wr!te2 B re$_le#a$%(
endloop(
CA,, -+CT*O+ 5DO<+,OAD5
EFPORT*+7
*,E+A8E G p$/le
TAB,ES
DATA_TAB G !ta&
EFCEPT*O+S
*+HA,*D_*,ES*IE G 3
*+HA,*D_TAB,E_<*DT= G 2
*+HA,*D_TYPE G J
+O_BATC= G 4
-+>+O<+_ERROR G K
7-*_RE-SE_*,ETRA+SER G L
OT=ERS G M(
* SY-S-BRC @A 0(
8ESSA7E *D SY-8S7*D TYPE SY-8S7TY +-8BER SY-8S7+O
<*T= SY-8S7H3 SY-8S7H2 SY-8S7HJ SY-8S7H4(
E+D*(
SAP AG BC420 7-38

".ercise 5
/nit: Se0uential -iles
'opic: 1op2ing a Se0uential -ile *ro+ t3e 4resentation
Server to t3e Application Server
/rite a program that reads a sequential file containing external data
from the presentation server &P)' and writes it to the application
server.
4rogra+: J,1AB03KK31OP-3DE,3TO3AS
Solution: SAP,1AB03SELS31OP-3DE,3TO3AS
/rite program ZBC420_##_COPY_DEB_TO_AS to copy source file BC420_##_DEBI.LEG
from the presentation server to the application server.
You should find source file B)?79@PP@#!B+.*!5 in directory 1)=2temp21 on the presentation
server &see exercise :'. +f you cannot find it, you can create it there using program
SAPBC420_SEQS_COPY_DEB_TO_PC.
)reate the program in the development class ZBC420-##. Bse the function module "pload.
The file name of the source file and the target file should be specified as parameters on the
selection screen.
The parameter for the function module must have a specific data type &see function module
interface'.
The structure of the source file REC_LEGACY can be included in the program using the
include SAPBC420_SEI_DEBI_LEGACYS!R"C.
#isplay the file in the file monitor &Al::'.
Tip=
/hen you define the file within the program, the path details may be omitted as the
#+%@C,! directory is automatically used.
SAP AG BC420 7-39

Solution 5
/nit: Se0uential -iles
Solution SA4B145$_S"6S_1O4Y_D"B_'O_AS
*&---------------------------------------------------------------------*
*& Report SAPBC420_SEQS_COPY_DEB_TO_AS *
*&---------------------------------------------------------------------*
*& Trans4ers !le 4ro1 PC to Appl!$at!on SerCer *
*&---------------------------------------------------------------------*
REPORT SAPBC420_SEQS_COPY_DEB_TO_AS(
* le#a$%-/le str)$t)r
!n$l)de SAPBC420_SEQ*_DEB*_,E7ACYSTR-C(
* /le de/n!t!ons
PARA8ETERS2 as/le"300' TYPE $ DEA-,T 5&$420_::_de&!(le#56
p$/le t%pe R,7RAP-*,E+A8E
DEA-,T 5C29Te1p9&$420_::_de&!(le#5(
* *nternal ta&le 4or lo$al dataset de/ned w!t0 Ta&le /elds
DATA2 !ta& ,*>E STA+DARD TAB,E O re$_le#a$%
<*T= >EY ;)nnr <*T= =EADER ,*+E(
* -pload t0e data 4ro1 t0e PC !nto t0e !nternal ta&le !ta&
CA,, -+CT*O+ 5-P,OAD5
EFPORT*+7
/lena1e G p$/le
TAB,ES
data_ta& G !ta&
EFCEPT*O+S
$onCers!on_error G 3
!nCal!d_ta&le_w!dt0 G 2
!nCal!d_t%pe G J
no_&at$0 G 4
)n;nown_error G K
#)!_re4)se_/letrans4er G L
SAP AG BC420 7-40

OT=ERS G M(
* s%-s)&r$ @A 0(
<R*TE2 B 5Co)ld not )pload t0e /le 4ro1 PC5( EF*T(
E+D*(
* open t0e /le on t0e Apl!$at!on-SerCer to trans4er data
OPE+ DATASET as/le OR O-TP-T *+ TEFT 8ODE(
* s%-s)&r$ @A 0(
<R*TE2 B 5ERROR2 $o)ld not open /le 56 as/le( EF*T(
E+D*(
* read $ontent o4 !ta& and saCe !t to Appl!$at!on-SerCer
,OOP AT !ta& *+TO re$_le#a$%(
TRA+SER re$_le#a$% TO as/le(
<R*TE2 B re$_le#a$%(
E+D,OOP(
SAP AG BC420 7-41

".ercise 7
/nit: Se0uential -iles
'opic: ,or&ing %it3 Se0uential -iles 8 1reating a
1onversion 4rogra+ *or Debtor Data
/riting of a program that reads a sequential file with legacy data, that
converts the legacy data to the record layout format and then writes in
an output file.
The data transfer from the #A0/B must be started with this output
file. The result is a B+ session, which is run later.
The analysis of the transfer process to be selected, as well as the analysis
of the $AP record layout structures has been completed.
You should write a conversion program now, in order to convert the
legacy data in the $AP record layout format.
4rogra+: J,1AB03KK31ON=ERT3DE,I
'e+plate progra+: SAP,1AB03SELT31ON=ERT3DE,I; 2r
SAP,1AB03SELT31ON=ERT3DE,IB
Solution: SAP,1AB03SELS31ON=ERT3DE,I
: /rite a program J,1AB03KK31ON=ERT3DE,I to import and convert legacy debtors
in the source file BC420_##_DEBI.LEG.
The path is automatically generated in the template program and must not be especially
set. (ile BC420_##_DEBI.SAP should be written as the output file.
Tips=
The necessary source and target structures are already set in +")*B#! files, too.
There are two template programs. You should use one of them as a template for your
solution.
SAPBC420_SEQT_CONVERT_DEBI1 contains a large number of notes concerning the
statements that are still missing. Please complete them.
SAPBC420_SEQT_CONVERT_DEBI2 contains fewer statements and therefore should
be used by participants with a sound 3nowledge of ABAP.
:0: The opening and closing of the sequential files is specified according to the
template program &the data variables in#il$% o&'#il$ and $((#il$ are already
predefined with the matching path and can be used directly'.
:07 (orm routines to initialiKe and fill the record layouts are already prepared and
partly contain coding. Please complete the coding.
SAP AG BC420 7-42

:0. %ead the legacy data in a loop. Build the record layout structures in this loop.
$ave the record layout structures in the target file.
+ncorrect records are records in which the old debtor number has not been filled
in &filled with a blan3 character'. /rite these incorrect records in the error file.
:0.0: You have to format some fields before you assign them to the record
layout fields=
:0.07 Assign the old debtor number to the field BD"B:0A*TD". )reate the
debtor in the system with a new legacy number. The new number should
be a reformatted :90digit debtor number. Bse 19:;;:51 as a prefix.
Because of the predefined variable aux3unnr&:9', this has already been
performed. (ill in the last four digits of this new debtor number using the
loop index $Y0+"#!A &numbers 999:099:9 are supplied via a wor3 field
"B,'. This is how the following debtor numbers are created= 9:;;:
5$$$1 to 9:;;:5$$1$.
:0.0. (or another formatting example change the language 3ey &$AP language
is 7 digits'. C+"T= Bse or write a form routine C)*+ER!_LA*G"AGE%
in which the language 3ey is converted in a )A$! statement.
Add the following languages= #0I#!, (0I(%, $0I!$, Q0IQA,
!0I!".
:0? /hen the program has been created, chec3 the structure of your record layout file
with the A*:: and the #A0/B.
7 )reate a new run with two tas3s under your subproEect=
ProEect name= &s$ old p(o,$-'.
$ubproEect name= &s$ old s&.p(o,$-'.
%un definition name= BI-##% '(ans#$( d$.'o(s
70: To be able to use your own programs in the #A0/B, you have to register them
first. %egister your program RB)?79@PP@)"4!%T@#!B+ as tas3 type ,AP
under the program type %!P.
707 )reate the following tas3=
Technical name = /ap-##.
#escription= ,ap debtors
Tas3 type= ,AP
$elect your mapping program from &the program type %!P'S
70. )reate the following tas3=
Technical name = D$.i-##-load.
#escription= *oad debtors
Tas3 type= *A
$elect the standard transfer program %(B+#!99 with program type B+"P.
70? $tart the run and analyKe the flow trace.
+mportant= /hen you perform the tas3 *A, chec3 the file fTrst &flag
chec3box'. +f there is no termination situation discovered, the session can be
created.
70< Process the batch input session with the B+ ,onitor.
SAP AG BC420 7-43

Solution 7
/nit: Se0uential -iles
Solution SA4B145$_S"6S_1O(#"R'_D"BI
*&---------------------------------------------------------------------*
*& Report SAPBC420_SEQS_CO+HERT_DEB* *
*&---------------------------------------------------------------------*
*& So)r$e /le $onta!ns de&!tors !n le#a$% 4or1at( *
*& T0!s data !s $onCerted !nto SAP re$ord la%o)t 4or1at 4or data *
*& trans4er w!t0 RB*DE00 *
*&---------------------------------------------------------------------*
REPORT sap&$420_se.s_$onCert_de&! 8ESSA7E-*D &$420 ,*+E-S*IE 200(
TAB,ES2 &#r006 &;n006 &;na36 &;n&3(
* !n$l)de $onta!ns str)$t)r o4 /le w!t0 SAP-4or1atted data
*+C,-DE sap&$420_se.!_de&!_le#a$%str)$(
*+C,-DE &$420_/ll_nodata(
* 0elp str)$t)re "str)$t)re e.)als B>+00'
DATA &;n00_nodata ,*>E &;n00(
* 0elp str)$t)re "str)$t)re e.)als B>+A3'
DATA &;na3_nodata ,*>E &;na3(
* 0elp str)$t)re "str)$t)re e.)als B>+B3'
DATA &;n&3_nodata ,*>E &;n&3(
DATA2 n)1"4' TYPE n6
te?t"300'(
PARA8ETERS2
new;)nnr"30' DEA-,T 5I-::-256 Nw!ll &e new de&!tor-no(
!n/le"M0' de4a)lt 5BC420_DEB*(,E75 ,O<ER CASE6
o)t/le3"M0' de4a)lt 5BC420_::_DEB*(SAP5 ,O<ER CASE6
err/le"M0' de4a)lt 5BC420_::_DEB*(ERR5 ,O<ER CASE6
sess!on"20' DEA-,T 5BC420SES-::5 ,O<ER CASE6
nodata DEA-,T 5B5 ,O<ER CASE(
AT SE,ECT*O+-SCREE+(
SAP AG BC420 7-44

*--------------------
* open /les
OPE+ DATASET2 !n/le OR *+P-T *+ TEFT 8ODE 8ESSA7E te?t(
* s%-s)&r$ +E 0(
8ESSA7E e303 <*T= !n/le(
E+D*(
OPE+ DATASET2 o)t/le3 OR O-TP-T *+ TEFT 8ODE 8ESSA7E te?t(
* s%-s)&r$ +E 0(
8ESSA7E e300 <*T= o)t/le3(
E+D*(
OPE+ DATASET2 err/le OR O-TP-T *+ TEFT 8ODE 8ESSA7E te?t(
* s%-s)&r$ +E 0(
8ESSA7E e300 <*T= err/le(
E+D*(
START-O-SE,ECT*O+(
*-------------------
* /ll str)$t)re w!t0 nodata
PEROR8 !n!t -S*+7 &;n00_nodata nodata(
PEROR8 !n!t -S*+7 &;na3_nodata nodata(
PEROR8 !n!t -S*+7 &;n&3_nodata nodata(
* /ll str)$t)re &#r00
PEROR8 /ll_&#r00(
* wr!te data to /le
TRA+SER &#r00 TO o)t/le3(
<R*TE B &#r00(
* /ll str)$t)re &;n006 &;na3 and &;n&3
DO(
READ DATASET !n/le *+TO re$_le#a$%(
* s%-s)&r$ +E 0( EF*T( E+D*(
N O)st to do so1e $leans!n# o4 le#a$% dataE
* re$_le#a$%-;)nnr *S *+*T*A,(
TRA+SER re$_le#a$% TO err/le(
<R*TE2 B te?t-0036 re$_le#a$%-;)nnr(
E,SE( N re$ord !s o;a% E
8OHE &;n00_nodata TO &;n00(
PEROR8 /ll_&;n00(
8OHE &;na3_nodata TO &;na3(
PEROR8 /ll_&;na3(
8OHE &;n&3_nodata TO &;n&3(
PEROR8 /ll_&;n&3(
SAP AG BC420 7-45

N wr!te data to /le
TRA+SER2 &;n00 TO o)t/le36
&;na3 TO o)t/le36
&;n&3 TO o)t/le3(
<R*TE2 B te?t-0026 re$_le#a$%-;)nnr(
<R*TE2 te?t-00J6 &;n00-;)nnr(
E+D*(
E+DDO(
* $lose /les
C,OSE DATASET2 !n/le6 o)t/le36 err/le(
*&---------------------------------------------------------------------*
*& or1 *,,_B7R00
* /ll str)$t)re &#r00
*----------------------------------------------------------------------*
OR8 /ll_&#r00(
8OHE2 505 TO &#r00-st%pe6
sess!on TO &#r00-#ro)p6
s%-1andt TO &#r00-1andt6
s%-)na1e TO &#r00-)sna16
nodata TO &#r00-nodata6
5F5 TO &#r00-?;eep(
E+DOR8( N *,,_B7R00
*&---------------------------------------------------------------------*
*& or1 *,,_B>+00
*& /ll str)$t)re &;n00
*& +ew de&!tor-n)1&ers are $reatedP t0e% start w!t0 NI-::-3N
*& t0e old de&!tor n)1&er !s $on$atenated --A NI-::-3????N
*----------------------------------------------------------------------*
OR8 /ll_&;n00(
8OHE2 535 TO &;n00-st%pe6
5FD035 TO &;n00-t$ode6
500035 TO &;n00-&);rs6
5>-+A5 TO &;n00-;to;d(
n)1 G s%-!nde?( Ns%-!nde? !s set !n DO-E+DDO-,oop
8OHE n)1 TO new;)nnrQL"4'( N1oCe new n)1&er
8OHE new;)nnr TO &;n00-;)nnr(
E+DOR8( N *,,_B>+00
*&---------------------------------------------------------------------*
*& or1 *,,_B>+A3
* /ll str)$t)re &;na3
SAP AG BC420 7-46

*----------------------------------------------------------------------*
OR8 /ll_&;na3(
8OHE2 525 TO &;na3-st%pe6
5B>+A35 TO &;na3-t&na16
re$_le#a$%-na1e3 TO &;na3-na1e36
re$_le#a$%-sortl TO &;na3-sortl6
re$_le#a$%-stras TO &;na3-stras6
re$_le#a$%-ort03 TO &;na3-ort036
re$_le#a$%-pstlR TO &;na3-pstlR6
re$_le#a$%-land3 TO &;na3-land36
re$_le#a$%-tel43 TO &;na3-tel43(
PEROR8 $onCert_lan#)a#e( ND-ADEP E-AE+ and so on
* re$_le#a$%-st$e# *S *+*T*A,(
8OHE nodata TO &;na3-st$e#(
E,SE(
8OHE re$_le#a$%-st$e# TO &;na3-st$e#(
E+D*(
E+DOR8( N *,,_B>+A3
*&---------------------------------------------------------------------*
*& or1 *,,_B>+B3
* /ll str)$t)re &;n&3
*----------------------------------------------------------------------*
OR8 /ll_&;n&3(
8OHE2 525 TO &;n&3-st%pe6
5B>+B35 TO &;n&3-t&na16
53200005 TO &;n&3-a;ont6
re$_le#a$%-;)nnr TO &;n&3-alt;n(
* wr!te2 B 5Alte +)11er G 56 re$_le#a$%-;)nnr(
E+DOR8( N *,,_B>+B3
SAP AG BC420 7-47

*---------------------------------------------------------------------*
* OR8 ConCert_lan#) *
*---------------------------------------------------------------------*
OR8 $onCert_lan#)a#e(
CASE re$_le#a$%-spras(
<=E+ 5E5(
&;na3-spras G 5E+5(
<=E+ 5D5(
&;na3-spras G 5DE5(
<=E+ 55(
&;na3-spras G 5R5(
<=E+ 5S5(
&;na3-spras G 5ES5(
<=E+ 5D5(
&;na3-spras G 5DA5(
E+DCASE(
E+DOR8(
SAP AG BC420 7-48

Das könnte Ihnen auch gefallen