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.
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.
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.
hello experts.. how to create BAPI...plz hlp me with an example........thnkssss
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThank you for your excellent and valuable content,Great blog.
ReplyDeleteSAP ABAP Online Training
SAP ABAP Online Training in Hyderabad
Online SAP ABAP Training in USA
It was so nice article.I was really satisified by seeing this article sap hana videos.
ReplyDeleteThanks for the great information in your blog on It was so nice articlesap video tutorials
ReplyDeleteI am planning to join sap abap with them after reading your blog.
ReplyDeleteHope the best will turn out.
Call them at 8122241286 in chennai.
www.thecreatingexperts.com
We provide sap abap technical course, call us to know more about us and join with us.
ReplyDeleteCall them at 8122241286 in chennai.
www.thecreatingexperts.com
Thank you for your post on sap video tutorials.
ReplyDeleteThank you for your post on sap video tutorials.
ReplyDeleteI get a lot of great information from this blog on sap video tutorials
ReplyDeleteThanks for the great information in your blog on It was so nice article Thank you for valuable informationsap video tutorials
ReplyDeleteGood post! Thanks for sharing this Information.The information you Provided is much useful on sap video
ReplyDeleteThank you for giving this best information. It’s a very nice topic.sap video
ReplyDeleteIt was so nice article.I was really satisified by seeing this article sap video
ReplyDeleteWell it Was Very Good Information. Thanks for sharing this Information.sap video
ReplyDeleteThank you sir.I am very greatful to you that you share very informative post with us sap video
ReplyDeleteThank you sir.Thankyou for information excellent blog have a great possible sap video
ReplyDeleteThanks for the great information in your blog on It was so nice article sap video
ReplyDeleteI have been a blogger too but you post much technical details. Thank you for sharing your knowledge. The creating experts was my first trainer in SAP ABAP got in depth learning from them
ReplyDeletehttp://thecreatingexperts.com/sap-abap-training-in-chennai/
contact +91-08122241286
SAP ABAP training is provided in CHENNAI.
ReplyDeleteTHE CREATING EXPERTS is one of the leading trainer in SAP who provides real time training
http://thecreatingexperts.com/sap-abap-training-in-chennai/
contact 8122241286
Thank you for Wonderful information.
ReplyDeleteSAP ABAP training in CHENNAI BY THE CREATING EXPERTS
http://thecreatingexperts.com/sap-abap-training-in-chennai/
CONTACT 8122241286
It has Wonderful Information on sap remote access 24x7 available.
ReplyDeleteThankyou for wonderful article. It has more Information in Your Website sap video training.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteits too informative blog,Thank you for sharing.
ReplyDeleteSAP ABAP Training Institute in Noida