Tuesday, May 6, 2008

Sample ABAP Program of FTP Function Module

FUNCTION Y_FTP.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(USER)
*" VALUE(PWD)
*" VALUE(HOST)
*" TABLES
*" COMMANDS
*" EXCEPTIONS
*" NO_SUCH_FILE
*"----------------------------------------------------------------------

DATA: W_USER(12) TYPE C ,
W_PWD(20) TYPE C ,
W_HOST(64) TYPE C.

DATA: HDL TYPE I,
KEY TYPE I VALUE 26101957,
DSTLEN TYPE I.

DATA: BEGIN OF RESULT OCCURS 0,
LINE(100) TYPE C,
END OF RESULT.

DESCRIBE FIELD PWD LENGTH DSTLEN.

CALL 'AB_RFC_X_SCRAMBLE_STRING'
ID 'SOURCE' FIELD PWD ID 'KEY' FIELD KEY
ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD PWD
ID 'DSTLEN' FIELD DSTLEN.

CALL FUNCTION 'FTP_CONNECT'
EXPORTING
USER = USER
PASSWORD = PWD
HOST = HOST
RFC_DESTINATION = 'SAPFTP'
IMPORTING
HANDLE = HDL.

LOOP AT COMMANDS.
IF COMMANDS NE ' '.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
HANDLE = HDL
COMMAND = COMMANDS
TABLES
DATA = RESULT
EXCEPTIONS
COMMAND_ERROR = 1
TCPIP_ERROR = 2.
LOOP AT RESULT.
WRITE AT / RESULT-LINE.
IF RESULT CS 'error'.
RAISE NO_SUCH_FILE.
ENDIF.
ENDLOOP.
REFRESH RESULT.
ENDIF.
ENDLOOP.

CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
HANDLE = HDL.




ENDFUNCTION.

No comments:

Blog Archive