cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Workflow exception handling

MikeB
Contributor
0 Likes
4,277

Hi Workflow Community,

In my workflow project I have a task to implement an exception handling for the case when there is no any agent for User Decision step. In order to do that, I can implement a method in my BOR that will check for agent and if there is no such, then an exception will be thrown. After that I can catch it in a Local Workflow via Local Events of workflow's Version-Dependent settings. The problem is that I have to add this check / handle to every user decision step and there are a lot of such steps.

My question is there any better way to deal with exceptions, where you don't need to pass over all workflows steps and manually add the call of the method, which will raise an exception in case of lack of suitable agent?

Thanks.

View Entire Topic
pokrakam
Active Contributor
0 Likes

G'Day Mike,

I've done similar things before, and a good approach is to build yourself a generic agent determination step, pull the agents into the WF and validate whether agents exist. This could even done using a common subWF which is also used to maintain agents (if you want to go the extra mile, you can even do some funky stuff like decide whether it's an HR or business function and route accordingly).

The exact approach depends on your setup. For example if you have lots of rules, your custom method will have importing parameters for a rule name (AC90000324) and generic container elements as parameters. Or you can have importing elements matching all your rules that will be calling the method (here it makes sense to use the same element names for all rules - not Plant in one and Plnt in another and WERKS in the next one) and only bind those which are relevant.

There are many ways to approach this, hope this gives you some ideas.

Regards,

Mike

MikeB
Contributor
0 Likes

Hi Mike,

Thanks for the directions, as far as I understand, there is no some workflow / system built-in approach to throw exception (e.g. NO_AGENTS_ASSUMED) each time when there is no available agent. And the only way to do so is manual development?

Regarding to «generic agent determination step», should I implement it as separate Condition step, where a successful result will continue the process execution and the fail will throw an exception? Or just add a desired method to the existed User Decision step and there throw an exception, which will be catched by Local Workflow?

Thanks.

pokrakam
Active Contributor
0 Likes

Hi Mike,

The closest thing is the 'Terminate if rule has no result' checkbox for a rule. If it's not checked, the step has no agents, if checked, it goes into error.

No what I mean is a separate container operation or workflow step where you call a custom method (e.g. ZCL_WF_RULE->EVALUATE if you use rules) to do your agent determination.

The result populates a multiline container element 'AGENTS' in your workflow. The next step can be a condition where you check if the agents table is empty, if not proceed to your 'real' step (decision, whatever) where you use the AGENTS element as your agent. If it is empty, you can raise an event or get as creative as you like (e.g. my last post). If you have a perfectly good workflow engine, why not use it to maintain your agents...

Regards,

Mike

Former Member
0 Likes

Hi Mike,

In the method where you are determining the agents fill a flag for agents found and keep it blank for no agents found and export that flag in to the workflow template with agents container. Add a condition step to check variable is NE expression and raise exception in that case. As you said you have multiple user decision steps then are those using the same agents container or agents container keeps on changing for every user decision step. If they use the same container have this flag checked right below the agent determination method and if you are using multiple containers for agents with different values then you have to add the exception blocks in all those instances where decisions steps are used.

Regards,

Sandip

pokrakam
Active Contributor
0 Likes

No, flag not needed. Just check if agents exist.

Former Member
0 Likes

Hello Mike,

How will work flow engine know that there are no agents selected either multiline work flow container has to be checked in the work flow template or like i said a flag can be set to read it in the template and decide what to do.

Please Correct me if I am wrong.

Regards,

Sandip

pokrakam
Active Contributor
0 Likes

Hello Sandip,

As I said above - "check if the agents table is empty". You then propose the use of an agents container AND a flag. Why do we need an additional flag? Unnecessary container elements occupy space in the DB and add complexity.

Just check the agents container directly. If it contains agents we have agents, if it's empty we don't. Therefore I say flag not needed.

Regards,

Mike

MikeB
Contributor
0 Likes

One more technical question.

I defined the method AgentAssignChecker() inside of BOR, this method gets the agent name from agent container of workflow via binding, checks its value and if it is blank, we want to throw an exception. For this reason I defined the message 9010 in a message class (SE91), now I throw it with code: EXIT_RETURN 9010 space space space space.

The question is how and where should I catch this exception in the workflow?

In Version-Dependent events settings or in User Decision events settings?

Thanks.

pokrakam
Active Contributor
0 Likes

Hi Mike,

Why use a method? Workflow steps are expensive, just check it in a condition. The operator CE or EX should work. Two branches, one means you have something in there, the other means it's empty.

Or else your agent determination step can raise the exception. If you enable the exception in the WF builder (step outcomes), it adds another branch. In there you can add a raise event step.

Regards,

Mike

Former Member
0 Likes

Check out the link http://wiki.scn.sap.com/wiki/display/ABAP/Exception+handling+in+Workflows,

