Sunday, April 3, 2016

Convert csv file and send to ftp server

DATAIT_FTP TYPE STANDARD TABLE OF ZFTPSERVERLIST ,
      WA_FTP 
TYPE ZFTPSERVERLIST,
      L_SLEN 
TYPE I,
      LV_USER
(30TYPE C,
      LV_PWD
(30TYPE C,
      C_KEY 
TYPE I VALUE 26101957.

DATATO_FILE TYPE CHAR300.
DATAMI_HANDLE TYPE I.
DATAitab1  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.
  
CLEARTO_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 
STRLENLV_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.

25 comments:

  1. hello experts.. how to create BAPI...plz hlp me with an example........thnkssss

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. It was so nice article.I was really satisified by seeing this article sap hana videos.

    ReplyDelete
  4. Thanks for the great information in your blog on It was so nice articlesap video tutorials

    ReplyDelete
  5. I am planning to join sap abap with them after reading your blog.
    Hope the best will turn out.
    Call them at 8122241286 in chennai.
    www.thecreatingexperts.com

    ReplyDelete
  6. We provide sap abap technical course, call us to know more about us and join with us.
    Call them at 8122241286 in chennai.
    www.thecreatingexperts.com

    ReplyDelete
  7. I get a lot of great information from this blog on sap video tutorials

    ReplyDelete
  8. Thanks for the great information in your blog on It was so nice article Thank you for valuable informationsap video tutorials

    ReplyDelete
  9. Good post! Thanks for sharing this Information.The information you Provided is much useful on sap video

    ReplyDelete
  10. Thank you for giving this best information. It’s a very nice topic.sap video

    ReplyDelete
  11. It was so nice article.I was really satisified by seeing this article sap video

    ReplyDelete
  12. Well it Was Very Good Information. Thanks for sharing this Information.sap video

    ReplyDelete
  13. Thank you sir.I am very greatful to you that you share very informative post with us sap video

    ReplyDelete
  14. Thank you sir.Thankyou for information excellent blog have a great possible sap video

    ReplyDelete
  15. Thanks for the great information in your blog on It was so nice article sap video

    ReplyDelete
  16. I 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

    http://thecreatingexperts.com/sap-abap-training-in-chennai/


    contact +91-08122241286

    ReplyDelete
  17. SAP ABAP training is provided in CHENNAI.

    THE 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

    ReplyDelete
  18. Thank you for Wonderful information.

    SAP ABAP training in CHENNAI BY THE CREATING EXPERTS

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    CONTACT 8122241286

    ReplyDelete
  19. Thankyou for wonderful article. It has more Information in Your Website sap video training.

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete