Skip to Content

FTP_R3_TO_SERVER - does not sends all files

Hello SCN Members,

We have a requirement to transfer an XML and few PDF's to an external FTP location.

The XML contains delivery information(let's say 8 deliveries) and PDF's are invoices for these 8 deliveries.

Everything works fine, except sometimes one or more invoice PDF's are not in the FTP.

If we rerun the process, the file is sent correctly.

Adding the code. Any ideas how to resolve this?

Should a wait be added to make sure there is enough time to write the file to ftp before sending another write request?

FORM file_to_ftp .

   DATA  : lv_dest           TYPE rfcdes-rfcdest VALUE 'SAPFTPA',

           lv_slen           TYPE i,

           lv_len            TYPE i,

           lv_command(120)   TYPE c,

           lv_outfile        LIKE rlgrap-filename,

           lv_key            TYPE i VALUE 26101957,

           lv_handle         TYPE i,

           lt_tab            TYPE tsfixml,

           lt_result        TYPE TABLE OF text WITH HEADER LINE.

   CLEAR gv_ftp_error .

   IF lv_handle IS INITIAL.

     lv_slen = STRLEN( gs_3pl_definition-password ).

     CALL FUNCTION 'HTTP_SCRAMBLE'

       EXPORTING

         SOURCE      = gs_3pl_definition-password

         sourcelen   = lv_slen

         key         = lv_key

       IMPORTING

         destination = gs_3pl_definition-password.

     CALL FUNCTION 'FTP_CONNECT'

       EXPORTING

         user            = gs_3pl_definition-userid

         password        = gs_3pl_definition-password

         host            = gs_3pl_definition-ftp

         rfc_destination = lv_dest

       IMPORTING

         handle          = lv_handle

       EXCEPTIONS

         not_connected   = 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.

*  HOME OR ROOT

     CONCATENATE 'cd' '/..' INTO lv_command SEPARATED BY ' '.

     REFRESH lt_result.

     CALL FUNCTION 'FTP_COMMAND'

       EXPORTING

         handle        = lv_handle

         command       = lv_command

         verify        = 'X'

       TABLES

         data          = lt_result

       EXCEPTIONS

         tcpip_error   = 1

         command_error = 2

         data_error    = 3.

     CONCATENATE 'cd' gs_3pl_definition-path INTO lv_command SEPARATED BY ' '.

     REFRESH lt_result.

     CALL FUNCTION 'FTP_COMMAND'

       EXPORTING

         handle        = lv_handle

         command       = lv_command

         verify        = 'X'

       TABLES

         data          = lt_result

       EXCEPTIONS

         tcpip_error   = 1

         command_error = 2

         data_error    = 3.

     lv_command = 'set passive on'.

     CALL FUNCTION 'FTP_COMMAND'

       EXPORTING

         handle        = lv_handle

         command       = lv_command

         verify        = 'X'

       TABLES

         data          = lt_result

       EXCEPTIONS

         tcpip_error   = 1

         command_error = 2

         data_error    = 3.

     CONCATENATE gv_date 'Nuskin' gv_time '.xml' INTO lv_outfile SEPARATED BY '_'.

     IF gv_reprint = 'X'.

       CONCATENATE 'R-' lv_outfile INTO lv_outfile.

     ENDIF.

     CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

       EXPORTING

         buffer        = ixml

       IMPORTING

         output_length = lv_len

       TABLES

         binary_tab    = lt_tab.

     CALL FUNCTION 'FTP_R3_TO_SERVER'

       EXPORTING

         handle        = lv_handle

         fname         = lv_outfile

         blob_length   = lv_len

       TABLES

         blob          = lt_tab

       EXCEPTIONS

         tcpip_error   = 1

         command_error = 2

         data_error    = 3

         OTHERS        = 4.

     IF sy-subrc <> 0.

       gv_ftp_error = 'X'.

     ENDIF.

     SORT gt_pdf_temp BY vbeln.

     LOOP AT gt_pdf_temp INTO wa_pdf_temp.

       READ TABLE gt_results WITH KEY vgbel = wa_pdf_temp-vbeln.

       IF sy-subrc = 0.

         REFRESH lt_tab.

         lv_outfile = wa_pdf_temp-pdf_key.

         lv_outfile(8) = gv_date.

         lv_outfile+20(6) = gv_time.

         IF gv_reprint = 'X'.

           CONCATENATE 'R-' lv_outfile INTO lv_outfile.

         ENDIF.

         CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

           EXPORTING

             buffer        = wa_pdf_temp-pdf_string

           IMPORTING

             output_length = lv_len

           TABLES

             binary_tab    = lt_tab.

         IF sy-subrc = 0.

           CALL FUNCTION 'FTP_R3_TO_SERVER'

             EXPORTING

               handle        = lv_handle

               fname         = lv_outfile

               blob_length   = lv_len

             TABLES

               blob          = lt_tab

             EXCEPTIONS

               tcpip_error   = 1

               command_error = 2

               data_error    = 3

               OTHERS        = 4.

           IF sy-subrc <> 0.

             gv_ftp_error = 'X'.

           ENDIF.

         ENDIF.

         DELETE FROM zpdf_temp WHERE pdf_key = wa_pdf_temp-pdf_key.

       ENDIF.

       CLEAR : wa_pdf_temp, lv_len.

     ENDLOOP.

     CALL FUNCTION 'FTP_DISCONNECT'

       EXPORTING

         handle = lv_handle.

     CALL FUNCTION 'RFC_CONNECTION_CLOSE'

       EXPORTING

         destination = lv_dest

       EXCEPTIONS

         OTHERS      = 1.

   ENDIF.


ENDFORM.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Oct 27, 2015 at 10:31 AM

    In the FTP_COMMAND you should manage the returned code and the log returned in DATA to build your own log, in other FTP FM, analyze the return codes/error messages.


    Regards,

    Raymond    

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Richa Singh

      Hi Richa,

      As Raymond is rightly mentioning, you may need to patiently check if the logic is getting called for all the 56 PDF's in your case.

      Just a hunch, it might be a failure of the function module call CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' (the call within the LOOP...ENDLOOP) in all those four cases mentioned by you. Kindly handle ELSE part for IF SY-SUBRC = 0 check for this function module call and place a break point within the ELSE part to check if the call is failing for those 4 entries mentioned by you. Then you might understand the issue.


      Regards,

      Kiran

  • avatar image
    Former Member
    Dec 10, 2015 at 06:02 AM

    I dont know if this is still relevant to you but why not make your life easier by using 3rd-party-tools?

    For simple File-transfer just use Filezilla but for scripts and such you could use SysaxAutomation (sysax.com) and create automated scripts.

    Add comment
    10|10000 characters needed characters exceeded