DATA: IT_FTP TYPE STANDARD TABLE OF ZFTPSERVERLIST ,
WA_FTP TYPE ZFTPSERVERLIST,
L_SLEN TYPE I,
LV_USER(30) TYPE C,
LV_PWD(30) TYPE C,
C_KEY TYPE I VALUE 26101957.
DATA: TO_FILE TYPE CHAR300.
DATA: MI_HANDLE TYPE I.
DATA: itab1 TYPE truxs_t_text_data.
PERFORM CONVERT_TO_CSV.
PERFORM SERVER_CONN.
PERFORM R3_FTP USING TO_FILE.
FORM convert_to_csv .
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
i_field_seperator = ','
I_LINE_HEADER = 'X'
TABLES
i_tab_sap_data = ITAB[] " final file
"FIELDNAMES = T_DESC " for header file
CHANGING
i_tab_converted_data = itab1[]
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
FORM r3_ftp USING p_to_file.
""""" SEND FILE TO SERVER""""""
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
HANDLE = MI_HANDLE
FNAME = TO_FILE "file path of destination system
CHARACTER_MODE = 'X'
TABLES
TEXT = itab1
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4.
IF sy-subrc <> 0.
WRITE : / 'FILE NOT SEND'.
ELSE.
WRITE : / 'FILE SEND'.
ENDIF.
ENDFORM.
FORM server_conn .
SELECT * FROM ZFTPSERVERLIST CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF TABLE IT_FTP
WHERE MANDT = SY-MANDT
AND ZCOUNTRY = 'BD'.
CLEAR WA_FTP.
READ TABLE IT_FTP INTO WA_FTP INDEX 1.
*----CONNECTING TO FTP SERVER.
PERFORM FTP_CONNECT USING WA_FTP-ZUSER WA_FTP-ZPASSWD WA_FTP-ZHOST.
*----CHECKING SUCCESSFUL FTP CONNECTION
CHECK SY-SUBRC = 0.
CLEAR: TO_FILE.
" FILE NAME CREATIONN
CONCATENATE WA_FTP-zapp 'test' '_' DATE '.csv' INTO TO_FILE.
ENDFORM.
FORM ftp_connect USING LV_USER LV_PWD LV_HOST.
L_SLEN = STRLEN( LV_PWD ).
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE = LV_PWD
SOURCELEN = L_SLEN
KEY = C_KEY
IMPORTING
DESTINATION = LV_PWD.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
USER = LV_USER "Your SAP-UNIX FTP user name (case sensitive)
PASSWORD = LV_PWD "Your SAP-UNIX server host name (case sensitive)
HOST = LV_HOST
RFC_DESTINATION = 'SAPFTPA'
IMPORTING
HANDLE = MI_HANDLE
EXCEPTIONS
NOT_CONNECTED = 1
OTHERS = 2.
ENDFORM.
Serkan AKKAVAK
Computer Engineer BSc
SAP Department Manager
Contact : serkurumsal@yandex.com
0 Comments