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!
You are using this to get the file extension, for example lv_extensions will be 'DOCX' for 'TEST.DOCX':
CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'
EXPORTING
filename = lv_file
uppercase = 'X'
IMPORTING
extension = lv_extensions.And then this: (I'm snipping just the important stuff)
MOVE lv_extensions TO ld_doc_type.
...
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
EXPORTING
folder_id = ls_fol_id
document_data = ls_doc_data
document_type = ld_doc_type
...But ld_doc_type is not the same as the file extension. First, it's only three characters, so 'DOCX' will not fit (It will be 'DOC'). But other than that, that's some customizing... I can't say exactly where to set up, but the domain says it's in table TSOTD.
That's what looks wrong to me, but I've not really been using the GOS. You may be getting the document_type_not_exist exception, as you're not checking sy-subrc after the CALL FUNCTION...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes you are right, SAP does not offer any four character extensions. Maybe thats part of the problem but would not explain why JPG does not work at all. In some tutorials there are explanations with format 'EXT' but that did not help because with it it was always displayed as external document to open in my case.
No I do not get any exception, I ask rc after inserting function as you can see in the coding below. Its always rc = 0.
Hm no its not in this table, but Im not sure if it has to be there. There are only some SAP like looking doc types in there. Does it look different in your system?
ALI X X ABAPList-Dokument
ARC X Archivobjekt (Image)
BCS X Externe Dokumentablage
BIN X Binäres Dokument
DLI X Verteilerliste
EXT X X PC-Dokument
FOL X Mappe
GRA X X SAP-Graphik
OBJ X Business Objekt
OFO X Object folder
OTF X OTF-Dokument
R3I X IDoc
RAW X X SAP-Editor-Dokument
SCR X SAPscript-Dokument
URL Link ins Inter-/Intranet
WIM X Workitem
XXL X X Dokument für Listviewer
| 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.