What’s a little variant between friends, anyway?

In all the years I have used SAP_WAPI_WORKITEMS_TO_OBJECT, the use of the ‘Selection Status Variant’ has been the most confusing to me. I’ve used it roughly 20 times, and each time, I seem to forget which values will get what results, so I thought I would try to sort it out for other people here.

This particular WAPI (and I am going to stop typing the whole name now) is the preferred method of locating workflows related to specific objects, replacing the function SWI_WORKITEMS_OF_OBJECT_GET. If you are still using that function – or some <ahem> custom function like it – you would be well-advised to change over to SAP_WAPIs – and not just for this purpose, but there is a whole range of SAP_WAPIs available to you, so get on the bus, OK?

First off, I can use transaction SWI6 to find all the workflows that have worked on an individual object. This is a good start towards testing SAP_WAPI, as I trust SWI6. We can see that there are 12 workflows that have started on this object – in a variety of states.

Diagram 1

Diagram 2

Running SAP_WAPI with no task_filter and merely specifying the object type and key, defaulting in SELECTION_STATUS_VARIANT ‘0001’ yields these results.

In the return structure WORKLIST, we can see 3 entries. It doesn’t take a rocket scientist to determine that these three workflow IDs are the same ones that are listed as ‘in process’ from Diagram 1. So, selection status variant 0001 must mean ‘All workflows that are In Process’. Fair enough.

Kind of like ‘Bring out yer dead’ from Monty Python and the Holy Grail?

Diagram 5 – courtesy of Tumblr

Interesting, Variant 0003 returns 6 results, which corresponds to the other 6 workitem ids, which are *not* completed.

Diagram 6 – Workitem IDs IN PROCESS

Variant 0004 returns all 12 workitem IDs. I went ahead and tried running with additional status variants but 0004 is the most comprehensive and you don’t get any different results just because you threw a ‘9999’ in the status variant. But hey, you can’t blame me for trying.

Diagram 7 – All Workitems

BUT, remove that little ‘X’ in Top_Level_Items, and run with variant ‘0001’ again? You will get a list of all the workitems – for the 3 that were in process – you will get the workitem IDs for all Workflows (also Subworkflows) Event types, and Dialog Tasks.

Again, without Top_Level_Items selected, variant ‘0002’ returns all tasks – dialog, event, and background for the Completed or cancelled workflows.

Try using the Task Filter – I entered the task ID of an approval task used in this particular workflow.

Variant 1 returns 0 items, as no approval tasks were ‘in process’.

Variant 2 returned all the approval tasks that had been completed.

Variant 3 returned any approval tasks that were ‘READY’.

Variant 4 returned all the approval tasks, ready or not.

<MinorRant>

So, as any goodprogrammer will tell you, we always need to be conscious of the runtime even when using our best (ie: SAP Delivered J) functions. Now, I am no ABAP Detective, but I ran a trace on this function, using Variant 4 (gimme all you got) and also using the Task Filter.

The results? Well, they are not surprising at all.

Diagram 8 – SQL and RFC trace using Top-Level Workitems

Diagram 9 – Trace using Task Filter

So I could have been greedy (and lazy) and just run SAP_WAPI_blabbity-blah with the highest variant and no filter, but eventually my bad deeds would catch up to me (they always do). Sooner or later, that difference of 15,000 durtns (what is a durtn? Heck it’s a unit of measure, and in this case, unlike with your bank balance, it’s always good to see it go down) was going to come back to haunt me. Passing in the smallest – most significant – piece of data that I needed to get returned will not only simplify my programming in the caller, but it ensures that the Basis team does not come down on me. Or that the end users don’t wander away from their desks for a coffee break.

</MinorRant>

I hope I have demystified at least one of the SAP_WAPI functions. Once you get used to them, they are quite good. You will find SAP_WAPIs to do everything from raise an event (a much preferred method of starting workflows than simply starting the workflow) to container manipulation to substitution management.

When you DO use one, I hope you will share what it’s for, and expose any little variants which could help others here.

Seriously, though, I’ve found (at many sites) that workflow gets treated as a set-and-forget type of thing; some junior developer gets told to check these transactions and follow a checklist that was handed down from ancient times, and within 6 weeks they’re known as the workflow specialist. These sorts of blogs, by experts like yourself, Jocelyn Dart, and the Bakker boys (Paul Bakker and Rick Bakker), are proving useful for myself and for developers in general, so thanks to all concerned 🙂

Thanks for the feedback. I wondered if putting a trace in the document would garner any attention 🙂 .

While SAP Workflow could stand on it’s own (do some config, set-and-forget) I doubt that is the case in real life. Once the business gets a taste of it, they want more. And I’ve found that the metrics on approvals and task completion need to be captured for a variety of purposes. That is why the ‘workflow specialist’ will often be tasked with complementing the SAP-delivered Workflow reports, and for this reason, the WAPIs are indispensable. And so is the proper usage of them!

Thanks for the blog. I’ve used SAP_WAPI_WORKITEMS_TO_OBJECTS a number of times within methods – once it was to see if the current approver had already approved this workflow at a lower approval level and hence no need to do it again – and I ran into the same problem as well. I can’t remember all these options so I just use 0000 and filter the results myself. Basis can go jump!

I don’t know how people find the time to write these intricate blogs! Every time I think of a subject someone else uses it. One day…

As for time – I happen to know you spend plenty of time doing your own thing – which is much harder IMHO than writing a blog. So, next time you have a couple of ‘days off’ from your moderating, write a blog!