on 2021 Feb 11 8:25 AM
Hello everyone,
I'm now facing a problem which is well discussed here and in other forums. In spite of reading lots of tutorials, blogs and other questions here I was not able to solve it. I'm trying to upload a document (pdf, jpg, xlsx, docx) and attach it as GOS document to a business object. I'm doing this in FIORI app context so the uploaded file will imported to me as an xstring. So all I have to do is put this xstring into GOS document. I followed the guidelines here and tried it like this.
* Get folder id
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
region = 'B'
IMPORTING
folder_id = ls_fol_id
EXCEPTIONS
communication_failure = 1
owner_not_exist = 2
system_failure = 3
x_error = 4
OTHERS = 5.
* To get the extension from the file name
IF iv_slug IS NOT INITIAL.
SPLIT iv_slug AT '/' INTO lv_qmnum lv_file.
CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'
EXPORTING
filename = lv_file
uppercase = 'X'
IMPORTING
extension = lv_extensions.
ENDIF.
* Transfer Importing Xstring to binary solix table
lt_solix = cl_bcs_convert=>xstring_to_solix( iv_xstring = is_media_resource-value ).
* Fill Doc Data
* ls_doc_data-doc_size = XSTRLEN( is_media_resource-value ).
ls_doc_data-obj_descr = 'TEST'.
ls_doc_data-obj_name = lv_file.
MOVE lv_extensions TO ld_doc_type.
ls_object-objkey = lv_qmnum.
ls_object-objtype = 'BUS2038'.
* Create Document
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
EXPORTING
folder_id = ls_fol_id
document_data = ls_doc_data
document_type = ld_doc_type
IMPORTING
document_info = ls_doc_info
TABLES
contents_hex = lt_solix
EXCEPTIONS
folder_not_exist = 1
document_type_not_exist = 2
operation_no_authorization = 3
parameter_error = 4
x_error = 5
enqueue_error = 6
OTHERS = 7.
* To link the document attachment and business object
IF sy-subrc = 0 AND ls_object-objkey IS NOT INITIAL.
ls_object-instid = lv_qmnum.
ls_object-typeid = 'BUS2038'.
ls_object-catid = 'BO'.
ls_objtgt-instid = ls_doc_info-doc_id.
ls_objtgt-typeid = 'MESSAGE'.
ls_objtgt-catid = 'BO'.
TRY.
cl_binary_relation=>create_link(
EXPORTING
is_object_a = ls_object
is_object_b = ls_objtgt
ip_reltype = 'ATTA' ).
COMMIT WORK AND WAIT.
CATCH cx_obl_parameter_error cx_obl_model_error cx_obl_internal_error.
ENDTRY.
ENDIF.
Can anyone tell me what I did wrong? File gets transfered and uploaded correctly to business object, but when trying to open it, it only works for pdf files. All the other document types get opened with error that data is corrupt or document type gets not supported. Document type can not be the problem because I uploaded the files manually and can open them, so it must have to do with the creation here.
I tried several things, using the 'SO_OBJECT_INSERT' function instead, using the 'SCMS_XSTRING_TO_BINARY' function for convert instead, working with '&SO_FILENAME=' etc., working with document size. Nothing helped. Evertytime I got the same error when opening the uploaded document.
In some blogs it says that it has to do with SAP ECC 6 and unicode system that many user have problems, I have that too and dont know how to solve it. Maybe any ideas here?
Thanks a lot
Regards Michael
Request clarification before answering.
Hi Missschaaa,
Add the OBJECT_HEADER parameter in Function Module , it will work
* Add the OBJECT_HEADER parameter in Function Module , it will work
t_objhead = VALUE #(
( line = |&SO_FILENAME={ lv_file_name }| )
( line = |&SO_DESCRIPTION={ lv_obj_descr }| )
( line = |&SO_FORMAT=BIN| ) "Important
( line = |&SO_FILEEXT=png| ) "png
( line = |&SO_OBJLEN={ lv_doc_size }| )
).
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
EXPORTING
folder_id = ls_fol_id
document_data = ls_doc_data
document_type = 'PNG'
* document_type = 'jpg'
IMPORTING
document_info = ls_doc_info
TABLES
contents_hex = lt_solix
OBJECT_HEADER = lt_objhead
EXCEPTIONS
folder_not_exist = 1
document_type_not_exist = 2
operation_no_authorization = 3
parameter_error = 4
x_error = 5
enqueue_error = 6
OTHERS = 7.
IF sy-subrc <> 0 OR ls_doc_info-doc_id IS INITIAL.
MESSAGE 'Failed to insert attachment' TYPE 'E'.
RETURN.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.