Leveraging SCP Neo Workflow from the SCP ABAP Environment
I recently worked on a project which gave me the opportunity to learn a little about Workflow on SAP Cloud Platform Neo as well as jump head first into SAP Cloud Platform, ABAP Environment(aka Steampunk). My task on the project was to integrate an application running on Steampunk with Workflow running on SCP Neo. Firstly, I have to say it just felt right working with ABAP again. ? Very welcomed change to be honest. Next, I found some very good resources on workflow which did help me through the process. I found the tutorials on the developer center very helpful in getting me started with setting up Workflow on Neo. Christian’s zombie blog was definitely helpful as it shows an on-prem version of how to do this ABAP integration. As most of you know, the Steampunk environment is a restricted version of an on-prem ABAP system, where you are only allowed to use white-listed objects. Also, the documentation for the Workflow API for Neo is quite good and super helpful. In this blog, I’d like to share my learning experience with the community and show how to leverage workflow from an ABAP class in Steampunk.
Before we take a look at the ABAP code, lets see what I’ve done with the workflow definition itself. After doing the initial workflow setup on my SCP trial account, I created a workflow project in the SAP Web IDE Full Stack IDE called ApproveProductWFProj. This workflow is very simple in that it basically has one user task called “Approve Product”. Take note that I am setting the Business Key in the definition to a context value. This is so that I can query the instances by this Business Key value later on.
I’ve defined a form which is used as the test user interface, where the end user has the ability to “Approve” or “Reject” the product. It shows just a couple fields such as Product ID, Description, and Approver User ID.
After the user task approval is done(either by the end user or programmatically), the workflow will trigger a script task called “Set Status”. I wanted to be able to capture the user’s decision from the “Approve Product” user task, so here I’m capturing that decision and filling the corresponding variable in the instance context. In doing so, I will always be able to extract this decision via the API from ABAP.
Finally, I have a very simple email task as well, where an email is sent to the recipient notifying them of the status, “Approved” or “Rejected”. Assumption is that you have correctly configured the Workflow Mail Service on your SCP account already.
So now I have all of the components I need for my workflow and I have successfully deployed them to SCP Neo. Now I need to be able to create instances of my workflow as well as interact with those instances from Steampunk. Lets take a look at the ABAP code.
Firstly, when first starting my coding, I quickly realized that I was not going to be able to use existing examples that I’ve had laying around over the years. The interfaces that I’m used to using such as IF_HTTP_CLIENT are not white-listed in Steampunk. Luckily, I’ve found some new white-listed classes/interfaces that I can use for HTTP connectivity. Problem solved. ? Be advised as of the time of this writing, these new HTTP connectivity APIs are only supported in the Steampunk environment. So what I’ve done here is basically wrapped many of the SCP Neo Workflow API endpoints with ABAP methods, in an attempt to remove the complexity of handling the request/response from the rest of my application. I did not create wrappers for all endpoints of the API, only what I needed for my application really. So this is in no way a complete API implementation. Also, this API class assumes you have all of the required authorizations to perform these actions on the workflow definitions/instances. The required authorizations are documented in the API documentation for the Workflow API for Neo.
All of these wrapper methods then leverage one common private method called EXECUTE_WORKFLOW_REQUEST which is the method that does all of the work. Notice the use of the new HTTP connectivity APIs CL_HTTP_DESTINATION_PROVIDER and CL_WEB_HTTP_CLIENT_MANAGER.
We can now use this workflow API class in our application. For this, I have created class ZCL_SCP_WORKFLOW_TEST to show how to call the API methods. In a productive application, you would probably not have all of these API calls stacked inside of one execution, but for our purposes here, I just wanted to show how to call all of these APIs in one single execution. So don’t read into the fact that we are deleting all instances, creating new instances, and updating/completing those instances all at the same time.
First we need to create an instance of the API class, passing the workflow runtime URL, SCP user and password.
This next section of code shows how to call the API to get the workflow definition, the definition model, and the workflow instances of the workflow definition by the status, for example, get all RUNNING instances.
The next section shows how to delete instances of the workflow definition by the status, RUNNING, COMPLETED, or ERRONEOUS.
This next section shows how to create workflow instances of the workflow definition and set its context. Its important to pass a valid SCP user id as the “approverUserId” and a valid email address to the “recipientEmail”, otherwise the Workflow will not work correctly.
Finally, this last section of code shows how to interact with the workflow instances. First there is a call to the API to get the instance details by business key, from there we can get the workflow instance context and read its values. We can also then update the workflow instance context. Finally, we can get the details of the workflow task instances, and update them as well.
You may also notice the use of the PARSE_JSON method in the previous code. This method parses the json response returned by the Workflow API calls. This method is meant to be very generic in nature to be used across the different API calls. Due to the fact that my usual JSON parsing and RTTS classes are not currently white-listed, this method ended up being kind of messy, hence the reason I’m not showing that code here. I very much plan to rewrite that mess as soon as humanly possible, the way I wanted to from the start. 🙂 But for now, it works and does what it is suppose to. Moving on….
Now if we run this test class, and view our workflow instances in the Workflow Monitor we should see 3 instances(you may have to change the filter on this screen to show COMPLETED status). Of course, the workflow has been completed since we had programmatically set that status. We can also see that the context was updated. The context value “approvalStatus” is now set to “approved”.
If we look at the execution log of the workflow instance, we see that all of the steps have been captured in the log.
That just about wraps up this project. I have to say it was a lot of fun working on ABAP again, and of course the challenge of learning something new( the Workflow piece ) is always fun. On to the next one! Hopefully I’ll be back in a couple months with some more cool stuff. Until then…
great blog. Finally, there is an example of how to use one of the SAP CP APIs in ABAP. IMHO this is something missing from the API hub. Especially, how to work with the XSRF token was really difficult to figure out for me. And this part is not shown in the code snippets on the API hub.
Yes, I stumbled a little on the XSRF token as well, but got a better understanding of it after talking with my pal DJ Adams. Thanks DJ! 🙂
One more question. Do you know in which NetWeaver version the http_client you used is delivered? I checked 7.51 SP2. There the version you used is not available.
As mentioned in the blog, these classes/interfaces are currently only available in steampunk.
Thanks for the great blog sir! On a side note you tested the class methods to see it all fits it in or does steampunk has something like test cockpit to test its different kind of developments?
I'm currently trying to create an example like this calling directly from 7.4 and 7.52 systems, but am finding the HTTP calls quite erratic in their behavior. It takes 4-7 calls with 403 Errors to produce a successful one. Performing the same using CPI work fine every single time.
Have you got any pointers where I am going wrong? I'm using the ABAP code snippets from the APIhub.
I'm really not sure Michael. 403 would tell me there is an authorization problem. Be sure that your SCP user has the correct workflow authorizations assigned. I did not find this erratic behavior when using the new HTTP APIs in Steampunk.
Thanks, Rich. I actually changed my processing to use oAuth and the HTTPS calls went through fine 100% of the time. We now know that something's not quite right with basic auth and will probably log this in a ticket.
Great blog, thank you for the insights and git repo :). I can see the http client class you used in our steampunk system, but it's not available in S/4. Will it be delivered with 1909 to on-prem?
I am wondering about authentication. We are planning to consume SCP services (both NEO and CF) from ABAP, but do not want to on-board all users for technical services (e.g. machine learning API). Is it possible to create some kind of "technical user" for this in SCP?
Have you looked at the OAuth Client Credentials flow? I think, it is the "technical user" concept that you are looking for.
In my understanding, it is available independent of whether you have an IDP for user authentication.
I can't say for machine learning APIs, but CP Workflow APIs do support the OAuth client credentials flow.
Is it possible to please answer or create a blog with your expert inputs on how the CDS+BOPF things will be applied in the new ABAP CP. The previous ODATA things had more flexibility to play around.
I have created a SCP workflow on neo trial account, now i want to call this workflow from ABAP system using Workflow AP. I have used Basic Authentication, below call method returns, sy-subrc as 1,
font-family: "Courier New";
CALL METHOD lo_http_client->receive
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 5.
I checked SMICM transaction where i'm getting the " ERROR => SSL handshake with bpmworkflowruntimewfs-p1941179555trial.hanatrial.ondemand.com:443 failed: SSSLERR_PEER_CE"
Can anybody help me, what certificate i need to install and from where can i get the same
With 2005 release, SCP ABAP environment support native integration with Cloud Foundry workflow. Please check this link for more details - https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b7931f7b42d5433987b9d3f30e2445fd.html