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?
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.