Implementing reusable Attachment data model using ArchiveLink
‘Attachments’ service is a re-usable UI component in S/4HANA application. Applications can make use of this component to deal with attachment related functionality. Uploading, downloading, renaming, and deleting an attachment from or to the parent application are some of the basic features supported by Attachment Services.
Attachments are stored in Open Text (content server) using ArchiveLink integration.
In this blog, I would like to share my experience of implementing and consuming attachment services from backend for a custom business object built on top of S/4 HANA. I used tools and technologies provided in S/4 HANA to minimize the development effort.
*Please note that scope of this blog is only limited to consumption of attachment services from backend. You may require an additional UI knowledge to develop full-fledged attachment UI application*
The architecture is designed in a way that same attachment object is re-used and consumed by different applications across the entire solution.
Basic Knowledge of BOPF
Basic knowledge of OData
- Designing BOPF
- To have re-usable attachment object so that it can be consumed across different applications, dependent business object ‘ATTACHMENT’ is created using BOBX transaction. This dependent object can be tied to any parent business object for example Sales order, Purchase order, Deal, etc.
- To have version history of an attachment, child node ‘ATTACHMENTVERSION’ is created for dependent BO
- Dependent BO created in step 1 can be plugged with different parent objects with respect to each application wherever attachment functionality is required. These parent business objects may be sales order, Purchase order, etc. In this blog custom business object ‘Deal’ is used as parent object.
- Designing Odata
- Data Dictionary tool (SE11) is used to prepare a new database structure for the entity type to be created for uploading files
- Execute Gateway Services Builder (SEGW) and new entity types are created that refers the dictionary structure created in step 1 and flag the media checkbox
- Save and generate
- Data model definition is updated using MPC_EXT generated class. Standard method called DEFINE is redefined as below to declare mime type property as content type for the new entity. In this provided example, the property is called “Mime type”
- To achieve upload functionality, CREATE_STREAM method of the data provider class is implemented. In this method, attachment is kept in locally defined temporary staging table. At this moment attachment is uploaded in open text and unique archive document id gets generated. Slug parameter is used to pass filename along with file type. Standard importing parameter ‘IS_MEDIA_RESOURCE’ is used to get file size and mime type. To upload file in open text, available standard FM ‘ARCHIV_CREATE_TABLE’ is re-used. Pre-requisite customization is required in place to achieve this functionality. (Please refer to configuration steps mentioned at the end).
- On pressing global save of the application, document id generated in open text, will move from staging table to attachment BOPF tables.
- To view and download attachments, method GET_STREAM of the data provider class is implemented. Standard FM ‘ARCHIV_GET_CONNECTIONS’ is reused to get the file connections and archive document id. These are then passed to FM ‘ARCHIVOBJECT_GET_TABLE’ to get document size and content.
I would further like to share specific requirement of my project where I need to show all versions of an attachment i.e. version history. To achieve this, S/4 HANA capabilities are leveraged to minimize the development effort. ‘AttachmentVersion’ entity created above is consumed with SADL (Service Adaptation Description Language). SADL enables fast read access to data for scenarios on mobile and desktop applications based on SAP HANA using query push-down.
CDS is created for an Attachment and its association is exposed with AttachmentVersion and then OData Model is implemented through SADL by mapping the relevant element from the SADL model (CDS) to the OData properties.
Thus, on pressing show version from UI, pop-up is received displaying the version history of that attachment. User can download any version by pressing an arrow button.
SAP Customizing Implementation Guide->SAP NetWeaver->Application Server->Basis Services->Archive Link->Basic Customizing->Define Content Repositories->Edit Document Classes->Edit Document Types->Edit Links
Content Repository: Content repositories are logical units within your storage system. There can be more than one content repository, for example, for dividing the information content either thematically or physically.
Document Class: It is the technical format of a document type. SAP has pre-delivered document classes e.g. PDF, XLSX, JPEG, DOCX etc. which can be directly used and configured with Document type as explained in next steps
Document Type: It groups several documents together and is important from customizing point of view as it influences the storage of document based on link table configuration. A document type should be assigned to a document class
Edit Links: The prerequisite to maintain links is having a content repository, document type and a BOR object already defined. There are SAP standard link tables TOA01, TOA02, TOA03 and TOAHR which can be used to define relationship in this configuration. Link tables define in relationship are actual database tables These database tables contain details of stored document which will be queried during find/search operations.
- In case you need to define your own link tables, you may define using following path Archive Link->Customizing Enhancements->Register Link Tables.
- The pre-requisite here is to have an existing Database table with the same name.
- Business Object Repository: A BOR object must be created if application cannot be mapped to already existing BOR objects. In transaction SWO1, enter the name of the BOR object to be created and save the object.
Hope this blog will help you in consuming and implementing attachment services in your applications.