Wednesday, July 15, 2015

Instantiating an object in SAP Workflow

The other day I was struggling with determining emailaddresses in SAP Workflow.

In my case, I was looking for the email address of a user assigned to a businesspartner, assigned to the lead I was working on.

In BUS2000108, there is an attribute 'EMPLOYEERESPONSIBLEUSER'.

The attribute is of type USR01, which is nice, but does not contain the attribute 'Emailaddress'...

Whilst looking around, I noticed another business object, named 'BUS4101', that could also eat usernames. The BUS4101 apparently does contain my emailaddress.

Great news... But how to get from a username to the attached emailaddres when the definition of the attribute is of the wrong type?

Browsing over the internet, I found that there is a method GENERICINSTANTIATE in object SYSTEM.

Note the description of object type SYSTEM.

Even though I consider myself a workflow wizard, I don't reckon that's what they mean, so I created a subtype ZSYSTEM, and redefined the GENERICINSTANTIATE and implemented the exact same code as the standard.

Next I created a standard task, called CRE_USER, that feeds the method the objectname 'BUS4101' and objectkey from the container, and returns the &OBJECTINSTANCE to my container 'BUS4101'.

This now enables me to create an activity in my workflow where in the binding, I give a username to the method, and it returns me the user as a BUS4101.

I can now use the emailaddress attribute to send emails to.
Note that this method can be used to instantiate any object you like, as long as you have the key at hand in your workflow.