Tuesday, July 17, 2007

FTP



SAP provide sample code to connect to FTP.

It provided in SAP function module, FTP_CONNECT (connect to FTP), FTP_COMMAND (send command by FTP), FTP_DISCONNECT (disconnect),FTP_R3_TO_SERVER (put file to FTP),FTP_SERVER_TO_R3 (get file from FTP).

Instead of writing a new code, I will try to give you explanation on SAP sample code.

I will explore program RSFTP002.


Program RSFTP002 demonstrate how to send command to FTP.



You can send any FTP command by this program.
For RFC destination use SAPFTP or SAPFTPA. Those are standard RFC destination to connect to FTP. SAPFTP run on client, and SAPFTPA run on application server.

First step of this program is using FTP_CONNECT, don't forget to use scrambled password.
Then we send a command to FTP by using FTP_COMMAND.
To disconnect, use FTP_DISCONNECT.

To copy, or get a file from SAP to/from FTP, you can explore RSFTP002. It demonstrate how to use FTP_R3_TO_SERVER (put file to FTP) & FTP_SERVER_TO_R3 (get file from FTP).
Other way is send put command using FTP_COMMAND. To put a file, do this steps, change FTP directory using "cd dir", change local directory using "lcd localdir", then send put command "put file".

11 komentar:

Rose said...

Hello alionzo,

I have done one interface program.In that i am getting one text file data by using FTP connections successfully.
FTP_CONNECT
FTP_COMMAND
FTP_CLIENT_TO_R3
FTP_R3_TO_CLIENT

Now my requirement has been changed to get excel file data instead of text file data from the non sap server.
So please help me if any one knows solution.

I have tried in same way as getting text file data.but it is going to dump and some times getting some #$## like this in my internal table.

So pls guide me what is the procedure to get excel file data from other server by using FTP connections only.

Regards,
Rose.

alionzo said...

Hi Rose,

FTP is about copying file, opening excel file is another process.
I suggest you to put it into 2 separate process:

First, copy file from remote server into local server.

Second, open excel file using ABAP OLE automation. Just search in google with keyword "ABAP excel".

Hope it help,
regards,
Alionzo

Rose said...

Hello alionzo,

Could you please elaborate on ABAP OLE automation. Thanks in advance

Rose.

alionzo said...

Here is the definition in wikipedia:
http://en.wikipedia.org/wiki/OLE_Automation

In simple words: ABAP did not recognized Excel format, so to make an excel file readable, ABAP must use OLE as an interpreter.

Here is the sample of accessing excel from ABAP:
http://www.guidancetech.com/people/holland/sap/abap/zzbgs700.htm

Rose said...

Hello alionzo,

Thank you. The sites were helpful too.

Regards,
Rose.

Rose said...

Hello alionzo,

Is it not possible to schedule the FTP_CONNECT, FTP_R3_TO_SERVER FM in background?

Regards
Rose.

alionzo said...

Yes, it is possible to schedule FTP function module in background.
To make sure, use SAPFTPA instead SAPFTP in RFC destination. Because SAPFTP run on client, and SAPFTPA run on application server.

Anonymous said...

Hi. Do you know the reason why when I ftp file to the server, the contents of the internal table from SAP is in the single line? If for example I have 12 records in the internal table, when I transfer it to the server, all the 12 records are in a single row. I need to show all the records as it is in the internal table. Please help.

Anonymous said...

Any one can help

I have to read vender data from sap into a text file , then I have to send the file to an SQL server .

How can I do that

Malu
regrads

alionzo said...

to export SAP data to SQL server you can use SAP Automation (RFC).
Here is link if you want to explore more:
http://help.sap.com/saphelp_46c/helpdata/en/d8/44cb66ac3c11d189c60000e829fbbd/frameset.htm

or you can open google, find "SAP Visual Basic"

Anonymous said...

Hello Alionzo , Need your suggestion for transfering spool output which is in PDF format to Portal server .

Can we use these FTP functions to transfer SPOOL output(which is stored in R/3 server ) as PDF to another Server . Please help as I have to publish one of my query output which is in spool to portal server .

Regards,
KA