Application Development and Automation 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: 
Read only

fm or method for converting doc,pdf or text files to binary format

Former Member
0 Likes
4,056

Hello,

Are you aware of any function module or method which takes input as a file of type doc, pdf or text files and convert it to binary format? Kindly let me know.

This is what i tried and was unsuccessful.

i tried using gui_upload method and pass " asc" as file type while importing file of type .doc but it returns me string filled with strange characters.

I did try converting this string to xstring using cl_proxy_service=>cstring2xstring but i realized my 1st step of uploading file itself was wrong.

Please let me know what can be done if you are aware of how to convert file of various types to binary.

thanks

Pooja

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,813

Try this FM,

C13Z_FILE_UPLOAD_BINARY – Uploads a file in binary format

C13Z_FILE_DOWNLOAD_BINARY – Downloads a file in binary format

and i think you should use 'BIN' in the gui_upload .

Hello,

Are you aware of any function module or method which takes input as a file of type doc, pdf or text files and convert it to binary format? Kindly let me know.

This is what i tried and was unsuccessful.

i tried using gui_upload method and pass " asc" as file type while importing file of type .doc but it returns me string filled with strange characters.

I did try converting this string to xstring using cl_proxy_service=>cstring2xstring but i realized my 1st step of uploading file itself was wrong.

Please let me know what can be done if you are aware of how to convert file of various types to binary.

thanks

Pooja

3 REPLIES 3
Read only

Former Member
0 Likes
1,813

Hello,

If you want to read a Word file as a Word file directly - i.e. not converted to text - then you have to work out/find out the internal format, and write a program to handle it. Effectively an ABAP version of a Word Document viewer. Applications such as Open Office have managed to do this, but I think even with their source code, you'd have a very difficult task on your hands.

If you are using the latest version of Word (2007), then you can comparitively easily write an XML parser for Microsoft Open Office XML (OOXML)

It may be possible to write a Word VBA macro that extracts the information from the Word Document, which you could call from ABAP using OLE. But again, a lot depends on your SAP version and your version of Word.

Of course, you can simplify the problem dramatically by converting the word document to a text format, then reading the text file by GUI_UPLOAD.

Read only

Former Member
0 Likes
1,814

Try this FM,

C13Z_FILE_UPLOAD_BINARY – Uploads a file in binary format

C13Z_FILE_DOWNLOAD_BINARY – Downloads a file in binary format

and i think you should use 'BIN' in the gui_upload .

Read only

Former Member
0 Likes
1,813

hi All,

thanks alot for the information and help provided by all of you.

I did figure out a way where the word document or pdf can be pretty much loaded with gui_upload. the file type used in the method would be "BIN" the following thing has to be done. declare data type as given below and file would be the complete path along with document name which has to be uploaded

DATA: BEGIN OF res_line,

raw(255) TYPE x,

END OF res_line.

DATA: res_tab LIKE res_line OCCURS 0 WITH HEADER LINE.

data : wf_var_stringx TYPE xstring .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file

filetype = 'BIN'

read_by_line = 'X'

  • has_field_separator = ' '

  • header_length = 0

  • header_line = 'X'

IMPORTING

filelength = l_filelength

TABLES

data_tab = res_tab

EXCEPTIONS

OTHERS = 1.

*

LOOP AT res_tab .

CONCATENATE wf_var_stringx res_tab-raw INTO wf_var_stringx IN BYTE MODE.

ENDLOOP.

*

this will upload the file and will file the string x with its content.

hope this helps to some of you.

Thanks

Pooja