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: 

Pdf file is corrupted in GOS attachment

jitendra_it
Active Contributor
0 Kudos

Hello All,

I am reading pdf file from application server and attaching it to a document in FB03.

I see that file is successfully attached. However, when i download it, reading is giving error of corrupt file.

Below is code snippet. Could you please let me know where is the issue ?

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }

OPEN DATASET p_file FOR INPUT IN BINARY MODE.
IF sy-subrc EQ 0. "Attachment file
READ DATASET p_file INTO l_filestring.
CLOSE DATASET p_file.

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; }

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_filestring
IMPORTING
OUTPUT_LENGTH = l_doc_size
tables
binary_tab = lt_doc.

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }

TRY.
swc_create_object l_message 'MESSAGE' l_message_key.
swc_set_element l_message_container 'DOCUMENTTITLE' 'TestGOS'.
swc_set_element l_message_container 'DOCUMENTLANGU' sy-langu.
swc_set_element l_message_container 'NO_DIALOG' 'X'.
swc_set_element l_message_container 'DOCUMENTNAME' 'MESSAGE'.
swc_set_element l_message_container 'DOCUMENTTYPE' 'PDF'.
CATCH cx_root INTO l_cx_root.
ENDTRY.

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; }

TRY.
swc_set_table l_message_container 'Content_Hex' lt_doc1[].
swc_set_element l_message_container 'DOCUMENTSIZE' l_doc_size.
swc_refresh_object l_message.
swc_call_method l_message 'CREATE' l_message_container.
swc_get_object_key l_message l_message_key.

CATCH cx_root INTO l_cx_root.
ENDTRY.

After this called FM BINARY_RELATION_CREATE to create link.

1 ACCEPTED SOLUTION

jitendra_it
Active Contributor
0 Kudos

Thanks all for your responses.

Not sure why but I removed line with attribute "DOCUMENTSIZE" and it worked.



2 REPLIES 2

jozsef_hegyi
Active Participant
0 Kudos

Hello

please check the file size before and after the upload, is it the same?

Best regards

Jozsef H

jitendra_it
Active Contributor
0 Kudos

Thanks all for your responses.

Not sure why but I removed line with attribute "DOCUMENTSIZE" and it worked.