the sapftp library - ftp programming in abap
TRANSCRIPT
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 127
The SAPFTP Library - FTP Programming in ABAPSkip to end of metadata
bull Created by Fahad Javed last modified on ov $
ampo to start of metadata
The SAPFTP Library - FTP Programming in ABAPThis artile is dediated to FTP Programming in ABAP( )t o+ld onsist of both bakgro+nd and front-end transfer of files via
FTP(
Applies to
ABAP
Summary
This artile is dediated to FTP Programming in ABAP( )t o+ld onsist of both bakgro+nd and front-end transfer of files via
FTP(
Author Fahad Javed
Created on th Jan+ary $
Table of Contents
bull The SAPFTP Library - FTP Programming in ABAP
bull Applies to
bull S+mmary
bull A+thor Fahad Javed
bull )ntro
bull List of all F+ntion od+les in the SFTP F+ntion ampro+p
bull For reating 0FC 1estinations for FTP omm+niations
bull For testing the 0FC destinations
bull For heking the Trae of the FTP omm+niation
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 227
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
bull Sample program for onneting from an SAP Server to an FTP server3Senario Type 4 Front5nd6
bull 7A82ploading a te9t file from an SAP system to an FTP Server ith SAP 1ata
bull So+re Code for 2ploading a te9t file to an FTP Server based on 1ATA from the SAP System3Front5nd6
bull 7B80eading a te9t file from an FTP Server bak to an SAP System
bull So+re Code for 0eading a te9t file from an FTP Server into the SAP System3Front5nd6
bull 7C81eleting a file from an FTP Server
bull So+re Code for 1eleting a te9t file from an FTP Server via the FTPCA1 F+ntion od+le3Front5nd6
)ntro
FTP7FileTransferProtool8 is a netork protool b+ilt on top of the TCPlt)P protoolalloing transfer of files beteen to host
mahinesover the netork( FTP is +sed for Appliation-to-appiation7AA8 or B+siness-to-b+siness7BB8 senarios(
SAP provides a b+ilt in lient library alled SAPFTP Library( )t has to parts
Part A Exeutable File
59e+table file alled SAPFTPhih is installed on the SAP eteaver AS Abap =ostas ell as installed on any lient as
part of the SAP amp+i lient installation(
Figure SAPFTPexe file as part of
the SAP GUI Installation
Part The SAPFTP library
These are a set of 0FC enabled f+ntion mod+leshih are provided in a F+ntion ampro+p named SFTP( These F+ntion
od+les aess the 59e+table via 0FC to onnet to an FTP host and for e9e+ting vario+s ommands( SAPFTP library
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 327
implements FTP aording to the FC $ speifiation( gto+ an find more indepth information regarding 0FC
speifiation +sing the folloing link httpltlt(ietf(orgltrfltrf(t9t (
List of all F+ntion od+les in the SFTP F+ntion ampro+p
The F+ntion gro+p SFTP is the SAPFTP library that onsists of the folloing f+ntion mod+les for FTP programming
SNo Function Module escription
01 FTP_CLIENT_TO_R3
02 FTPMMAN Execute FTP Command
03 FTP_COMMAND_LIST
04 FTPNN$T Connect to an FTP ee
0 FTP_COP$ FTP Coamp
0 FTPISNN$T D(connect )om FTP ee
0 FTP_R3_TO_CLIENT
0+ FTPampTS$$ SAP to FTP See Commun(cat(on
0 FTPS$$Tamp FTP See to SAP Commun(cat(on
10 FTP_START_RE-_SERER
11 FTP_START_SAPFTP
12 FTP_STOP_RE-_SERER
13 FTP_ERSION Pocue SAPFTP e(on
14 TTP_ASE4_ENCODE ae4 encode t(n
1 TTP_-ET TTP -et
1 TTP_-ET_FILE TTP -et F(e
1 TTP_-ET_FILES TTP -et F(e
1+ TTP_-ET_FILES_2 TTP -et F(e
1 TTP_-ET_FILE_DP TTP -et F(e
20 TTP_-ET_FILE_E
21 TTP_POST TTP ot
22 TTP_POST_DOC5MENT
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 427
SNo Function Module escription
23 TTP_POST_DOC5MENTS
24 TTP_POST_DOC5MENT_2
2 TTP_POST_FILES TTP Pot F(e
2 TTP_POST_FILES_2 TTP Pot F(e
2 TTP_POST_FILE_E
2+ TTP_PRO$_CONFI-
2 TTP_P5T_COMPONENT
30 TTP_P5T_FILE
31 TTP_P5T_FILE_DP
32 (TTPSAM)$ Fo Encampt(n Pa6od
33 TTP_ERSION Pocue SAPTTP e(on
Some +sef+l f+ntion mod+les that are part of the SAPFTP Library inl+de
ampFTP(C)ECT
2sed for onneting to an FTP hostret+rns a handle that is +sed to bind s+bse+ent ommands to the session(
Syntax
CALL F2CT) FTP(C)ECT
5P0T)amp
DAL2572S508 TgtP5 C
DAL257PASSE018 TgtP5 C
DAL257ACC2T8 TgtP5 C PT)AL
DAL257=ST8 TgtP5 C
DAL2570FC15ST)AT)8 L)5 0FC15S-0FC15ST
DAL257ampAT5EAgt2S508 TgtP5 C PT)AL
DAL257ampAT5EAgtPASSE018 TgtP5 C PT)AL
DAL257ampAT5EAgt=ST8 TgtP5 C PT)AL
)P0T)amp
DAL257=A1L58 TgtP5 )
5C5PT)S
TC5CT51
Example
CALL F2CT) FTP(C)ECT
5P0T)amp
2S50 4 lv+serThis user name is ase sensitive
PASSE01 4 lvpassord+This passord ould also be srambled via the -TTP(SCALE funtion
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 527
module
=ST 4 lvhostip+P Address of the host FTP Server012n ase of Server host name3it is ase sensitive
0FC15ST)AT) 4 SAPFTPA or SAPFTP +SAPFTPA 4 for ba56round aess to FTP -ost server or
SAPFTP 4 for front end aess to FTP Server
)P0T)amp
=A1L5 4 =A1L5+For performin6 subse7uent operations for the onneted FTP Session
5C5PT)S
TC5CT51 4 +FTP onnetion failed
T=50S 4 (
8FTP(C)A9
2sed to e9e+te an FTP ommand on the FTP host( For a omplete list of s+pported FTP ommands on an FTP hostyo+
an e9e+te the help ommand( Some of the ommands inl+des the likes of P97for Printing the ontents of the C+rrent
Eorking 1iretory8ltT7For Logging o+t the +ser +rrently onneted to the FTP server via the FTPC5CT f+ntion
mod+le8 e(t((
=FTP(=(T)(CLET
2sed to transfer a file don to the front-end(
gtFTP(CLET(T)(=
2sed to +pload a file from the front-end(
$FTP(=(T)(SEE
2sed to +pload a file to the FTP host(
FTP(SEE(T)(=
2sed to donload a file from the FTP host(
FTP(9SC)ECT
2sed to disonnet from an FTP host(
BFC(C)ECT)(CL)SE
For 1isonneting 0FC onnetion beteen SAP and FTP(
Example
CALL F2CT) 0FCC5CT)CLS5
5P0T)amp
destination 4 lrfdest0FC 1estination host(e(gSAPFTPA
5C5PT)S
T=50S 4 (
For reating 0FC 1estinations for FTP omm+niations
gto+ need to reate 0FC destinations for FTP omm+niations( There is a standard report for that p+rpose alled
SFTP$7SAPFTP hek8
instead of onfig+ring it man+ally via the transation S$7Config+rations of 0FC onnetions8it a+tomatially reates the
folloing to 0FC destinations
78SAPFTP7For invoking the 0FC library on the SAP amp2) frontend8
78SAPFTPA7For invoking the 0FC library on the SAP eteaver AS ABAP host8
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 627
Figure + A SAP Standard Progra
-SFTP0 for Generation of F
estinations SAPFTP and SAPFTPA
Figure + ) Generated F estinations
SAPFTP and SAPFTPA as sho1n
in Transaction SM2
For testing the 0FC destinations
After setting +p the 0FC destinationsyo+ an hek the folloing report for testing them
SFTP8759e+te FTP Command8( =ere yo+ enter in the redentials7hih inl+des fields like
ltser Passord-ostFC 9estination8( )n order to test ommands yo+ enter in a ommand s+h as helpthat
displays a list of all ommands that an be entered in the ommand field(
Figure Standard Progra for Testing
FTP ounications -SFTP30
For heking the Trae of the FTP omm+niation
gto+ an +se the report SFTPamphih displays the trae of the FTP omm+niationsprovided traing has been enabled
for BT= 0FC destinations SAPFTP and SAPFTPA in Transation S$( This report not only tells yo+ abo+t all
ommands and interation b+t also informs abo+t attrib+tes s+h as the orking diretorySAPFTP e9e+table file path for
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 727
eah of the 0FC destinations mentioned above7SAPFTP and SAPFTPA8( 5nabling Traing generates a trae file in the SAP
amp2) Eorking diretory ith the name dev(rf7For +ni98 and rf(tr7Eindos 8(
Figure Standard SAP Progra
-SFTP40for tracing F
estinations SAPFTP 5 SAPFTPA
Setting 2p an FTP Server
Before yo+ an +se the SAPFTP library AP)syo+ ill first need to set +p an FTP Server at least loally to test the e9amples
that ill be reated in the +poming setions( Ee ill be +sing a free FTP Server alled FileDilla Server and an FTP lient
alled FileDilla Client for aessing the FTP Server( Both of these softare pakages an be donloaded from the
folloing 20L
httpltltfileGilla-proHet(orglt
J+st lik on the 7ui5 donload lin5s area on the ain Page or donload both the server and the lient from the
9onload setion on the left for FileDilla and FileDilla Server setions respetively( See the sreenshot belo
Figure Site for o1loading FTP
Ser6er 5 FTP lient
After 1onloading the FileServer e9e+table file7in o+r ase it is FileDilla(Server((gtamp2exe8( 1o+ble Clik the installer to
ikstart the )nstallation proed+re( Clik the ) Agree b+tton to Agree to the terms of the liense and move forard to the
ne9t step( )n the e9t sreen7Choose Components8 selet all options apart from the Soure Code option( o Clik the
extb+tton hoose the )nstallation folder here the FTP Server ill be deployed and here all FTP )nterations ill takeplae( o the ne9t sreen7Startup Settin6s8 is the most important sreen in the set+p iGardas here yo+ ill need to
provide the Port umber For hih the FTP Server admin interfae ill listen to( in the Please Choose ho FileDilla
Server should be started drop donhoose either nstall as Servie3started ith indos default 7This ill start the
FTP Servie eah time yo+ start +p System8 or hoose nstall as Servie3started manually7To )nstall as a Serviehere
yo+ ill need to start it man+ally by providing the Admin logon redentials8(
otes
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 827
I gto+ an man+ally start or stop the FTP Server servie by making +se of the Servies snap-in hih an be aessed by
pressing 3indo 6 typing in servies2ms and hoosing FileDilla Server FTP server from the list of servies by
making +se of the playpa+se and stop b+ttons in the appliation toolbar( )n ase yo+ have set the )nstall as a Servie and
set it as man+alyo+ ill need to start that servie +sing method as mentioned abovether ise yo+ ont be able to
onnet to the FTP Server(
I 1o keep in mindthat the port assigned m+st have privileges to be alloed for its omm+niation( This an be set bysetting the P)T number in the Exeptions settings of yo+r fireall program( 1o also keep in mind that yo+ dont assign a
port n+mber that is +sed for other servies in Eindos(
e9t in the Startup settin6s selet the options that ill appliable to indo +sers and lik the install b+tton( after
)nstallationlik the lose b+tton(
Figure Installation-A0 + icense
Agreeent
Figure Installation-)0 + hoose
oponents
Figure Installation-0 + hoose
Install ocation
Figure Installation-0 + Startup
Settings-A0
Figure Installation-$0 + Startup
Settings-)0
e9t yo+ ill need to start the SAP FTP Server( gto+ an la+nh it by folloing the men+ path
indo menu G All Pro6rams G File Dilla FTP Server G File Dilla Server nterfae
gto+ ill be prompted ith a Connet to Server pop +p dialog bo9( Provide the Server Address7)P8Port +mber as set
d+ring installation and the Administrator Passord7by defa+lt it is admin8(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 927
Figure Installation-F0 + onnecting
to the FTP Ser6er Interface
Figure Installation-G0 + ogged in to
the FTP Ser6er
Creating a 2ser in the FTP Server
gto+ ill need to reate a +ser in the FTP Server in order to onnet and perform file transfer operations in SAP( To reate a
+seryo+ ill need to first reate a Hroup and then reate a +ser and assign it to that ampro+p(
)n order to reate a gro+pgo to the men+ path
Edit G Hroups
Then lik the Add b+tton to add a ampro+pgive it a name and then lik the )I b+tton( e9t e ill reate a ltser by
+sing the folloing men+ path
Edit G ltsers
Then lik the Add b+tton and provide the +ser name and +ser gro+preated in the previo+s step and lik )I and then
lik the )5 b+tton again to reate the +ser( Also hek the Passord hekbo9 and assign a passord to the +serhih
ill be re+ired for aessing it via the FTP Client Softare(
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Figure -0 + reating a User Figure -$0 + Adding a User to a
Group
Figure -F0 + Adding Pass1ord
to a User
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 227
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
bull Sample program for onneting from an SAP Server to an FTP server3Senario Type 4 Front5nd6
bull 7A82ploading a te9t file from an SAP system to an FTP Server ith SAP 1ata
bull So+re Code for 2ploading a te9t file to an FTP Server based on 1ATA from the SAP System3Front5nd6
bull 7B80eading a te9t file from an FTP Server bak to an SAP System
bull So+re Code for 0eading a te9t file from an FTP Server into the SAP System3Front5nd6
bull 7C81eleting a file from an FTP Server
bull So+re Code for 1eleting a te9t file from an FTP Server via the FTPCA1 F+ntion od+le3Front5nd6
)ntro
FTP7FileTransferProtool8 is a netork protool b+ilt on top of the TCPlt)P protoolalloing transfer of files beteen to host
mahinesover the netork( FTP is +sed for Appliation-to-appiation7AA8 or B+siness-to-b+siness7BB8 senarios(
SAP provides a b+ilt in lient library alled SAPFTP Library( )t has to parts
Part A Exeutable File
59e+table file alled SAPFTPhih is installed on the SAP eteaver AS Abap =ostas ell as installed on any lient as
part of the SAP amp+i lient installation(
Figure SAPFTPexe file as part of
the SAP GUI Installation
Part The SAPFTP library
These are a set of 0FC enabled f+ntion mod+leshih are provided in a F+ntion ampro+p named SFTP( These F+ntion
od+les aess the 59e+table via 0FC to onnet to an FTP host and for e9e+ting vario+s ommands( SAPFTP library
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 327
implements FTP aording to the FC $ speifiation( gto+ an find more indepth information regarding 0FC
speifiation +sing the folloing link httpltlt(ietf(orgltrfltrf(t9t (
List of all F+ntion od+les in the SFTP F+ntion ampro+p
The F+ntion gro+p SFTP is the SAPFTP library that onsists of the folloing f+ntion mod+les for FTP programming
SNo Function Module escription
01 FTP_CLIENT_TO_R3
02 FTPMMAN Execute FTP Command
03 FTP_COMMAND_LIST
04 FTPNN$T Connect to an FTP ee
0 FTP_COP$ FTP Coamp
0 FTPISNN$T D(connect )om FTP ee
0 FTP_R3_TO_CLIENT
0+ FTPampTS$$ SAP to FTP See Commun(cat(on
0 FTPS$$Tamp FTP See to SAP Commun(cat(on
10 FTP_START_RE-_SERER
11 FTP_START_SAPFTP
12 FTP_STOP_RE-_SERER
13 FTP_ERSION Pocue SAPFTP e(on
14 TTP_ASE4_ENCODE ae4 encode t(n
1 TTP_-ET TTP -et
1 TTP_-ET_FILE TTP -et F(e
1 TTP_-ET_FILES TTP -et F(e
1+ TTP_-ET_FILES_2 TTP -et F(e
1 TTP_-ET_FILE_DP TTP -et F(e
20 TTP_-ET_FILE_E
21 TTP_POST TTP ot
22 TTP_POST_DOC5MENT
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 427
SNo Function Module escription
23 TTP_POST_DOC5MENTS
24 TTP_POST_DOC5MENT_2
2 TTP_POST_FILES TTP Pot F(e
2 TTP_POST_FILES_2 TTP Pot F(e
2 TTP_POST_FILE_E
2+ TTP_PRO$_CONFI-
2 TTP_P5T_COMPONENT
30 TTP_P5T_FILE
31 TTP_P5T_FILE_DP
32 (TTPSAM)$ Fo Encampt(n Pa6od
33 TTP_ERSION Pocue SAPTTP e(on
Some +sef+l f+ntion mod+les that are part of the SAPFTP Library inl+de
ampFTP(C)ECT
2sed for onneting to an FTP hostret+rns a handle that is +sed to bind s+bse+ent ommands to the session(
Syntax
CALL F2CT) FTP(C)ECT
5P0T)amp
DAL2572S508 TgtP5 C
DAL257PASSE018 TgtP5 C
DAL257ACC2T8 TgtP5 C PT)AL
DAL257=ST8 TgtP5 C
DAL2570FC15ST)AT)8 L)5 0FC15S-0FC15ST
DAL257ampAT5EAgt2S508 TgtP5 C PT)AL
DAL257ampAT5EAgtPASSE018 TgtP5 C PT)AL
DAL257ampAT5EAgt=ST8 TgtP5 C PT)AL
)P0T)amp
DAL257=A1L58 TgtP5 )
5C5PT)S
TC5CT51
Example
CALL F2CT) FTP(C)ECT
5P0T)amp
2S50 4 lv+serThis user name is ase sensitive
PASSE01 4 lvpassord+This passord ould also be srambled via the -TTP(SCALE funtion
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 527
module
=ST 4 lvhostip+P Address of the host FTP Server012n ase of Server host name3it is ase sensitive
0FC15ST)AT) 4 SAPFTPA or SAPFTP +SAPFTPA 4 for ba56round aess to FTP -ost server or
SAPFTP 4 for front end aess to FTP Server
)P0T)amp
=A1L5 4 =A1L5+For performin6 subse7uent operations for the onneted FTP Session
5C5PT)S
TC5CT51 4 +FTP onnetion failed
T=50S 4 (
8FTP(C)A9
2sed to e9e+te an FTP ommand on the FTP host( For a omplete list of s+pported FTP ommands on an FTP hostyo+
an e9e+te the help ommand( Some of the ommands inl+des the likes of P97for Printing the ontents of the C+rrent
Eorking 1iretory8ltT7For Logging o+t the +ser +rrently onneted to the FTP server via the FTPC5CT f+ntion
mod+le8 e(t((
=FTP(=(T)(CLET
2sed to transfer a file don to the front-end(
gtFTP(CLET(T)(=
2sed to +pload a file from the front-end(
$FTP(=(T)(SEE
2sed to +pload a file to the FTP host(
FTP(SEE(T)(=
2sed to donload a file from the FTP host(
FTP(9SC)ECT
2sed to disonnet from an FTP host(
BFC(C)ECT)(CL)SE
For 1isonneting 0FC onnetion beteen SAP and FTP(
Example
CALL F2CT) 0FCC5CT)CLS5
5P0T)amp
destination 4 lrfdest0FC 1estination host(e(gSAPFTPA
5C5PT)S
T=50S 4 (
For reating 0FC 1estinations for FTP omm+niations
gto+ need to reate 0FC destinations for FTP omm+niations( There is a standard report for that p+rpose alled
SFTP$7SAPFTP hek8
instead of onfig+ring it man+ally via the transation S$7Config+rations of 0FC onnetions8it a+tomatially reates the
folloing to 0FC destinations
78SAPFTP7For invoking the 0FC library on the SAP amp2) frontend8
78SAPFTPA7For invoking the 0FC library on the SAP eteaver AS ABAP host8
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 627
Figure + A SAP Standard Progra
-SFTP0 for Generation of F
estinations SAPFTP and SAPFTPA
Figure + ) Generated F estinations
SAPFTP and SAPFTPA as sho1n
in Transaction SM2
For testing the 0FC destinations
After setting +p the 0FC destinationsyo+ an hek the folloing report for testing them
SFTP8759e+te FTP Command8( =ere yo+ enter in the redentials7hih inl+des fields like
ltser Passord-ostFC 9estination8( )n order to test ommands yo+ enter in a ommand s+h as helpthat
displays a list of all ommands that an be entered in the ommand field(
Figure Standard Progra for Testing
FTP ounications -SFTP30
For heking the Trae of the FTP omm+niation
gto+ an +se the report SFTPamphih displays the trae of the FTP omm+niationsprovided traing has been enabled
for BT= 0FC destinations SAPFTP and SAPFTPA in Transation S$( This report not only tells yo+ abo+t all
ommands and interation b+t also informs abo+t attrib+tes s+h as the orking diretorySAPFTP e9e+table file path for
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 727
eah of the 0FC destinations mentioned above7SAPFTP and SAPFTPA8( 5nabling Traing generates a trae file in the SAP
amp2) Eorking diretory ith the name dev(rf7For +ni98 and rf(tr7Eindos 8(
Figure Standard SAP Progra
-SFTP40for tracing F
estinations SAPFTP 5 SAPFTPA
Setting 2p an FTP Server
Before yo+ an +se the SAPFTP library AP)syo+ ill first need to set +p an FTP Server at least loally to test the e9amples
that ill be reated in the +poming setions( Ee ill be +sing a free FTP Server alled FileDilla Server and an FTP lient
alled FileDilla Client for aessing the FTP Server( Both of these softare pakages an be donloaded from the
folloing 20L
httpltltfileGilla-proHet(orglt
J+st lik on the 7ui5 donload lin5s area on the ain Page or donload both the server and the lient from the
9onload setion on the left for FileDilla and FileDilla Server setions respetively( See the sreenshot belo
Figure Site for o1loading FTP
Ser6er 5 FTP lient
After 1onloading the FileServer e9e+table file7in o+r ase it is FileDilla(Server((gtamp2exe8( 1o+ble Clik the installer to
ikstart the )nstallation proed+re( Clik the ) Agree b+tton to Agree to the terms of the liense and move forard to the
ne9t step( )n the e9t sreen7Choose Components8 selet all options apart from the Soure Code option( o Clik the
extb+tton hoose the )nstallation folder here the FTP Server ill be deployed and here all FTP )nterations ill takeplae( o the ne9t sreen7Startup Settin6s8 is the most important sreen in the set+p iGardas here yo+ ill need to
provide the Port umber For hih the FTP Server admin interfae ill listen to( in the Please Choose ho FileDilla
Server should be started drop donhoose either nstall as Servie3started ith indos default 7This ill start the
FTP Servie eah time yo+ start +p System8 or hoose nstall as Servie3started manually7To )nstall as a Serviehere
yo+ ill need to start it man+ally by providing the Admin logon redentials8(
otes
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 827
I gto+ an man+ally start or stop the FTP Server servie by making +se of the Servies snap-in hih an be aessed by
pressing 3indo 6 typing in servies2ms and hoosing FileDilla Server FTP server from the list of servies by
making +se of the playpa+se and stop b+ttons in the appliation toolbar( )n ase yo+ have set the )nstall as a Servie and
set it as man+alyo+ ill need to start that servie +sing method as mentioned abovether ise yo+ ont be able to
onnet to the FTP Server(
I 1o keep in mindthat the port assigned m+st have privileges to be alloed for its omm+niation( This an be set bysetting the P)T number in the Exeptions settings of yo+r fireall program( 1o also keep in mind that yo+ dont assign a
port n+mber that is +sed for other servies in Eindos(
e9t in the Startup settin6s selet the options that ill appliable to indo +sers and lik the install b+tton( after
)nstallationlik the lose b+tton(
Figure Installation-A0 + icense
Agreeent
Figure Installation-)0 + hoose
oponents
Figure Installation-0 + hoose
Install ocation
Figure Installation-0 + Startup
Settings-A0
Figure Installation-$0 + Startup
Settings-)0
e9t yo+ ill need to start the SAP FTP Server( gto+ an la+nh it by folloing the men+ path
indo menu G All Pro6rams G File Dilla FTP Server G File Dilla Server nterfae
gto+ ill be prompted ith a Connet to Server pop +p dialog bo9( Provide the Server Address7)P8Port +mber as set
d+ring installation and the Administrator Passord7by defa+lt it is admin8(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 927
Figure Installation-F0 + onnecting
to the FTP Ser6er Interface
Figure Installation-G0 + ogged in to
the FTP Ser6er
Creating a 2ser in the FTP Server
gto+ ill need to reate a +ser in the FTP Server in order to onnet and perform file transfer operations in SAP( To reate a
+seryo+ ill need to first reate a Hroup and then reate a +ser and assign it to that ampro+p(
)n order to reate a gro+pgo to the men+ path
Edit G Hroups
Then lik the Add b+tton to add a ampro+pgive it a name and then lik the )I b+tton( e9t e ill reate a ltser by
+sing the folloing men+ path
Edit G ltsers
Then lik the Add b+tton and provide the +ser name and +ser gro+preated in the previo+s step and lik )I and then
lik the )5 b+tton again to reate the +ser( Also hek the Passord hekbo9 and assign a passord to the +serhih
ill be re+ired for aessing it via the FTP Client Softare(
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Figure -0 + reating a User Figure -$0 + Adding a User to a
Group
Figure -F0 + Adding Pass1ord
to a User
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 327
implements FTP aording to the FC $ speifiation( gto+ an find more indepth information regarding 0FC
speifiation +sing the folloing link httpltlt(ietf(orgltrfltrf(t9t (
List of all F+ntion od+les in the SFTP F+ntion ampro+p
The F+ntion gro+p SFTP is the SAPFTP library that onsists of the folloing f+ntion mod+les for FTP programming
SNo Function Module escription
01 FTP_CLIENT_TO_R3
02 FTPMMAN Execute FTP Command
03 FTP_COMMAND_LIST
04 FTPNN$T Connect to an FTP ee
0 FTP_COP$ FTP Coamp
0 FTPISNN$T D(connect )om FTP ee
0 FTP_R3_TO_CLIENT
0+ FTPampTS$$ SAP to FTP See Commun(cat(on
0 FTPS$$Tamp FTP See to SAP Commun(cat(on
10 FTP_START_RE-_SERER
11 FTP_START_SAPFTP
12 FTP_STOP_RE-_SERER
13 FTP_ERSION Pocue SAPFTP e(on
14 TTP_ASE4_ENCODE ae4 encode t(n
1 TTP_-ET TTP -et
1 TTP_-ET_FILE TTP -et F(e
1 TTP_-ET_FILES TTP -et F(e
1+ TTP_-ET_FILES_2 TTP -et F(e
1 TTP_-ET_FILE_DP TTP -et F(e
20 TTP_-ET_FILE_E
21 TTP_POST TTP ot
22 TTP_POST_DOC5MENT
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 427
SNo Function Module escription
23 TTP_POST_DOC5MENTS
24 TTP_POST_DOC5MENT_2
2 TTP_POST_FILES TTP Pot F(e
2 TTP_POST_FILES_2 TTP Pot F(e
2 TTP_POST_FILE_E
2+ TTP_PRO$_CONFI-
2 TTP_P5T_COMPONENT
30 TTP_P5T_FILE
31 TTP_P5T_FILE_DP
32 (TTPSAM)$ Fo Encampt(n Pa6od
33 TTP_ERSION Pocue SAPTTP e(on
Some +sef+l f+ntion mod+les that are part of the SAPFTP Library inl+de
ampFTP(C)ECT
2sed for onneting to an FTP hostret+rns a handle that is +sed to bind s+bse+ent ommands to the session(
Syntax
CALL F2CT) FTP(C)ECT
5P0T)amp
DAL2572S508 TgtP5 C
DAL257PASSE018 TgtP5 C
DAL257ACC2T8 TgtP5 C PT)AL
DAL257=ST8 TgtP5 C
DAL2570FC15ST)AT)8 L)5 0FC15S-0FC15ST
DAL257ampAT5EAgt2S508 TgtP5 C PT)AL
DAL257ampAT5EAgtPASSE018 TgtP5 C PT)AL
DAL257ampAT5EAgt=ST8 TgtP5 C PT)AL
)P0T)amp
DAL257=A1L58 TgtP5 )
5C5PT)S
TC5CT51
Example
CALL F2CT) FTP(C)ECT
5P0T)amp
2S50 4 lv+serThis user name is ase sensitive
PASSE01 4 lvpassord+This passord ould also be srambled via the -TTP(SCALE funtion
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 527
module
=ST 4 lvhostip+P Address of the host FTP Server012n ase of Server host name3it is ase sensitive
0FC15ST)AT) 4 SAPFTPA or SAPFTP +SAPFTPA 4 for ba56round aess to FTP -ost server or
SAPFTP 4 for front end aess to FTP Server
)P0T)amp
=A1L5 4 =A1L5+For performin6 subse7uent operations for the onneted FTP Session
5C5PT)S
TC5CT51 4 +FTP onnetion failed
T=50S 4 (
8FTP(C)A9
2sed to e9e+te an FTP ommand on the FTP host( For a omplete list of s+pported FTP ommands on an FTP hostyo+
an e9e+te the help ommand( Some of the ommands inl+des the likes of P97for Printing the ontents of the C+rrent
Eorking 1iretory8ltT7For Logging o+t the +ser +rrently onneted to the FTP server via the FTPC5CT f+ntion
mod+le8 e(t((
=FTP(=(T)(CLET
2sed to transfer a file don to the front-end(
gtFTP(CLET(T)(=
2sed to +pload a file from the front-end(
$FTP(=(T)(SEE
2sed to +pload a file to the FTP host(
FTP(SEE(T)(=
2sed to donload a file from the FTP host(
FTP(9SC)ECT
2sed to disonnet from an FTP host(
BFC(C)ECT)(CL)SE
For 1isonneting 0FC onnetion beteen SAP and FTP(
Example
CALL F2CT) 0FCC5CT)CLS5
5P0T)amp
destination 4 lrfdest0FC 1estination host(e(gSAPFTPA
5C5PT)S
T=50S 4 (
For reating 0FC 1estinations for FTP omm+niations
gto+ need to reate 0FC destinations for FTP omm+niations( There is a standard report for that p+rpose alled
SFTP$7SAPFTP hek8
instead of onfig+ring it man+ally via the transation S$7Config+rations of 0FC onnetions8it a+tomatially reates the
folloing to 0FC destinations
78SAPFTP7For invoking the 0FC library on the SAP amp2) frontend8
78SAPFTPA7For invoking the 0FC library on the SAP eteaver AS ABAP host8
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 627
Figure + A SAP Standard Progra
-SFTP0 for Generation of F
estinations SAPFTP and SAPFTPA
Figure + ) Generated F estinations
SAPFTP and SAPFTPA as sho1n
in Transaction SM2
For testing the 0FC destinations
After setting +p the 0FC destinationsyo+ an hek the folloing report for testing them
SFTP8759e+te FTP Command8( =ere yo+ enter in the redentials7hih inl+des fields like
ltser Passord-ostFC 9estination8( )n order to test ommands yo+ enter in a ommand s+h as helpthat
displays a list of all ommands that an be entered in the ommand field(
Figure Standard Progra for Testing
FTP ounications -SFTP30
For heking the Trae of the FTP omm+niation
gto+ an +se the report SFTPamphih displays the trae of the FTP omm+niationsprovided traing has been enabled
for BT= 0FC destinations SAPFTP and SAPFTPA in Transation S$( This report not only tells yo+ abo+t all
ommands and interation b+t also informs abo+t attrib+tes s+h as the orking diretorySAPFTP e9e+table file path for
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 727
eah of the 0FC destinations mentioned above7SAPFTP and SAPFTPA8( 5nabling Traing generates a trae file in the SAP
amp2) Eorking diretory ith the name dev(rf7For +ni98 and rf(tr7Eindos 8(
Figure Standard SAP Progra
-SFTP40for tracing F
estinations SAPFTP 5 SAPFTPA
Setting 2p an FTP Server
Before yo+ an +se the SAPFTP library AP)syo+ ill first need to set +p an FTP Server at least loally to test the e9amples
that ill be reated in the +poming setions( Ee ill be +sing a free FTP Server alled FileDilla Server and an FTP lient
alled FileDilla Client for aessing the FTP Server( Both of these softare pakages an be donloaded from the
folloing 20L
httpltltfileGilla-proHet(orglt
J+st lik on the 7ui5 donload lin5s area on the ain Page or donload both the server and the lient from the
9onload setion on the left for FileDilla and FileDilla Server setions respetively( See the sreenshot belo
Figure Site for o1loading FTP
Ser6er 5 FTP lient
After 1onloading the FileServer e9e+table file7in o+r ase it is FileDilla(Server((gtamp2exe8( 1o+ble Clik the installer to
ikstart the )nstallation proed+re( Clik the ) Agree b+tton to Agree to the terms of the liense and move forard to the
ne9t step( )n the e9t sreen7Choose Components8 selet all options apart from the Soure Code option( o Clik the
extb+tton hoose the )nstallation folder here the FTP Server ill be deployed and here all FTP )nterations ill takeplae( o the ne9t sreen7Startup Settin6s8 is the most important sreen in the set+p iGardas here yo+ ill need to
provide the Port umber For hih the FTP Server admin interfae ill listen to( in the Please Choose ho FileDilla
Server should be started drop donhoose either nstall as Servie3started ith indos default 7This ill start the
FTP Servie eah time yo+ start +p System8 or hoose nstall as Servie3started manually7To )nstall as a Serviehere
yo+ ill need to start it man+ally by providing the Admin logon redentials8(
otes
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 827
I gto+ an man+ally start or stop the FTP Server servie by making +se of the Servies snap-in hih an be aessed by
pressing 3indo 6 typing in servies2ms and hoosing FileDilla Server FTP server from the list of servies by
making +se of the playpa+se and stop b+ttons in the appliation toolbar( )n ase yo+ have set the )nstall as a Servie and
set it as man+alyo+ ill need to start that servie +sing method as mentioned abovether ise yo+ ont be able to
onnet to the FTP Server(
I 1o keep in mindthat the port assigned m+st have privileges to be alloed for its omm+niation( This an be set bysetting the P)T number in the Exeptions settings of yo+r fireall program( 1o also keep in mind that yo+ dont assign a
port n+mber that is +sed for other servies in Eindos(
e9t in the Startup settin6s selet the options that ill appliable to indo +sers and lik the install b+tton( after
)nstallationlik the lose b+tton(
Figure Installation-A0 + icense
Agreeent
Figure Installation-)0 + hoose
oponents
Figure Installation-0 + hoose
Install ocation
Figure Installation-0 + Startup
Settings-A0
Figure Installation-$0 + Startup
Settings-)0
e9t yo+ ill need to start the SAP FTP Server( gto+ an la+nh it by folloing the men+ path
indo menu G All Pro6rams G File Dilla FTP Server G File Dilla Server nterfae
gto+ ill be prompted ith a Connet to Server pop +p dialog bo9( Provide the Server Address7)P8Port +mber as set
d+ring installation and the Administrator Passord7by defa+lt it is admin8(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 927
Figure Installation-F0 + onnecting
to the FTP Ser6er Interface
Figure Installation-G0 + ogged in to
the FTP Ser6er
Creating a 2ser in the FTP Server
gto+ ill need to reate a +ser in the FTP Server in order to onnet and perform file transfer operations in SAP( To reate a
+seryo+ ill need to first reate a Hroup and then reate a +ser and assign it to that ampro+p(
)n order to reate a gro+pgo to the men+ path
Edit G Hroups
Then lik the Add b+tton to add a ampro+pgive it a name and then lik the )I b+tton( e9t e ill reate a ltser by
+sing the folloing men+ path
Edit G ltsers
Then lik the Add b+tton and provide the +ser name and +ser gro+preated in the previo+s step and lik )I and then
lik the )5 b+tton again to reate the +ser( Also hek the Passord hekbo9 and assign a passord to the +serhih
ill be re+ired for aessing it via the FTP Client Softare(
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Figure -0 + reating a User Figure -$0 + Adding a User to a
Group
Figure -F0 + Adding Pass1ord
to a User
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 427
SNo Function Module escription
23 TTP_POST_DOC5MENTS
24 TTP_POST_DOC5MENT_2
2 TTP_POST_FILES TTP Pot F(e
2 TTP_POST_FILES_2 TTP Pot F(e
2 TTP_POST_FILE_E
2+ TTP_PRO$_CONFI-
2 TTP_P5T_COMPONENT
30 TTP_P5T_FILE
31 TTP_P5T_FILE_DP
32 (TTPSAM)$ Fo Encampt(n Pa6od
33 TTP_ERSION Pocue SAPTTP e(on
Some +sef+l f+ntion mod+les that are part of the SAPFTP Library inl+de
ampFTP(C)ECT
2sed for onneting to an FTP hostret+rns a handle that is +sed to bind s+bse+ent ommands to the session(
Syntax
CALL F2CT) FTP(C)ECT
5P0T)amp
DAL2572S508 TgtP5 C
DAL257PASSE018 TgtP5 C
DAL257ACC2T8 TgtP5 C PT)AL
DAL257=ST8 TgtP5 C
DAL2570FC15ST)AT)8 L)5 0FC15S-0FC15ST
DAL257ampAT5EAgt2S508 TgtP5 C PT)AL
DAL257ampAT5EAgtPASSE018 TgtP5 C PT)AL
DAL257ampAT5EAgt=ST8 TgtP5 C PT)AL
)P0T)amp
DAL257=A1L58 TgtP5 )
5C5PT)S
TC5CT51
Example
CALL F2CT) FTP(C)ECT
5P0T)amp
2S50 4 lv+serThis user name is ase sensitive
PASSE01 4 lvpassord+This passord ould also be srambled via the -TTP(SCALE funtion
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 527
module
=ST 4 lvhostip+P Address of the host FTP Server012n ase of Server host name3it is ase sensitive
0FC15ST)AT) 4 SAPFTPA or SAPFTP +SAPFTPA 4 for ba56round aess to FTP -ost server or
SAPFTP 4 for front end aess to FTP Server
)P0T)amp
=A1L5 4 =A1L5+For performin6 subse7uent operations for the onneted FTP Session
5C5PT)S
TC5CT51 4 +FTP onnetion failed
T=50S 4 (
8FTP(C)A9
2sed to e9e+te an FTP ommand on the FTP host( For a omplete list of s+pported FTP ommands on an FTP hostyo+
an e9e+te the help ommand( Some of the ommands inl+des the likes of P97for Printing the ontents of the C+rrent
Eorking 1iretory8ltT7For Logging o+t the +ser +rrently onneted to the FTP server via the FTPC5CT f+ntion
mod+le8 e(t((
=FTP(=(T)(CLET
2sed to transfer a file don to the front-end(
gtFTP(CLET(T)(=
2sed to +pload a file from the front-end(
$FTP(=(T)(SEE
2sed to +pload a file to the FTP host(
FTP(SEE(T)(=
2sed to donload a file from the FTP host(
FTP(9SC)ECT
2sed to disonnet from an FTP host(
BFC(C)ECT)(CL)SE
For 1isonneting 0FC onnetion beteen SAP and FTP(
Example
CALL F2CT) 0FCC5CT)CLS5
5P0T)amp
destination 4 lrfdest0FC 1estination host(e(gSAPFTPA
5C5PT)S
T=50S 4 (
For reating 0FC 1estinations for FTP omm+niations
gto+ need to reate 0FC destinations for FTP omm+niations( There is a standard report for that p+rpose alled
SFTP$7SAPFTP hek8
instead of onfig+ring it man+ally via the transation S$7Config+rations of 0FC onnetions8it a+tomatially reates the
folloing to 0FC destinations
78SAPFTP7For invoking the 0FC library on the SAP amp2) frontend8
78SAPFTPA7For invoking the 0FC library on the SAP eteaver AS ABAP host8
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 627
Figure + A SAP Standard Progra
-SFTP0 for Generation of F
estinations SAPFTP and SAPFTPA
Figure + ) Generated F estinations
SAPFTP and SAPFTPA as sho1n
in Transaction SM2
For testing the 0FC destinations
After setting +p the 0FC destinationsyo+ an hek the folloing report for testing them
SFTP8759e+te FTP Command8( =ere yo+ enter in the redentials7hih inl+des fields like
ltser Passord-ostFC 9estination8( )n order to test ommands yo+ enter in a ommand s+h as helpthat
displays a list of all ommands that an be entered in the ommand field(
Figure Standard Progra for Testing
FTP ounications -SFTP30
For heking the Trae of the FTP omm+niation
gto+ an +se the report SFTPamphih displays the trae of the FTP omm+niationsprovided traing has been enabled
for BT= 0FC destinations SAPFTP and SAPFTPA in Transation S$( This report not only tells yo+ abo+t all
ommands and interation b+t also informs abo+t attrib+tes s+h as the orking diretorySAPFTP e9e+table file path for
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 727
eah of the 0FC destinations mentioned above7SAPFTP and SAPFTPA8( 5nabling Traing generates a trae file in the SAP
amp2) Eorking diretory ith the name dev(rf7For +ni98 and rf(tr7Eindos 8(
Figure Standard SAP Progra
-SFTP40for tracing F
estinations SAPFTP 5 SAPFTPA
Setting 2p an FTP Server
Before yo+ an +se the SAPFTP library AP)syo+ ill first need to set +p an FTP Server at least loally to test the e9amples
that ill be reated in the +poming setions( Ee ill be +sing a free FTP Server alled FileDilla Server and an FTP lient
alled FileDilla Client for aessing the FTP Server( Both of these softare pakages an be donloaded from the
folloing 20L
httpltltfileGilla-proHet(orglt
J+st lik on the 7ui5 donload lin5s area on the ain Page or donload both the server and the lient from the
9onload setion on the left for FileDilla and FileDilla Server setions respetively( See the sreenshot belo
Figure Site for o1loading FTP
Ser6er 5 FTP lient
After 1onloading the FileServer e9e+table file7in o+r ase it is FileDilla(Server((gtamp2exe8( 1o+ble Clik the installer to
ikstart the )nstallation proed+re( Clik the ) Agree b+tton to Agree to the terms of the liense and move forard to the
ne9t step( )n the e9t sreen7Choose Components8 selet all options apart from the Soure Code option( o Clik the
extb+tton hoose the )nstallation folder here the FTP Server ill be deployed and here all FTP )nterations ill takeplae( o the ne9t sreen7Startup Settin6s8 is the most important sreen in the set+p iGardas here yo+ ill need to
provide the Port umber For hih the FTP Server admin interfae ill listen to( in the Please Choose ho FileDilla
Server should be started drop donhoose either nstall as Servie3started ith indos default 7This ill start the
FTP Servie eah time yo+ start +p System8 or hoose nstall as Servie3started manually7To )nstall as a Serviehere
yo+ ill need to start it man+ally by providing the Admin logon redentials8(
otes
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 827
I gto+ an man+ally start or stop the FTP Server servie by making +se of the Servies snap-in hih an be aessed by
pressing 3indo 6 typing in servies2ms and hoosing FileDilla Server FTP server from the list of servies by
making +se of the playpa+se and stop b+ttons in the appliation toolbar( )n ase yo+ have set the )nstall as a Servie and
set it as man+alyo+ ill need to start that servie +sing method as mentioned abovether ise yo+ ont be able to
onnet to the FTP Server(
I 1o keep in mindthat the port assigned m+st have privileges to be alloed for its omm+niation( This an be set bysetting the P)T number in the Exeptions settings of yo+r fireall program( 1o also keep in mind that yo+ dont assign a
port n+mber that is +sed for other servies in Eindos(
e9t in the Startup settin6s selet the options that ill appliable to indo +sers and lik the install b+tton( after
)nstallationlik the lose b+tton(
Figure Installation-A0 + icense
Agreeent
Figure Installation-)0 + hoose
oponents
Figure Installation-0 + hoose
Install ocation
Figure Installation-0 + Startup
Settings-A0
Figure Installation-$0 + Startup
Settings-)0
e9t yo+ ill need to start the SAP FTP Server( gto+ an la+nh it by folloing the men+ path
indo menu G All Pro6rams G File Dilla FTP Server G File Dilla Server nterfae
gto+ ill be prompted ith a Connet to Server pop +p dialog bo9( Provide the Server Address7)P8Port +mber as set
d+ring installation and the Administrator Passord7by defa+lt it is admin8(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 927
Figure Installation-F0 + onnecting
to the FTP Ser6er Interface
Figure Installation-G0 + ogged in to
the FTP Ser6er
Creating a 2ser in the FTP Server
gto+ ill need to reate a +ser in the FTP Server in order to onnet and perform file transfer operations in SAP( To reate a
+seryo+ ill need to first reate a Hroup and then reate a +ser and assign it to that ampro+p(
)n order to reate a gro+pgo to the men+ path
Edit G Hroups
Then lik the Add b+tton to add a ampro+pgive it a name and then lik the )I b+tton( e9t e ill reate a ltser by
+sing the folloing men+ path
Edit G ltsers
Then lik the Add b+tton and provide the +ser name and +ser gro+preated in the previo+s step and lik )I and then
lik the )5 b+tton again to reate the +ser( Also hek the Passord hekbo9 and assign a passord to the +serhih
ill be re+ired for aessing it via the FTP Client Softare(
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Figure -0 + reating a User Figure -$0 + Adding a User to a
Group
Figure -F0 + Adding Pass1ord
to a User
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 527
module
=ST 4 lvhostip+P Address of the host FTP Server012n ase of Server host name3it is ase sensitive
0FC15ST)AT) 4 SAPFTPA or SAPFTP +SAPFTPA 4 for ba56round aess to FTP -ost server or
SAPFTP 4 for front end aess to FTP Server
)P0T)amp
=A1L5 4 =A1L5+For performin6 subse7uent operations for the onneted FTP Session
5C5PT)S
TC5CT51 4 +FTP onnetion failed
T=50S 4 (
8FTP(C)A9
2sed to e9e+te an FTP ommand on the FTP host( For a omplete list of s+pported FTP ommands on an FTP hostyo+
an e9e+te the help ommand( Some of the ommands inl+des the likes of P97for Printing the ontents of the C+rrent
Eorking 1iretory8ltT7For Logging o+t the +ser +rrently onneted to the FTP server via the FTPC5CT f+ntion
mod+le8 e(t((
=FTP(=(T)(CLET
2sed to transfer a file don to the front-end(
gtFTP(CLET(T)(=
2sed to +pload a file from the front-end(
$FTP(=(T)(SEE
2sed to +pload a file to the FTP host(
FTP(SEE(T)(=
2sed to donload a file from the FTP host(
FTP(9SC)ECT
2sed to disonnet from an FTP host(
BFC(C)ECT)(CL)SE
For 1isonneting 0FC onnetion beteen SAP and FTP(
Example
CALL F2CT) 0FCC5CT)CLS5
5P0T)amp
destination 4 lrfdest0FC 1estination host(e(gSAPFTPA
5C5PT)S
T=50S 4 (
For reating 0FC 1estinations for FTP omm+niations
gto+ need to reate 0FC destinations for FTP omm+niations( There is a standard report for that p+rpose alled
SFTP$7SAPFTP hek8
instead of onfig+ring it man+ally via the transation S$7Config+rations of 0FC onnetions8it a+tomatially reates the
folloing to 0FC destinations
78SAPFTP7For invoking the 0FC library on the SAP amp2) frontend8
78SAPFTPA7For invoking the 0FC library on the SAP eteaver AS ABAP host8
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 627
Figure + A SAP Standard Progra
-SFTP0 for Generation of F
estinations SAPFTP and SAPFTPA
Figure + ) Generated F estinations
SAPFTP and SAPFTPA as sho1n
in Transaction SM2
For testing the 0FC destinations
After setting +p the 0FC destinationsyo+ an hek the folloing report for testing them
SFTP8759e+te FTP Command8( =ere yo+ enter in the redentials7hih inl+des fields like
ltser Passord-ostFC 9estination8( )n order to test ommands yo+ enter in a ommand s+h as helpthat
displays a list of all ommands that an be entered in the ommand field(
Figure Standard Progra for Testing
FTP ounications -SFTP30
For heking the Trae of the FTP omm+niation
gto+ an +se the report SFTPamphih displays the trae of the FTP omm+niationsprovided traing has been enabled
for BT= 0FC destinations SAPFTP and SAPFTPA in Transation S$( This report not only tells yo+ abo+t all
ommands and interation b+t also informs abo+t attrib+tes s+h as the orking diretorySAPFTP e9e+table file path for
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 727
eah of the 0FC destinations mentioned above7SAPFTP and SAPFTPA8( 5nabling Traing generates a trae file in the SAP
amp2) Eorking diretory ith the name dev(rf7For +ni98 and rf(tr7Eindos 8(
Figure Standard SAP Progra
-SFTP40for tracing F
estinations SAPFTP 5 SAPFTPA
Setting 2p an FTP Server
Before yo+ an +se the SAPFTP library AP)syo+ ill first need to set +p an FTP Server at least loally to test the e9amples
that ill be reated in the +poming setions( Ee ill be +sing a free FTP Server alled FileDilla Server and an FTP lient
alled FileDilla Client for aessing the FTP Server( Both of these softare pakages an be donloaded from the
folloing 20L
httpltltfileGilla-proHet(orglt
J+st lik on the 7ui5 donload lin5s area on the ain Page or donload both the server and the lient from the
9onload setion on the left for FileDilla and FileDilla Server setions respetively( See the sreenshot belo
Figure Site for o1loading FTP
Ser6er 5 FTP lient
After 1onloading the FileServer e9e+table file7in o+r ase it is FileDilla(Server((gtamp2exe8( 1o+ble Clik the installer to
ikstart the )nstallation proed+re( Clik the ) Agree b+tton to Agree to the terms of the liense and move forard to the
ne9t step( )n the e9t sreen7Choose Components8 selet all options apart from the Soure Code option( o Clik the
extb+tton hoose the )nstallation folder here the FTP Server ill be deployed and here all FTP )nterations ill takeplae( o the ne9t sreen7Startup Settin6s8 is the most important sreen in the set+p iGardas here yo+ ill need to
provide the Port umber For hih the FTP Server admin interfae ill listen to( in the Please Choose ho FileDilla
Server should be started drop donhoose either nstall as Servie3started ith indos default 7This ill start the
FTP Servie eah time yo+ start +p System8 or hoose nstall as Servie3started manually7To )nstall as a Serviehere
yo+ ill need to start it man+ally by providing the Admin logon redentials8(
otes
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 827
I gto+ an man+ally start or stop the FTP Server servie by making +se of the Servies snap-in hih an be aessed by
pressing 3indo 6 typing in servies2ms and hoosing FileDilla Server FTP server from the list of servies by
making +se of the playpa+se and stop b+ttons in the appliation toolbar( )n ase yo+ have set the )nstall as a Servie and
set it as man+alyo+ ill need to start that servie +sing method as mentioned abovether ise yo+ ont be able to
onnet to the FTP Server(
I 1o keep in mindthat the port assigned m+st have privileges to be alloed for its omm+niation( This an be set bysetting the P)T number in the Exeptions settings of yo+r fireall program( 1o also keep in mind that yo+ dont assign a
port n+mber that is +sed for other servies in Eindos(
e9t in the Startup settin6s selet the options that ill appliable to indo +sers and lik the install b+tton( after
)nstallationlik the lose b+tton(
Figure Installation-A0 + icense
Agreeent
Figure Installation-)0 + hoose
oponents
Figure Installation-0 + hoose
Install ocation
Figure Installation-0 + Startup
Settings-A0
Figure Installation-$0 + Startup
Settings-)0
e9t yo+ ill need to start the SAP FTP Server( gto+ an la+nh it by folloing the men+ path
indo menu G All Pro6rams G File Dilla FTP Server G File Dilla Server nterfae
gto+ ill be prompted ith a Connet to Server pop +p dialog bo9( Provide the Server Address7)P8Port +mber as set
d+ring installation and the Administrator Passord7by defa+lt it is admin8(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 927
Figure Installation-F0 + onnecting
to the FTP Ser6er Interface
Figure Installation-G0 + ogged in to
the FTP Ser6er
Creating a 2ser in the FTP Server
gto+ ill need to reate a +ser in the FTP Server in order to onnet and perform file transfer operations in SAP( To reate a
+seryo+ ill need to first reate a Hroup and then reate a +ser and assign it to that ampro+p(
)n order to reate a gro+pgo to the men+ path
Edit G Hroups
Then lik the Add b+tton to add a ampro+pgive it a name and then lik the )I b+tton( e9t e ill reate a ltser by
+sing the folloing men+ path
Edit G ltsers
Then lik the Add b+tton and provide the +ser name and +ser gro+preated in the previo+s step and lik )I and then
lik the )5 b+tton again to reate the +ser( Also hek the Passord hekbo9 and assign a passord to the +serhih
ill be re+ired for aessing it via the FTP Client Softare(
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Figure -0 + reating a User Figure -$0 + Adding a User to a
Group
Figure -F0 + Adding Pass1ord
to a User
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 627
Figure + A SAP Standard Progra
-SFTP0 for Generation of F
estinations SAPFTP and SAPFTPA
Figure + ) Generated F estinations
SAPFTP and SAPFTPA as sho1n
in Transaction SM2
For testing the 0FC destinations
After setting +p the 0FC destinationsyo+ an hek the folloing report for testing them
SFTP8759e+te FTP Command8( =ere yo+ enter in the redentials7hih inl+des fields like
ltser Passord-ostFC 9estination8( )n order to test ommands yo+ enter in a ommand s+h as helpthat
displays a list of all ommands that an be entered in the ommand field(
Figure Standard Progra for Testing
FTP ounications -SFTP30
For heking the Trae of the FTP omm+niation
gto+ an +se the report SFTPamphih displays the trae of the FTP omm+niationsprovided traing has been enabled
for BT= 0FC destinations SAPFTP and SAPFTPA in Transation S$( This report not only tells yo+ abo+t all
ommands and interation b+t also informs abo+t attrib+tes s+h as the orking diretorySAPFTP e9e+table file path for
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 727
eah of the 0FC destinations mentioned above7SAPFTP and SAPFTPA8( 5nabling Traing generates a trae file in the SAP
amp2) Eorking diretory ith the name dev(rf7For +ni98 and rf(tr7Eindos 8(
Figure Standard SAP Progra
-SFTP40for tracing F
estinations SAPFTP 5 SAPFTPA
Setting 2p an FTP Server
Before yo+ an +se the SAPFTP library AP)syo+ ill first need to set +p an FTP Server at least loally to test the e9amples
that ill be reated in the +poming setions( Ee ill be +sing a free FTP Server alled FileDilla Server and an FTP lient
alled FileDilla Client for aessing the FTP Server( Both of these softare pakages an be donloaded from the
folloing 20L
httpltltfileGilla-proHet(orglt
J+st lik on the 7ui5 donload lin5s area on the ain Page or donload both the server and the lient from the
9onload setion on the left for FileDilla and FileDilla Server setions respetively( See the sreenshot belo
Figure Site for o1loading FTP
Ser6er 5 FTP lient
After 1onloading the FileServer e9e+table file7in o+r ase it is FileDilla(Server((gtamp2exe8( 1o+ble Clik the installer to
ikstart the )nstallation proed+re( Clik the ) Agree b+tton to Agree to the terms of the liense and move forard to the
ne9t step( )n the e9t sreen7Choose Components8 selet all options apart from the Soure Code option( o Clik the
extb+tton hoose the )nstallation folder here the FTP Server ill be deployed and here all FTP )nterations ill takeplae( o the ne9t sreen7Startup Settin6s8 is the most important sreen in the set+p iGardas here yo+ ill need to
provide the Port umber For hih the FTP Server admin interfae ill listen to( in the Please Choose ho FileDilla
Server should be started drop donhoose either nstall as Servie3started ith indos default 7This ill start the
FTP Servie eah time yo+ start +p System8 or hoose nstall as Servie3started manually7To )nstall as a Serviehere
yo+ ill need to start it man+ally by providing the Admin logon redentials8(
otes
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 827
I gto+ an man+ally start or stop the FTP Server servie by making +se of the Servies snap-in hih an be aessed by
pressing 3indo 6 typing in servies2ms and hoosing FileDilla Server FTP server from the list of servies by
making +se of the playpa+se and stop b+ttons in the appliation toolbar( )n ase yo+ have set the )nstall as a Servie and
set it as man+alyo+ ill need to start that servie +sing method as mentioned abovether ise yo+ ont be able to
onnet to the FTP Server(
I 1o keep in mindthat the port assigned m+st have privileges to be alloed for its omm+niation( This an be set bysetting the P)T number in the Exeptions settings of yo+r fireall program( 1o also keep in mind that yo+ dont assign a
port n+mber that is +sed for other servies in Eindos(
e9t in the Startup settin6s selet the options that ill appliable to indo +sers and lik the install b+tton( after
)nstallationlik the lose b+tton(
Figure Installation-A0 + icense
Agreeent
Figure Installation-)0 + hoose
oponents
Figure Installation-0 + hoose
Install ocation
Figure Installation-0 + Startup
Settings-A0
Figure Installation-$0 + Startup
Settings-)0
e9t yo+ ill need to start the SAP FTP Server( gto+ an la+nh it by folloing the men+ path
indo menu G All Pro6rams G File Dilla FTP Server G File Dilla Server nterfae
gto+ ill be prompted ith a Connet to Server pop +p dialog bo9( Provide the Server Address7)P8Port +mber as set
d+ring installation and the Administrator Passord7by defa+lt it is admin8(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 927
Figure Installation-F0 + onnecting
to the FTP Ser6er Interface
Figure Installation-G0 + ogged in to
the FTP Ser6er
Creating a 2ser in the FTP Server
gto+ ill need to reate a +ser in the FTP Server in order to onnet and perform file transfer operations in SAP( To reate a
+seryo+ ill need to first reate a Hroup and then reate a +ser and assign it to that ampro+p(
)n order to reate a gro+pgo to the men+ path
Edit G Hroups
Then lik the Add b+tton to add a ampro+pgive it a name and then lik the )I b+tton( e9t e ill reate a ltser by
+sing the folloing men+ path
Edit G ltsers
Then lik the Add b+tton and provide the +ser name and +ser gro+preated in the previo+s step and lik )I and then
lik the )5 b+tton again to reate the +ser( Also hek the Passord hekbo9 and assign a passord to the +serhih
ill be re+ired for aessing it via the FTP Client Softare(
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Figure -0 + reating a User Figure -$0 + Adding a User to a
Group
Figure -F0 + Adding Pass1ord
to a User
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 727
eah of the 0FC destinations mentioned above7SAPFTP and SAPFTPA8( 5nabling Traing generates a trae file in the SAP
amp2) Eorking diretory ith the name dev(rf7For +ni98 and rf(tr7Eindos 8(
Figure Standard SAP Progra
-SFTP40for tracing F
estinations SAPFTP 5 SAPFTPA
Setting 2p an FTP Server
Before yo+ an +se the SAPFTP library AP)syo+ ill first need to set +p an FTP Server at least loally to test the e9amples
that ill be reated in the +poming setions( Ee ill be +sing a free FTP Server alled FileDilla Server and an FTP lient
alled FileDilla Client for aessing the FTP Server( Both of these softare pakages an be donloaded from the
folloing 20L
httpltltfileGilla-proHet(orglt
J+st lik on the 7ui5 donload lin5s area on the ain Page or donload both the server and the lient from the
9onload setion on the left for FileDilla and FileDilla Server setions respetively( See the sreenshot belo
Figure Site for o1loading FTP
Ser6er 5 FTP lient
After 1onloading the FileServer e9e+table file7in o+r ase it is FileDilla(Server((gtamp2exe8( 1o+ble Clik the installer to
ikstart the )nstallation proed+re( Clik the ) Agree b+tton to Agree to the terms of the liense and move forard to the
ne9t step( )n the e9t sreen7Choose Components8 selet all options apart from the Soure Code option( o Clik the
extb+tton hoose the )nstallation folder here the FTP Server ill be deployed and here all FTP )nterations ill takeplae( o the ne9t sreen7Startup Settin6s8 is the most important sreen in the set+p iGardas here yo+ ill need to
provide the Port umber For hih the FTP Server admin interfae ill listen to( in the Please Choose ho FileDilla
Server should be started drop donhoose either nstall as Servie3started ith indos default 7This ill start the
FTP Servie eah time yo+ start +p System8 or hoose nstall as Servie3started manually7To )nstall as a Serviehere
yo+ ill need to start it man+ally by providing the Admin logon redentials8(
otes
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 827
I gto+ an man+ally start or stop the FTP Server servie by making +se of the Servies snap-in hih an be aessed by
pressing 3indo 6 typing in servies2ms and hoosing FileDilla Server FTP server from the list of servies by
making +se of the playpa+se and stop b+ttons in the appliation toolbar( )n ase yo+ have set the )nstall as a Servie and
set it as man+alyo+ ill need to start that servie +sing method as mentioned abovether ise yo+ ont be able to
onnet to the FTP Server(
I 1o keep in mindthat the port assigned m+st have privileges to be alloed for its omm+niation( This an be set bysetting the P)T number in the Exeptions settings of yo+r fireall program( 1o also keep in mind that yo+ dont assign a
port n+mber that is +sed for other servies in Eindos(
e9t in the Startup settin6s selet the options that ill appliable to indo +sers and lik the install b+tton( after
)nstallationlik the lose b+tton(
Figure Installation-A0 + icense
Agreeent
Figure Installation-)0 + hoose
oponents
Figure Installation-0 + hoose
Install ocation
Figure Installation-0 + Startup
Settings-A0
Figure Installation-$0 + Startup
Settings-)0
e9t yo+ ill need to start the SAP FTP Server( gto+ an la+nh it by folloing the men+ path
indo menu G All Pro6rams G File Dilla FTP Server G File Dilla Server nterfae
gto+ ill be prompted ith a Connet to Server pop +p dialog bo9( Provide the Server Address7)P8Port +mber as set
d+ring installation and the Administrator Passord7by defa+lt it is admin8(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 927
Figure Installation-F0 + onnecting
to the FTP Ser6er Interface
Figure Installation-G0 + ogged in to
the FTP Ser6er
Creating a 2ser in the FTP Server
gto+ ill need to reate a +ser in the FTP Server in order to onnet and perform file transfer operations in SAP( To reate a
+seryo+ ill need to first reate a Hroup and then reate a +ser and assign it to that ampro+p(
)n order to reate a gro+pgo to the men+ path
Edit G Hroups
Then lik the Add b+tton to add a ampro+pgive it a name and then lik the )I b+tton( e9t e ill reate a ltser by
+sing the folloing men+ path
Edit G ltsers
Then lik the Add b+tton and provide the +ser name and +ser gro+preated in the previo+s step and lik )I and then
lik the )5 b+tton again to reate the +ser( Also hek the Passord hekbo9 and assign a passord to the +serhih
ill be re+ired for aessing it via the FTP Client Softare(
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Figure -0 + reating a User Figure -$0 + Adding a User to a
Group
Figure -F0 + Adding Pass1ord
to a User
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 827
I gto+ an man+ally start or stop the FTP Server servie by making +se of the Servies snap-in hih an be aessed by
pressing 3indo 6 typing in servies2ms and hoosing FileDilla Server FTP server from the list of servies by
making +se of the playpa+se and stop b+ttons in the appliation toolbar( )n ase yo+ have set the )nstall as a Servie and
set it as man+alyo+ ill need to start that servie +sing method as mentioned abovether ise yo+ ont be able to
onnet to the FTP Server(
I 1o keep in mindthat the port assigned m+st have privileges to be alloed for its omm+niation( This an be set bysetting the P)T number in the Exeptions settings of yo+r fireall program( 1o also keep in mind that yo+ dont assign a
port n+mber that is +sed for other servies in Eindos(
e9t in the Startup settin6s selet the options that ill appliable to indo +sers and lik the install b+tton( after
)nstallationlik the lose b+tton(
Figure Installation-A0 + icense
Agreeent
Figure Installation-)0 + hoose
oponents
Figure Installation-0 + hoose
Install ocation
Figure Installation-0 + Startup
Settings-A0
Figure Installation-$0 + Startup
Settings-)0
e9t yo+ ill need to start the SAP FTP Server( gto+ an la+nh it by folloing the men+ path
indo menu G All Pro6rams G File Dilla FTP Server G File Dilla Server nterfae
gto+ ill be prompted ith a Connet to Server pop +p dialog bo9( Provide the Server Address7)P8Port +mber as set
d+ring installation and the Administrator Passord7by defa+lt it is admin8(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 927
Figure Installation-F0 + onnecting
to the FTP Ser6er Interface
Figure Installation-G0 + ogged in to
the FTP Ser6er
Creating a 2ser in the FTP Server
gto+ ill need to reate a +ser in the FTP Server in order to onnet and perform file transfer operations in SAP( To reate a
+seryo+ ill need to first reate a Hroup and then reate a +ser and assign it to that ampro+p(
)n order to reate a gro+pgo to the men+ path
Edit G Hroups
Then lik the Add b+tton to add a ampro+pgive it a name and then lik the )I b+tton( e9t e ill reate a ltser by
+sing the folloing men+ path
Edit G ltsers
Then lik the Add b+tton and provide the +ser name and +ser gro+preated in the previo+s step and lik )I and then
lik the )5 b+tton again to reate the +ser( Also hek the Passord hekbo9 and assign a passord to the +serhih
ill be re+ired for aessing it via the FTP Client Softare(
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Figure -0 + reating a User Figure -$0 + Adding a User to a
Group
Figure -F0 + Adding Pass1ord
to a User
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 927
Figure Installation-F0 + onnecting
to the FTP Ser6er Interface
Figure Installation-G0 + ogged in to
the FTP Ser6er
Creating a 2ser in the FTP Server
gto+ ill need to reate a +ser in the FTP Server in order to onnet and perform file transfer operations in SAP( To reate a
+seryo+ ill need to first reate a Hroup and then reate a +ser and assign it to that ampro+p(
)n order to reate a gro+pgo to the men+ path
Edit G Hroups
Then lik the Add b+tton to add a ampro+pgive it a name and then lik the )I b+tton( e9t e ill reate a ltser by
+sing the folloing men+ path
Edit G ltsers
Then lik the Add b+tton and provide the +ser name and +ser gro+preated in the previo+s step and lik )I and then
lik the )5 b+tton again to reate the +ser( Also hek the Passord hekbo9 and assign a passord to the +serhih
ill be re+ired for aessing it via the FTP Client Softare(
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Figure -0 + reating a User Figure -$0 + Adding a User to a
Group
Figure -F0 + Adding Pass1ord
to a User
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1027
Figure -A0 + reating a Group Figure -)0 + Adding a Group Figure 0 + Finali7ing a Group
Setting +p a diretory for a 2ser reated in the FTP Server
After reating the +sergo to the folloing men+ path
Edit G ltsers
o goto the Shared folders page on the left sideto set +p a home diretory for the +ser( Clik on the Add b+tton and
navigate to the diretory that yo+ ill set as the 2sers =ome 1iretory( o selet all permissions as provided in the Files
and 9iretories areaby heking the respetive hek bo9esthese ill be re+ired for ertain operations s+h as hether
a File o+ld be reated deleted or read from the given diretory and hether diretories an be listedreated or deleted
e(t(( o lik the Set as home dir b+tton to set the diretory path as the defa+lt home diretory of the +ser( o lik the
)5 b+tton to omplete setting +p the home diretory(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1127
Figure -G0 + Adding a user
director8
Figure -(0 + Setting Perissions
and setting it as hoedirector8
Figure -I0 + oplete setting
up the user director8
)nstalling the FTP Client Softare
Before yo+ an aess the +sers diretory reated in the FTP Serveryo+ re+ire an FTP lient to Aess to it( )nstallation of
the FTP lient softare is straightforard and typial of Eindo Appliations( 0efer to the folloing link for the omplete
installation steps on the offiial FileGilla site
httpsltltiki(fileGilla-proHet(orgltClient)nstallation)nstallingonEindos
Setting +p the FTP Client Softare to aess the 1iretory reated forthe +ser in the FTP Server
gto+ an aess the FTP Program+sing the men+ path
indo G All Pro6rams G Fileilla FTP Client G FileDilla
Figure -A0 + $xecuting the FTP lient
soft1are
)n order to aess the FTP 2sers diretoryyo+ ill need to reate a profile to aess aess it( gto+ do this by going to the
men+ path
File G Site ana6er222
K)
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1227
+se the keyboard short+t of CTL K S
o lik on the e Site b+ttonto reate the Profile for onneting o+r +ser to the FTP Server( ampive it a name7)n o+r ase
it is FTP(ltSE8(
Figure -)0 + reating a ne1 Profile
using the Site Manager
n the right side of site7s8 treeyo+ ill find all settings for logging into the FTP +ser( The ampeneral tab is the most is the
most +sed tab for setting +p FTP redential settings like -ostPortltser Passord e(t(( These are the settings that
ere sethile setting +p the FTP +ser and diretory in the FTP Server( gto+ an also onnet to this profile +sing the
Connet b+tton(
Figure -0 + Setting up ogin
redentials for the Profile
Figure -0 + onnecting to the FTP
user
1iretly onneting to the 2ser after setting it +p in the Site anager
After setting +p the profile in the Site manageryo+ an no +ikly onnet to it +sing the profile dropdonhih ontains a
list of all profilereated for different FTP 2sers( J+st selet it from the drop don and selet the +ser to onnet to it( )f the
ask for passord option as seletedhile setting +p the profilethe +ser ill be prompted to enter in the passord( After
s+essf+l onnetionthe +sers home 1iretory is shon on the left hand sidein the Loal Site setion( gto+ an also
hek the FileGilla FTP server as ell to see the log of hether the +ser as s+essf+lly onneted or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1327
Figure -A0 + Accessing the Site
anager dropdo1n for directl8
connecting to the profile
Figure -)0 + Successfull8 logging
in to the FTP User
Figure -0 + User onnection
log in the FTP Ser6er
Sample program for onneting from an SAP Server to an FTPserver3Senario Type 4 Front5nd6
Typially yo+ reate programs that either +pload data to an FTP Server from an SAP System or gto+ read a file already
+ploaded to an FTP Server in an SAP System e(t(( gto+ typially +se the folloing f+ntions for Comm+niation beteen an
SAP system and an FTP Server
I FTP(=(T)(SEE7SAP to an FTP Server8
I FTP(SEE(T)(=7FTP to an SAP System8
7A82ploading a te9t file from an SAP system to an FTP Server ithSAP 1ata
Before yo+ an proeed ith the +poming real orld sample programs for FTP programming that follomake s+re that yo+
have orretly set+p the FTP Server based on the topis mentioned belo
bull Setting 2p an FTP Server
bull Creating a 2ser in the FTP Server
bull Setting +p a diretory for a 2ser reated in the FTP Server
bull )nstalling the FTP Client Softare
bull Setting +p the FTP Client Softare to aess the 1iretory reated for the +ser in the FTP Server
bull 1iretly onneting to the 2ser after setting it +p in the Site anager
Ehen yo+ are orking ith an FTP Server deployed loally on yo+r mahineyo+ sho+ld +se the SAPFTP 0FC
1estinationfor front end omm+niation(
The sample program that follosill perform the folloing steps
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1427
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill e9trat the ontents of the SFLH-T table in an internal tableTransfer the
ontents of the )nternal table to be +ploaded to the FTP server in the form of a te9t file+sing the FTP(=(T)(SEE
f+ntion mod+le(
( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + Selection riteria
for the Frontend SAP to FTP
file upload progra
Figure -)0 + SAPFTP Frontend
in case of ocal Ser6er
9First tie propt
Figure -0 + FTP ounications
og essages in the FTP
Ser6er
Figure -0 + Final Text file
Generated 6ia the FTP Progra
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1527
So+re Code for 2ploading a te9t file to an FTP Server based on1ATA from the SAP System3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51ASAPTFTP
MM---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 SAP to FTP program for +ploading data from an SAP system
M to an FTP server in te9t file format
M Completed on 4 Oth April $
M Transation Code 4 NSFF5A
M---------------------------------------------------------------------
05P0T Gftpfendasaptoftp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend omm+niatio
ns7Loal Connetions8 (
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord mihandle TgtP5 i(=andle for Pointing to an already
onneted FTP onnetion+sed for s+bse+ent ations on the onneted FTP session
1ATA
itsflight TgtP5 STA1A01 TABL5 F sflightFinal )nternal table to be +ploaded as a Te9t file on an FTP Server
asflight L)5 L)5 F itsflight(
1ata begin of itfinal o+rs $
str78
end of itfinal
afinal like line of itfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1627
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd host 4 pahost
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
S5L5CT arrid onnid fldate planetype seatsma9 seatso
F0 sflight
)T C005SP1)amp F)5L1S F asflight(
APP51 asflight to itsflight(
Final )nternal table ith a String
onatenate asflight-arrid asflight-onnid asflight-fldate asflight-planetype asflight-seatsma9 asflight-
seatso
into afinal-str S5PA0AT51 Bgt (
APP51 afinal to itfinal(
51S5L5CT(
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78( e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 sy-dat+m e9tension )T path (
CALL F2CT) FTP(=(T)(SEEFor Creating a file from SAP 0 to FTP Server
5P0T)amp
handle 4 mihandle
fname 4 path
haratermode 4
TABL5S
te9t 4 itfinalFinal )nternal table to be ritten to the te9t file in the FTP Servers 1iretory
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1727
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
For 1isabling data typed in the FTP 2sers passord fieldat seletion-sreen o+tp+t(
loop at sreen(
if sreen-name 4 PAPSE01(
sreen-invisible 4 (
modify sreen(
endif(
endloop(
7B80eading a te9t file from an FTP Server bak to an SAP System
ne yo+ have +ploaded the te9t file to the FTP serveryo+ ill also need to provide a mehanism to read that te9t file bak
into SAP( This is +sef+l for appliations that reate log files or data files and they need to be read bak in SAP for reporting
p+rposes( This is ahieved by +sing a standard f+ntion mod+le named FTP(SEE(T)(=for reading FTP data bak
to SAP(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to read the log or te9t file +ploaded via the previo+s program to an FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill read the ontents of the file +ploaded to an FTP server in the form of string
based internal table(The ontents of the file ill be read +sing the FTP(SEE(T)(= f+ntion mod+le(
( The ontents of the file ill be mapped to an internal tableso that it an be shon in an ALD report(
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1827
Figure -A0 + Selection riteria
frontend FTP to SAP file ead
Progra
Figure -)0 + File to e ead
as a6ailale in the FTPSer6er
Figure -0 + Final ead eport
in A including FTP Ser6er og
lthen the File is ead
So+re Code for 0eading a te9t file from an FTP Server into the SAPSystem3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51BFTPTSAP05A1
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 0eading +ploaded data from an FTP
M Server3Te9t File6 to an SAP System in an )nternal Table
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5B05A1
M---------------------------------------------------------------------
05P0T Gftpfendbftptosapread STA1A01 PAamp5 =5A1)amp(
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8 filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 1927
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
TgtP5-PLS slis(ALD
1ATA B5amp) F itfinal CC20S $ Total Length of the data e9trated from the Sflight f ields 4 O haraters
str78
51 F itfinal
afinal L)5 L)5 F itfinal(
1ATA B5amp) F itabfinal CC20S $)nternal table for 1isplaying data from the file in the FTP Server to an SAP System
+sing ALD
arrid TgtP5 L5ampT= arrid type sflight-arrid
onnid TgtP5 L5ampT= onnid type sflight-onnid
fldate TgtP5 L5ampT= $fldate type sflight-fldate
planetype TgtP5 L5ampT= $planetype type sflight-planetype
51 F itabfinal
aitabfinal L)5 L)5 F itabfinal(
FTP Comm+niation 1ata bHets - 3516
S5T 5T5151 C=5C FF(
mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) -TTP(SCALEFor 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTP(C)ECTFor onneting to the FTP Servers +ser diretory 5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2027
CALL F2CT) FTP(SEE(T)(=For 0eading a file from the FTP Server to the SAP System
5P0T)amp
handle 4 mihandle
fname 4 path
BLBL5ampT= 4
haratermode 4 C
TABL5S
te9t 4 itfinalFinal )nternal table That ontains the string from te9t file read from the FTP Server
5C5PT)S
tpiperror 4
ommanderror 4
dataerror 4
T=50S 4 (
)F sy-s+br 4 $()f File is read S+essf+lly
15L5T5 itfinal E=505 str 4 ()t 0et+rns ith a Blank reord at the endso that the empty string reord is deleted
so that it an be properly mapped to an internal Table
P50F0 map(data(aps data from the FTP file to an )nternal Table
CALL F2CT) FTP(9SC)ECTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
P50F0 sho(data(Shos the data e9trated from the file on the FTP Server in ALD form
5LS5)F sy-s+br QI $()f File is not read s+essf+lly
E0)T5 lt File ot 0ead from the FTP Server(
51)F(
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
M---------------------------------------------------------------------
M S+b-0o+tine AP1ATA
M---------------------------------------------------------------------
M 1esription 4 aps the data from the file string to an )nternal
M Table to be displayed as an ALD 0eport
M---------------------------------------------------------------------
F0 mapdata(
LP AT itfinal )T afinal(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2127
aitabfinal-arrid 4 afinal-str78(
aitabfinal-onnid 4 afinal-strK78(
aitabfinal-fldate 4 afinal-strK78(
aitabfinal-planetype 4 afinal-strK7$8(
APP51 aitabfinal T itabfinal(
51LP(
51F0( AP1ATA
M---------------------------------------------------------------------
M S+b-0o+tine S=E1ATA
M---------------------------------------------------------------------
M 1esription 4 1isplays the data loaded from the te9t file in the FTP
M Server to an )nternal Table in ALD Form
M---------------------------------------------------------------------
F0 shodata(
1ATA fieldatalog TgtP5 slistfieldatalv E)T= =5A150 L)5(
fieldatalog-fieldname 4 CA00)1( f ieldatalog-selte9tl 4 Airline Code(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 C)1(
fieldatalog-selte9tl 4 Flight Connetion +mber(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 FL1AT5(
fieldatalog-selte9tl 4 Flight date(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
fieldatalog-fieldname 4 PLA5TgtP5(
f ieldatalog-selte9tl 4 Airraft Type(
fieldatalog-tabname 4 )TABF)AL(
fieldatalog-o+tp+tlen 4 $(
APP51 fieldatalog T fieldatalog(
CL5A0 fieldatalog(
1ATA islayo+t TgtP5 slislayo+talv
gdrepid L)5 sy-repid (
speifying alv layo+t
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2227
CL5A0 islayo+t(
islayo+t-olidthoptimiGe 4 (
islayo+t-Gebra 4 (
gdrepid 4 sy-repid(
CALL F2CT) 052S5ALDamp0)11)SPLAgt
5P0T)amp
))T50FAC5C=5C 4
)BgtPASS)ampB2FF50 4
)B2FF50ACT)D5 4
iallbakprogram 4 gdrepid
)CALLBACPFSTAT2SS5T 4
)CALLBAC2S50CA1 4
)CALLBACTPFPAamp5 4
)CALLBAC=TLTPFPAamp5 4
)CALLBAC=TL51FL)ST 4
itfieldat 4 fieldatalog36
istr+t+rename 4 NP0T
)BACamp021)1 4
igridtitle 4 FTP File 0ead 0eport
)amp0)1S5TT)ampS 4
islayo+t 4 islayo+t
)TF)5L1CAT 4
)T5CL21)amp 4
)TSP5C)ALamp02PS 4
)TS0T 4
)TF)LT50 4
)SS5L=)15 4
idefa+lt 4
isave 4 A
)SDA0)AT 4
)T5D5TS 4
)T5D5T5)T 4
)SP0)T 4
)S05P05P)1 4
)SC055STA0TCL2 4 $
)SC055STA0TL)5 4 $ )SC05551CL2 4 $
)SC05551L)5 4 $
)=TL=5)amp=TTP 4 $
)=TL=5)amp=T51 4 $
)TALDamp0AP=)CS 4
)T=gtP50L) 4
)TA11F)5L1CAT 4
)T5C5PTR)F 4
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2327
)0SALDF2LLSC055A1APT50 4
)P0T)amp
55)TCA2S51BgtCALL50 4
5S5)TCA2S51Bgt2S50 4
TABL5S
to+ttab 4 itabfinal 5C5PT)S
programerror 4
T=50S 4
(
)F sy-s+br QI $(
5SSAamp5 )1 sy-msgid TgtP5 sy-msgty 2B50 sy-msgno
E)T= sy-msgv sy-msgv sy-msgv sy-msgv(
51)F(
51F0( S=E1ATA
7C81eleting a file from an FTP Server
gto+ an also delete files +ploaded to an FTP Server( To ahieve thisyo+ an make +se of the FTP(C)A9 f+ntion
mod+le for seeking o+t the list of files in the +rrent FTP diretory and also for deleting the speifi file in the 1iretory( =ere
yo+ ill need to make +se of the FTPCA1 f+ntion ith a ommand of deletehih is +sed for deleting files from
the +rrent orking diretory of the FTP Server( gto+ ill need to onatenate the name of the f ile ith the delete ommand
separated by a spae and pass it to the ommand parameter(
otes
I )f there is no rite aess to the FTP =ome diretorythan yo+ might get errors ith regards to deleting a fileso do
maks+re that rite aess is enabled( see the setion on setting +p the FTP Server for more details(
The sample program that follosill perform the folloing steps
( 2ser ill f ill in FTP +ser redentials in )np+t Parameters like ltser PassordFTP P Address and FC
9estination(
( 2ser ill fill in the date parameter to delete the file based on the naming onvention hen these files ere reated
on the FTP Server(
( )t ill sramble the passord entered via the -TTP(SCALE F+ntion od+le(
( )t ill then onnet to the FTP server via the FTP(C)ECT f+ntion mod+le(
( After a s+essf+l onnetion it ill onatenate the delete ommand ith the file name and pass it to the f+ntion
mod+le named FTP(C)A9 for deleting the file off the FTP Server( This deletion of file ill be arried o+t if the9elete
File hekbo9 is he5ed(
( A list report like log ill be generated after the ommand has been e9e+ted hether it as s+essf+l or not(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2427
O( Finallyit ill disonnet from the FTP Connetion session+sing the FTP(9SC)ECT f+ntion mod+le(
Figure -A0 + File to e eleted
on FTP Ser6er
Figure -)0 + Selection riteria
of the FTP file deletion progra
Figure -0 + og after Successful
File eletion
Figure -0 + File eleted fro
the (oe irector8 of FTPSer6er
So+re Code for 1eleting a te9t file from an FTP Server via theFTPCA1 F+ntion od+le3Front5nd6
M---------------------------------------------------------------------
M 0eport NFTPF51CFTPTSAP15L5T5
M
M---------------------------------------------------------------------
M 1eveloper 4 Fahad Javed
M od+le 4 ABAP
M Library 2sed 4 SAPFTP
M 1esription 4 FTP to SAP program for 1eleting a file from an FTP Server
M based on date seletion of the generated file
M Completed on 4 th J+ne $
M Transation Code 4 NSFF5C15L5T5
M---------------------------------------------------------------------
05P0T Gftpfendftptosapdelete STA1A01 PAamp5 =5A1)amp(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2527
FTP Comm+niation 1ata bHets - 3STA0T6
S5L5CT)-SC055 B5amp) F BLC a E)T= F0A5 T)TL5 te9t-$$(
PA0A5T50S
pa+ser TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gtFTP Server 2ser
papsrd TgtP5 L5ampT= $ LE50 CAS5 BL)ampAT0gt FTP Server 2sers Passord
pahost TgtP5 L5ampT= LE50 CAS5 BL)ampAT0gt)P Address of the FTP Server
parfds L)5 rfdes-rfdest BL)ampAT0gt 15FA2LT SAPFTP 0FC 1estinationSAPFTP for Frontend
omm+niations7Loal Connetions8
filedt TgtP5 sy-dat+m BL)ampAT0gt 15FA2LT sy-dat+m The 1ate hen the file as +ploaded to FTP Server
filedel type as C=5CB
(
S5L5CT)-SC055 51 F BLC a(
1ATA
mikey TgtP5 i DAL25 $O=ardoded =andler eyThis is alays $O
mipdlen TgtP5 i For finding the length of the PassordThis is +sed hen srambling the passord
mihandle TgtP5 i(=andle for Pointing to an alerady onneted FTP onnetion+sed for s+bse+ent ations on the
onneted FTP session
FTP Comm+niation 1ata bHets - 3516
File 1eletion 1ata bHets - 3STA0T6
data begin of res+lt o+rs $
line7$$8 type
end of res+lt(
data
ompress type DAL25
fldelm type length $(File deletion ommand along ith the file path to file
File 1eletion 1ata bHets - 3516
S5T 5T5151 C=5C FF(mipdlen 4 ST0L57 papsrd 8(
CALL F2CT) =TTPSC0ABL5For 5nrypting the Passord
5P0T)amp
S20C5 4 papsrd
so+relen 4 mipdlen
key 4 mikey
)P0T)amp
destination 4 papsrd(
CALL F2CT) FTPC5CTFor onneting to the FTP Servers +ser diretory
5P0T)amp
+ser 4 pa+ser
passord 4 papsrd
host 4 pahost
=ST 4 O($($()P address of the FTP Server(in ase if it is onfig+red as a te9thost name is ase
sensitive
rfdestination 4 parfds 2sing the Bakgro+nd SAP FTP Library as part of the SAP bakend System
)P0T)amp
handle 4 mihandle
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2627
5C5PT)S
notonneted 4
T=50S 4 (
)F sy-s+br 4 $(Ehen FTP onnetion established S+essf+lly
1ATA path78 (Path that points to the FTP 2sers =ome 1iretory
1ATAe9tension78(59tension of the file
e9tension 4 (1AT (
CCAT5AT5 ltFTPBACamp021F)L5 filedt e9tension )T path (
P50F0 FTPF)L515L5T5(1eletes the seleted file from the FTP Server
CALL F2CT) FTP1)SC5CTFor 1isonneting the onneted FTP Session
5P0T)amp
handle 4 mihandle
5C5PT)S
T=50S 4 (
all f+ntion 0FCC5CT)CLS5
e9porting
destination 4 parfds
e9eptions
others 4 (
5LS5(Ehen FTP onnetion Fails
E0)T5 lt 5rror in FTP Command(
51)F(
M---------------------------------------------------------------------
M S+b-0o+tine FTPF)L515L5T5
M---------------------------------------------------------------------
M 1esription 4 1eletes the File residing on the FTP Server
M ith the seleted file based on the date parameter
M---------------------------------------------------------------------
F0 FTPF)L515L5T5(
if filedel 4 (1elete filehen heked
CCAT5AT5 delete path into fldelm S5PA0AT51 Bgt spae(1eletion Command K file Path
CALL F2CT) FTPCA1
5P0T)amp
=A1L5 4 mihandle
ommand 4 fldelm
CP05SS 4 ompress
D50)Fgt 4
)P0T)amp
F)L5S)N5 4
F)L51AT5 4
F)L5T)5 4
tables
data 4 res+lt
5C5PT)S
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(
8192019 The SAPFTP Library - FTP Programming in ABAP
httpslidepdfcomreaderfullthe-sapftp-library-ftp-programming-in-abap 2727
TCP)P5000 4
CA15000 4
1ATA5000 4
T=50S 4
(
For riting in the ommands e9e+ted d+ring FTP peration - 3STA0T6 loop at res+lt(
rite at lt res+lt-line(
endloop(
refresh res+lt(
For riting in the ommands e9e+ted d+ring FTP peration - 3516
)F sy-s+br QI $(
5SSAamp5 )1 Sgt-Samp)1 TgtP5 Sgt-SampTgt 2B50 Sgt-Samp
E)T= Sgt-SampD Sgt-SampD Sgt-SampD Sgt-SampD(
51)F(
else(dont delete file hen +nheked
endif(File 1eletion Parameter hek
51F0(
For 1isabling data typed in the FTP 2sers passord field
AT S5L5CT)-SC055 2TP2T(
LP AT SC055(
)F sreen-name 4 PAPSE01(
sreen-invisible 4 (
1)Fgt SC055(
51)F(
51LP(