Akshay Yerawar
Posted onApril 22, 2018 2 minute read
Programmatically create and retrieve documents attached in GOS (Generic Object Services) via Stored business document.
FollowRSS feedLike
22 Likes 21,371 Views 9 Comments
Few days back I came across a requirement, to programmatically create and retrieve documents attached in GOS (Generic Object Services) via Stored business object. It took significant amount of time for me to do this. Thought sharing the solution might help someone who may come across this requirement.
I have tried to cover the scenario which I have solved with this. Any suggestions/improvements/modifications in this document are appreciated.
Business object, Object ID, Document type are the prerequisite for this process. To get these details, refer T-code OAC3.
A. Existing attachments to the material.
Following are the function modules required to be executed for attaching the document.
Use FM ARCHIVOBJECT_CREATE_FILE to generate document id.
A different ARCHIV_DOC_ID is generated every time FM is executed.
Use FM ARCHIV_CONNECTION_INSERT to attach the document.
Following are the function modules required to be executed to get the binary value of the attachment.
Use FM ARCHIVOBJECT_GET_URI to get Archive document id i.e. ARC_DOC_ID.
This FM gives document id of the attachment which is required to be passed in next function module. Pass your Business object in OBJECTTYPE (e.g. BUS1001006 for Material Master, BUS2012 for Purchase Order) & object in OBJECT (e.g. Material code, Purchase order number).
Use FM ARCHIVOBJECT_GET_TABLE to get binary value.
This function module takes ARC_DOC_ID as an input & gives the binary value of the attached document.
Pass Content repository to the ARCHIVE_ID, Document type to DOCUMENT_TYPE & get ARCHIV_DOC_ID from FM ARCHIVOBJECT_GET_URI.
This will give the binary value for the attachment.
If you want to download the file in ECC, you can call method cl_gui_frontend_services=>gui_download. With this method file can be downloaded in given path.
If you want to use this in Ui5 application, you can use FM “SCMS_BINARY_TO_XSTRING“, which will convert binary value to XSTRING value. Ui5 developer can consume this Xstring value through Odata service.
Happy Learning!!!
Alert Moderator
Assigned tags
PLM Document Management System (DMS)
generic object services attachment
Generic Object Services FM
Generic Object Services programtically
Generic Object Services via stored business objects
View more...
Related Blog Posts
DMS HR – Enhancing GOS List option and Changing the Title of the attached document created using Store Business Document (SBD) in GOS
By S M Firoz Ashraf, Dec 30, 2012
Content Repository Migration in mind ?
By Sagar Shridhar Bhide, Dec 09, 2019
Avoid storage of Attachments in SAP Office tables (SOOD, SOFM, SOC3, SOFFCONT1) & Store it on OpenText Archive Server
By Kolusu Suresh Kumar, Dec 17, 2015
Related Questions
SOFFPHIO and GOS attachment
By Former Member, Nov 16, 2010
Storing Document in content server through Create Attachment(GOS)
By Former Member, Apr 17, 2013
ArchiveLink
By Former Member, May 16, 2011
9 Comments
You must be Logged on to comment or reply to a post.
Pratik Doshi
April 23, 2018 at 11:52 am
Excellent document akshay. Keep it up.
Like(1)
Akshay Yerawar Post author
April 23, 2018 at 11:54 am
Thank you Pratik. Appreciate that.
Like(0)
Michelle Crapo
April 23, 2018 at 12:14 pm
Interesting. We don't have any sort of document management . We save documents to a drive on the database server. OAC3 is not set up. This might be an interesting future project for me. As to load onto the database server a custom program is used anyway. Then another customer program to pull back the data for display. This seems like a better way.
Michelle
Like(1)
Akshay Yerawar Post author
May 27, 2020 at 10:27 am
Thanks Michelle. I'm happy that you found it useful.
Like(0)
Sayantani Sensharma
July 15, 2020 at 9:48 pm
I was searching for a way to achieve this for two days and couldn’t find anything. Thankfully I stumbled upon your blog! This has been a life saver! Thank you ?
I have an additional requirement to enable deletion of the attached files as well. Can you tell me the FM name for it?
Like(1)
Akshay Yerawar Post author
October 24, 2020 at 9:58 am
Hi Sayantani,
Glad to hear this blog helped you.
For deletion functionality you may use FM "ARCHIVOBJECT_DELETE".
Like(0)
Shruti Shah
September 17, 2020 at 6:50 pm
Where will you enter download document logic if I want to download document when the user clicks on the attachments option.
Like(0)
Akshay Yerawar Post author
October 24, 2020 at 10:04 am
Hi Shruti,
It depends in which application you are implementing the logic.
If you are implementing this logic in Module pool, you have write logic in PAI.
If you are implementing this logic in Webdynpro application, you have to write logic on that Action.
If you are implementing this logic in UI5 application, you have to write logic in respective entity set of the oData service.
Like(0)
Naveen Kumar
December 17, 2020 at 8:23 am
Hi, Than you for posting this blog and is very helpful
I have a similar requirement, using the Business Object BUS2038, we were posting attachments to non sap server
While posting attachments in the FM : ARCHIVOBJECT_CREATE_FILE, if we give the path name from the local system, this FM capture the path and saves the attachment to other server
We were using Sap Odata and Fiori as a front end, in Java Script sending the file path from the local system is obsolete and it's not a Good Idea.
Could you please let me know, if there is any other Function Module which will imports File Content and generates the Document Id for the Business Object
Thanks & Regards,
Naveen.
Like(0)
How to add a GOS Attachment to a Business objects
Wilco Menge
TECHNOLOGIE
ABAP
ABAP OO
ATTACHMENT
GEEK
GENERIC OBJECT SERVICES
GOS
Both SAP ECC and CRM offer the opportunity to add so called GOS attachments to any object in SAP. These attachments are usually added to Quotations, Sales orders or Business partners (for example, a photograph of the Business Partner).
In this blog I will show how to manage these attachment in an ABAP Object Oriented way.
But first, let start one level higher: GOS stands for Generic Object Services and offers some generic functionality to any business object. Amongst others, these services are*:
Creating personal notes on an object
Starting a workflow
Adding and removing attachments to an object
The GOS framework is flexible and even allows you to use your own custom business object. See this link for more information on how to achieve this.
Show me the code
Today we will focus on managing attachments in ABAP. The example code uses Sales Orders, but it is easy to adapt the example to other types of objects (even your own object types). The code is split into two parts:
An API class encapsulating the detailed calls to the CL_CRM_DOCUMENTS** class
Some example code calling the API class
DATA: lo_attachment TYPE REF TO zcl_attachment,lt_attachments TYPE TABLE OF REF TO zcl_attachment,
lv_xml TYPE string.
CALL METHOD zcl_gos_attachment=>get_attachments_for_bo(EXPORTING
object_key = ‘0017A45189CA1EE183DA3CA3941D4600’
object_type = ‘BUS2000131’ “ Sales Order Line
category_id = ‘BO’
RECEIVING
attachments = lt_attachments ).CHECK lt_attachments IS NOT INITIAL.
READ TABLE lt_attachments INTO lo_attachment INDEX 1.lv_xml = lo_attachment->get_ascii_content( ).This example reads an XML document that has been stored on a Sales Order Line. The result is a table of attachments instances that can be accessed.
DATA: lo_attachment TYPE REF TO zcl_attachment,lt_attachments TYPE TABLE OF REF TO zcl_attachment,
lv_binary_string TYPE xstring.
“ Fill with binary data
lv_binary_string = ‘’.CALL METHOD zcl_gos_attachment=>upload_binary_fileEXPORTING
object_key = ‘0017A45189CA1EE183DA3CA3941D4600’
object_type = ‘BUS2000131’
category_id = ‘BO’
binary_string = lv_binary_stringfilename = ‘Example document.pdf’
RECEIVING
attachment = lo_attachment.This example stores some binary data as an attachment to a Sales Order Line.
As you can see, calling the API class is straightforward as it encapsulates most of the boiler plate code needed to call CL_CRM_DOCUMENTS. As an example, one method of the example class is shown here, the rest of the code is available in a zip file attached to this article.
METHOD get_ascii_content.FIELD-SYMBOLS: <line> TYPE sdokcntasc.
DATA:lv_logical_key TYPE skwf_io,
lt_content TYPE sdokcntascs,
ls_error TYPE skwf_error,
lv_dummy_message TYPE string.
• Construct logical key
lv_logical_key-objtype = me->key-objtypelo.
lv_logical_key-class = me->key-classlo.
lv_logical_key-objid = me->key-objidlo.• Get text lines
CALL METHOD cl_crm_documents=>get_with_tableEXPORTING
loio = lv_logical_keyIMPORTING
error = ls_error
file_content_ascii = lt_content.IF ls_error IS NOT INITIAL.MESSAGE ID ls_error-id TYPE ls_error-type NUMBER ls_error-no
WITH ls_error-v1 ls_error-v2 ls_error-v3 ls_error-v4
INTO lv_dummy_message.
RAISE EXCEPTION TYPE zcx_gos_attachment_exception.
ENDIF.• Convert the separate text lines to a single string
LOOP AT lt_content ASSIGNING <line>.CONCATENATE content <line> INTO content SEPARATED BY cl_abap_char_utilities=>cr_lf.
ENDLOOP.ENDMETHOD.This method reads the text contents of a GOS attachment.
Full API class
You can download the full ABAP code here.
...