Skip to Content
Technical Articles

Programmatically create and retrieve documents attached in GOS (Generic Object Services) via Stored business document.

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.



B. To create attachment:

Following are the function modules required to be executed for attaching the document.

  1. Use FM ARCHIVOBJECT_CREATE_FILE to generate document id.

A different ARCHIV_DOC_ID is generated every time FM is executed.


  1. Use FM ARCHIV_CONNECTION_INSERT to attach the document.




C. To fetch attachment:

Following are the function modules required to be executed to get the binary value of the attachment.

  1. 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).





  1. 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!!! 🙂

You must be Logged on to comment or reply to a post.
  • 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.


  • 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?

    • 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.

  • 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,


    • Hello Naveen,


      Glad to hear you found the document useful.

      I'm not getting your point. Can you please explain me why you need other function module?