05-27-2011 7:34 AM
Hi all,
I have uploaded a document (can be any format) as binary to application server.
Now Iam trying to view the binary data content in a seperate window as a document. I have tried to convert the binary data(which is in the form of a table) to string, text, but the document continues to show in unmeaningful format.
Please suggest how do I handle this?
I have tried searching SDN and other sites, but did not get proper solution. I should only display the document.
05-27-2011 8:00 AM
Now Iam trying to view the binary data content in a seperate window as a document
How are you doing this? Via AL11? Not possible ... AL11 is nothing but a report which just gives a snapshot of the file, it is not the "physical file".
You need to download it to your PC using the usual AS file download trxns viz., CG3Y, CACS_FILE_COPY, if you want to view the actual file.
Further info on the forums.
05-27-2011 8:13 AM
Hi,
I need to achieve this using the code.
I get the application server content in a table, in binary format. I next tried to convert it to string, text, but still the data remains unmeaningful.
05-27-2011 8:36 AM
Hi,
I guess you need to provide more information on the complete scenario,
I have uploaded a document (can be any format) as binary to application server.
Well, while saving this definitely is easy as you are saving it in the binary format.
Now Iam trying to view the binary data content in a seperate window as a document.
The issue is if you want to open the binary as a document, you need to know which format the document it is PDF/DOC/TXT etc.
I have tried to convert the binary data(which is in the form of a table) to string, text, but the document continues to show in unmeaningful format.
Why do you want to convert the binary into a string/text...i mean it is a image file(as you say it can be of any format) that is uploaded, then it is no surprise that you are getting meaningless format.
Now assuming(that is all we can do, unless you are more descriptive) that you are uploading a PDF file onto the app server, and want to display it on a separate window, you can try the below piece of code as a starting point...but if your scenario is any different from the above...then provide more info on what exactly is that you are looking at/for.
DATA v_url TYPE c LENGTH 255.
DATA lcl_html_viewer TYPE REF TO cl_gui_html_viewer.
DATA: li_contents TYPE TABLE OF sdokcntbin.
CALL METHOD cl_gui_cfw=>flush.
CREATE OBJECT lcl_html_viewer
EXPORTING
parent = cl_gui_container=>screen2
lifetime = 0.
lcl_html_viewer->load_data(
EXPORTING type = '/pdf'
IMPORTING assigned_url = v_url
CHANGING data_table = li_contents ). "Pass the Binary content here.
CALL METHOD lcl_html_viewer->show_url "_in_browser
EXPORTING
url = v_url
in_place = ' '
EXCEPTIONS
cntl_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Regards,
Chen
Edited by: Chen K V on May 27, 2011 1:06 PM
Edited by: Chen K V on May 27, 2011 1:06 PM
05-27-2011 8:38 AM
If the document was, for example, a word 97 format document - what would results would you want?
05-27-2011 8:52 AM
Hi,
The uploaded document can be word or PDF or txt. I would want to display it in PDF format.
05-27-2011 9:07 AM
05-27-2011 9:08 AM
Hello,
Check the following code snippet:
DATA: gv_filepath TYPE string,
gv_filedata TYPE xstring,
gv_filesize TYPE i,
gt_bin_data TYPE STANDARD TABLE OF raw255,
gv_pc_filepath TYPE string.
* Open the file in binary mode
OPEN DATASET gv_filepath FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
* Since the file is opened in Binary mode, the entire contents of the
* file is read in one go!
READ DATASET gv_filepath INTO gv_filedata.
IF sy-subrc = 0.
CLOSE DATASET gv_filepath. "Close the file
ELSE.
"Error handling
ENDIF.
ELSE.
"Error Handling
ENDIF.
* Convert the file from hex-string to Binary format
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = gv_filedata
IMPORTING
output_length = gv_filesize
TABLES
binary_tab = gt_bin_data.
* Download the file in "Binary" mode as well
cl_gui_frontend_services=>gui_download(
EXPORTING
bin_filesize = gv_filesize
filename = gv_pc_filepath
filetype = 'BIN'
CHANGING
data_tab = gt_bin_data
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24
).
IF sy-subrc = 0.
* Open the file in a new window
cl_gui_frontend_services=>execute(
EXPORTING
document = gv_pc_filepath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
synchronous_failed = 8
not_supported_by_gui = 9
OTHERS = 10
).
IF sy-subrc <> 0.
"Error handling
ENDIF.
ELSE.
"Error handling
ENDIF.
@Chen:
The issue is if you want to open the binary as a document, you need to know which format the document it is PDF/DOC/TXT etc.
I don't think the fileformat makes any difference when you open the file in binary format!
BR,
Suhas
05-27-2011 9:35 AM
Hi Suhas,
don't think the fileformat makes any difference when you open the file in binary format!
If i send you a binary file and asked you to open it...wouldn't your question be...what is the format of the file?
In your example, i guess you are specifying the format in the file extension, so if you just sent the file path like
c:\temp\binary_doc as input to the below method...what would happen?
cl_gui_frontend_services=>execute(
EXPORTING
document = gv_pc_filepath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
synchronous_failed = 8
not_supported_by_gui = 9
OTHERS = 10
).
Regards,
Chen
05-27-2011 9:43 AM
If i send you a binary file and asked you to open it...wouldn't your question be...what is the format of the file?
Infact i had realised this question was coming But the catch is, we know the source filepath & hence can get the file format!
My solution:The OP will be specifying the AS filepath with OPEN DATASET. We can get the filename(along with the extension) from this path. So we can get the "filetype" in this case it'll be either *.doc, *.pdf & *.txt.
I don't think the fileformat makes any difference when you open the file in binary format
By this i mean no special handling need to be done! You can forget about the file format & just display/download it as you've mentioned
Your comments?
BR,
Suhas
05-27-2011 10:40 AM
@Suhas - You are right, there isn't any special handling needed, except that with gui_download you need to specify where you want to save the file...so i guess it just a matter of what the actual scenario is and how the solution needs implemented.
Regards,
Chen
05-27-2011 11:20 AM
Hi Aiswarya,
a file in binary format must be interpreted by a software that makes the content visible and understandable.
PDF will be interpreted and displayed by ACROBAT or any other PDF viewer.
DOC files may be interpreted and displayed by MS Word or Open Office,
pictures formatted as JPG, BMP or one of the many graphics formats will be interpreted and displayed by MS Paint or any other graphics software.
SAP ABAP is very limited. You can display pictures in a picture control of class cl_gui_picture. Pure ASCII text may be shown as a LIST.
Word, PDF, Excel etc. can not be displayed by SAP/ABAP. The only way is to provide the binary on the client (PC) side and start the software installed locally. There is OLE integration that allows you to run PC software in a GUI control so you may get the imagination as if it comes from SAP Server.
Hope this sheds a little light on this.
Regards,
Clemens
05-27-2011 8:31 AM
Hi,
If you want to open one binary file( except text file ), you need download it into local PC and open it by some program(word, pdf).
1. Use OPEN DATASET to get file content
2. Use GUI_DOWNLOAD to download
3. Use OPEN_FILE to open downloaded file(You need know the application to open that file)
Some sap standard program like 'attachment display' use this way too.