Skip to main content
ABAP

Create a Media Upload OData Service with Custom Header Parameters

Mark Smith Mark Smith, Senior Developer 3 min read

Thanks for tuning in and checking out my very first blog for Mindset, Create a Media Upload OData Service with Custom Header Parameters. Now, I’ve written a few blogs over the years. However, this is the first blog I’ve written for Mindset and I’m really looking forward to adding to the SAP knowledge-base and hopefully making a developer’s life a little bit easier.

Before spilling the beans on how I utilized the Create Stream method passing multiple custom parameters, I want to set the stage and explain the business use case for this particular development.

As you may know, Mindset is a development firm focusing on human-centered design. We were working with a client, bringing them out of the stone age GUI experience and building them a gorgeous web application.

My particular assignment was to find a way for the web application to upload documents into the SAP Document Management Service (DMS) and assign document classifications and characteristics via custom parameters. However, there isn’t much information on how to implement this using an OData service. Also, I found that the most common recommendation is to use a code-based implementation via SEGW and redefine the CREATE_STREAM method.

I want to add context around Classifications and Characteristics and how custom header parameters relate to them. When documents are loaded into the DMS, you can access these documents through transaction CV04N (there are multiple CV0*N Transactions you can use). Within this transaction, you will see that there are multiple tabs with additional fields that can be associated with the document that’s been uploaded. However, in my case, I needed to be able to add classification characteristics as well as link the document to a partner. Further, by utilizing the custom parameters in my payload, I was able to send those values through the parameters, utilize the FM that you’ll see in the code, and commit the records to the database.

HTTP POST to Upload_DocSet with custom header parameters and a 201 Created response

CV04N document view with class type 017 assigned and characteristic values listed, values redacted

Document display on the Object Links tab with the document linked to a customer, details redacted

Below are the following steps I followed in order to implement the above solution.

Steps

  1. Create SEGW Project
  2. Create Entity Type
    1. Check the “Media” box for Entity
  3. Generate Runtime Artifacts
  4. Model Provider Class Extension – Redefine the DEFINE method with the code snippet.
  5. Data Provider Class Extension- Redefine the CREATE_STREAM method with the code snippet.

Code Snippets

DEFINE Method in MPC Extension Class

ABAP DEFINE method in the MPC extension setting DocName as the content type of the Upload_Doc entity

CREATE_STREAM

Start of the CREATE_STREAM method with a header comment and DATA declarations for the DMS document BAPIs

CREATE_STREAM declarations for short texts, object links, class allocation, characteristics and a raw line type

DATA declarations for the binary table and request header variables for doctype, class and char1 to char5

ABAP reading custom request headers such as doctype, class and char1 to char5value from the request context

ABAP calling SPLIT_FILENAME, filling the document data and calling BAPI_DOCUMENT_CREATE2

ABAP converting the media stream to binary, building the file entry and calling CVAPI_DOC_CHECKIN

ABAP linking the document to a KNA1 customer, assigning the class and filling characteristic values

ABAP filling the remaining characteristics and calling BAPI_DOCUMENT_CHANGE2 with classes and object links

End of CREATE_STREAM with BAPI_TRANSACTION_COMMIT and copy_data_to_ref returning the entity

If you’re a developer new to the CREATE_STREAM and DEFINE methods and how they are implemented. I hope this blog gave you a good starting point and empowered you to create your own solution. Please feel free to reach out to me via LinkedIn or on the Git repository if you have any questions and I’ll try my best to get back to you. If you’re one of the old dogs and there is a better way to do this. Please, by all means, drop a comment in the Git repository and let me know how you would enhance this solution. But, most importantly, stay inspired, keep learning, and share the knowledge. Mark out.

Links:

https://github.com/marksmith-II/create_stream_upload_service

https://www.linkedin.com/in/mark-smith-6873644a/

If you are interested in viewing similar articles, visit our blog, here.

View our LinkedIn, here.

Share