Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy a PDF file from an FTP server to my SAP application server OS level directory (AL11)

jay_johnson4
Explorer
0 Kudos

I have a requirement to pull a PDF file from an FTP server and then write the exact same file to a folder in the SAP AL11 directory.

I am successfully connecting to and getting the date from the FTP server using several SAP standard function modules including FTP_SERVER_TO_R3.

That returns a BLOB table.

What I am having trouble is writing that BLOB data out to AL11 in a valid file that can then be opened.

The blob table returned by the FTP_SERVER_TO_R3 function is in GT_DATA

OPEN DATASET p_file2 FOR OUTPUT IN BINARY MODE.
IF sy-subrc EQ 0.

clear: lv_xstring.
LOOP AT gt_data into gs_data.
move gs_data to wa.
ASSIGN wa TO <hex_container> CASTING.
CONCATENATE lv_xstring <hex_container>
INTO lv_xstring IN BYTE MODE.
* endif.
ENDLOOP.
TRANSFER lv_xstring TO p_file2.
CLOSE DATASET p_file2.

I have also tried using the following function to convert the BLOB to XSTRING.

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = gv_len
IMPORTING
BUFFER = X_CONTENT
tables
binary_tab = gt_data
EXCEPTIONS
FAILED = 1
OTHERS = 2.

Then I transfer the X_CONENT to the file and close the file.

Neither approach seems to work.

Any suggestions would be appreciated.

Jay

1 REPLY 1

Sandra_Rossi
Active Contributor

You may simplify a lot !

Take your blob table of type SOLIX_TAB, then convert to XSTRING via

xstring = CL_BCS_CONVERT=>solix_to_xstring( IT_SOLIX = blob_table IV_SIZE = blob_length ).

Write the XSTRING, don't loop:

OPEN DATASET file FOR OUTPUT IN BINARY MODE.
TRANSFER xstring TO file.
CLOSE DATASET file.