Skip to Content

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. 

You may be using SAP_WAPI_WORKITEMS_TO_OBJECT to find any other workflows that have been instantiated for an object/key pair, or <gasp> for some sort of reporting (contrary to Paul Bakker’s excellent advice)

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.

Diagram 3


Using Selection Status Variant ‘0002’ returns 6 results in WORKLIST:

OK, so Variant 0002 must mean – maybe, give me the completed workitems?

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.

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. Jocelyn Dart

    Hi Sue,

    Yeah I know they always used to confuse me… and then I started using transaction SWI14 more often and realised this is what they stand for:

    0001 Active Instances – ready, selected, started, committed

    0002 Finished Instances – completed, canceled, errror, waiting

    0003 All Active Instances – same as 0001 adding waiting

    0000 All Instances (all active and finished) – i.e. no filter

    Not sure where 0004 came from?  Probably just treated the same as 0000 as it’s not one of the usually recognized filters.

    I suspect durtn may stand for duration?

    Good blog anyway… you are not the only one who rants about these things… but of course as an (mostly ex-) programmer I just go and pull the code apart.

    Cheers,

    Jocelyn

    (0) 
    1. Susan Keohan Post author

      Hi Jocelyn,

      Of course durtn is duration – I mock these reports sometimes 🙂

      I should retry with 0000 .vs. 0004.  But given that I posted this once as a blog (and then lost it) I think I will just let it stand.

      You can’t really take the programmer out of a person, I think.

      Cheers,
      Sue

      (0) 
  2. Paul Bakker

    Sue,

    Thank you for sharing that information – I’ve never used that WAPI so far but no doubt I will.

    I’m in awe of the amount of work you put into these blogs.

    beers & cheers

    Paul

    (0) 
    1. Susan Keohan Post author

      Why, thank you Paul!   For myself, I am eagerly awaiting the next installment from Down Under.  Who will it be?  You or Jocelyn?  Or perhaps Rick Bakker?  (Except he is so busy with the Discussion space 😉 .

      Anyhow, the clock is ticking…

      Cheers!
      Sue

      (0) 
      1. Susan Keohan Post author

        Oh, by the way, that particular WAPI is often useful if you need to see:

        1) If any workflow has been kicked off for that object

        2) If that/those workflows are completed, or

        3) as a precursor to SAP_WAPI_READ_CONTAINER if you are forced to evaluate the results of a task from outside of workflow.

        Have fun!

        (0) 
  3. Martin English

    MUHWAHWAHWAHWAH !!!!

    Another weapon for BASIS to bludgeon the developers with !!!!

    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 🙂

    hth

    (0) 
    1. Susan Keohan Post author

      Hi Martin,

      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!

      Sue

      (0) 
      1. Former Member

        Hi Sue,

        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…

        cheers

        Rick Bakker

        (0) 
        1. Susan Keohan Post author

          Hi Rick, and thanks for the kind words.

          Although ‘Basis can go jump!’ – sounds like fighting words to me 🙂

          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!

          Best,

          Sue

          (0) 

Leave a Reply