So in you case define the exceptions in the version dependent tab settings.

Add a condition step right after your agent determination step in workflow template.

Check if no agents found add a process control block to raise exception.

Please let me know if you need more details.

MikeB
Contributor
0 Likes

Hi Mike,

Thank you for the suggestion to use Condition + Process Control in order to implement my task, it looks right. But there is one moment that can be problematic in this approach — maintainability.

Suppose, in my workflow there are a lot of places, where I have to add an agent assignment verification (the process is dynamic, where the agent detection logic depends on outcomes of previous steps). Let say, I implement your suggestion and add conditions to relevant places. One day, there is a need to change the agent verification logic, in case of condition-based approach I'll have to pass over all conditions and do it manually, while in case of BOR-method I change it only one time in specific place and the change will begin to work immediately.

Is it significant enough aspect to bear it in mind?

Thanks.

MikeB
Contributor
0 Likes

As far as I know Condition let you check the specific value of container attribute with the following operators: EX, NX, CE, NE, AND, OR, NOT and in order to check if the attribute IS NOT INITIAL and contains the data, I have to use Container Operation step, where to calculate the length of the attribute's value, store the result in container variable and only then check its value in Condition step.

Is there any more smart way to check if container attribute (both, single and multi-line) contains the data?

Thanks.

pokrakam
Active Contributor
0 Likes

Hi Mike,

Not sure if you understood correctly. If you have a single generic method of determining agents then maintainability is no issue. Thus:

1. Determine agents

2. Is table populated?

3a. If no, engage whatever process

3b. If yes, proceed to dialog step

The condition just checks if you have agents. CE = Contains elements = Table has entries. Or use NE ' '. Test and see what works in your setup.

If step 1 above is a dedicated WF task then you don't even need a condition, but can just create two outcomes by defining and raising an exception.

Regards,

Mike

MikeB
Contributor
0 Likes

I actually got it as:

1. Define additional Condition step

2. In condition field set the following expression: «&agents_cont& CE 1»

3. If it's True, then continue, otherwise throw an exception.

As I understand, operator CE (Table Contains Rows) should return True if the multiline container contains rows (e.g. in step #2, described above, there should be one row in order to get True), otherwise False. But in my case operator CE always returns False, no matter if there are rows in the container or not.

What I'm doing wrong?

Former Member
0 Likes

Hello Mike,

How are you using the expression «&agents_cont& CE 1» in the condition step?

You should always use the F4 help or double click on the conditions space that pops up the screen with all the workflow containers and then choose the required container that you are using to fill the
agents or the container that contains the agents name at runtime.

Try «&agents_cont& CE 1» NX

which means no expression in container element to check if this is initial.

Let me know if you need more details.

Regards,

Sandip

MikeB
Contributor
0 Likes

Hi Sandip,

Here is the way I build the condition expression:
1. Double click on Condition step in workflow template.

2. Double click on condition text area.

3. The following window will be opened:

4. Here I choose desired container.

5. For the operator column pick CE.

6. In the column «Express. 2» I set 1, for the test case.

7. Press on green «V».

That's all, after that you'll exactly the same expression I posted above.

I suppose, that operator CE have to check if the container table has a rows and if I set the number after this operator, the expression will check if the container has exactly number of rows.

Now, I don't really understand where should I type this NX? In which column?
As you mentioned above, the expression «&agents_cont& CE 1 NX» will mean: «no expression in container element to check if this is initial», as I understand it, the container will not be checked if it is initial. Could you, please, elaborate in what circumstance it will return the True and when False?

In bottom line, my condition expression has to return True if the container if full and otherwise False.

Thanks.

pokrakam
Active Contributor
0 Likes

Hi Mike,

If the condition is your first step, where does &agents_cont& get it's values from?

Actually I was wrong about CE. Contains Element ==> search table for the value you specify. So as you have no agent named '1', it will always be false.

Also, if the condition is your first step, where does &agents_cont& get it's values from?

You could try EX (exists) and NX (not exists). SAP has a funny way of distinguishing between empty (exists in container with a blank value) versus nonexistent (hasn't been bound or assigned, therefore not in container), so some experimentation is necessary. Also try combinations of = '', =' ', >'', >' '. One of these is bound to work!

Regards,

Mike

Former Member
0 Likes

Hi Mike,

«&agents_cont& NX should be used.

This will check if there are any elements inside or not.

You do not have to give  «&agents_cont& CE 1 NX».

So  «&agents_cont& CE 1 NX» becomes  «&agents_cont& NX»

Wich means there are no agents inside.

So your outcomes at the bottom should have True & False.

If above expression is true it means you do not have any agents so do exception handling and if

if it is false it has agents follow decision step.

Regards,

Sandip

MikeB
Contributor
0 Likes

That's working!

The expression &agents_cont& NX returns TRUE if the container is empty, otherwise FALSE. In other words, NX is equal to is empty check.