-------------------------------------------------------------------------------------------------------------------------------
Post Summary: This is a use case of Loop Until in work flow. We are trying to update a record in a step inside the work flow. Before the record update if the record is already locked by some other program then the process should loop until it gets the lock and updates the data base.
Step1. in Tx- SE24 create a class.
Implement the interface IF_WORKFLOW.
CREATE TWO ATTRIBUTES.
Create one event with exporting parameter.
Below methods are interface methods.
Create a constructor with importing parameter and implement it with the shown code.
Implement other methods and activate them.
Create a new method TRIGGER_WF which would start the work flow by triggering the event and pass the carrid value to the work flow.
Define another method which will get the flight carrid value and update the data base.
Below LOCK modules are created.
Implement the method with lock.
Step2. Now go to Tx- SWDD and create a work flow.
Provide description.
Step3. Create necessary container elements as per shown.
Go to the work flow header to maintain the start event and do the parameter binding and activate it.
Step4.
Activate the binding. Save and Back.
Step5. Now create a activity step for data base update. Double click on the step and choose activity.
below screen appears.
Create a task.
below screen appears.
provide the class and method name. Select background processing and Save.
Select as Synchronous object method.
Save and go back.
Choose continue.
Click on binding.
The binding should be like below.
Continue.
Step6. We have created an activity step which will update the data base when it gets a lock. now if the lock is not granted then this step should be in a loop until the it gets the lock and updates the data base.
Double click and select Loop Until.
Below screen appears. provide a step name and double click to create a condition.
Choose flag from the container element.
Select operator as =.
In the constant give value as X and press Enter key.
Give the loop out come name and Enter. Then press the Continue button.
Now the loop is created and we have to put the activity step inside the loop.
Step7. This we have to do by cut and paste. Right click on the activity and cut the block.
Put the cursor and right click and from the option choose paste block.
Now the activity step is within the loop.
Step8. This is the SCARR table entries.
Create a small program and trigger the start workflow event by passing a carrid value.
Go to tx- SWI1 and execute.
Select the workflow and click on the icon.
Click on the contents to see the container elements.
The container element are set properly and now choose Graph button.
So here is the work flow process graph. The loop is not executed as the activity step gets the lock and updates the data base very first time.
Data base updated successfully.
Step9. Create some other program which currently puts a lock on the carrid = AA .
We can see the lock entry in SM12 transaction.
Now run the program for carrid = AA
Check the status in SWI1 transaction.
Select the work flow and click on log button.
Here we can see the same activity step is executed multiple times with an interval of 30 seconds to get the lock. but as the lock grant is failed it is looping.
Here is the loop graph.
Now remove the lock from the table or for text remove from SM12.
Now the loop runs again and finds the lock and updated the data base and loop is terminated and work flow is complete.
So here DB updated.
-------------------------------------------------------------------------------------------------------------------------------
Post Summary: This is a use case of Loop Until in work flow. We are trying to update a record in a step inside the work flow. Before the record update if the record is already locked by some other program then the process should loop until it gets the lock and updates the data base.
Step1. in Tx- SE24 create a class.
Implement the interface IF_WORKFLOW.
CREATE TWO ATTRIBUTES.
Create one event with exporting parameter.
Below methods are interface methods.
Create a constructor with importing parameter and implement it with the shown code.
Implement other methods and activate them.
Create a new method TRIGGER_WF which would start the work flow by triggering the event and pass the carrid value to the work flow.
Below LOCK modules are created.
Implement the method with lock.
Step2. Now go to Tx- SWDD and create a work flow.
Provide description.
Step3. Create necessary container elements as per shown.
Go to the work flow header to maintain the start event and do the parameter binding and activate it.
Step4.
Activate the binding. Save and Back.
Step5. Now create a activity step for data base update. Double click on the step and choose activity.
below screen appears.
Create a task.
below screen appears.
provide the class and method name. Select background processing and Save.
Select as Synchronous object method.
Save and go back.
Choose continue.
Click on binding.
The binding should be like below.
Continue.
Step6. We have created an activity step which will update the data base when it gets a lock. now if the lock is not granted then this step should be in a loop until the it gets the lock and updates the data base.
Double click and select Loop Until.
Below screen appears. provide a step name and double click to create a condition.
Choose flag from the container element.
Select operator as =.
In the constant give value as X and press Enter key.
Give the loop out come name and Enter. Then press the Continue button.
Now the loop is created and we have to put the activity step inside the loop.
Step7. This we have to do by cut and paste. Right click on the activity and cut the block.
Put the cursor and right click and from the option choose paste block.
Now the activity step is within the loop.
Step8. This is the SCARR table entries.
Create a small program and trigger the start workflow event by passing a carrid value.
Go to tx- SWI1 and execute.
Select the workflow and click on the icon.
Click on the contents to see the container elements.
The container element are set properly and now choose Graph button.
So here is the work flow process graph. The loop is not executed as the activity step gets the lock and updates the data base very first time.
Data base updated successfully.
Step9. Create some other program which currently puts a lock on the carrid = AA .
We can see the lock entry in SM12 transaction.
Now run the program for carrid = AA
Check the status in SWI1 transaction.
Select the work flow and click on log button.
Here we can see the same activity step is executed multiple times with an interval of 30 seconds to get the lock. but as the lock grant is failed it is looping.
Here is the loop graph.
Now remove the lock from the table or for text remove from SM12.
Now the loop runs again and finds the lock and updated the data base and loop is terminated and work flow is complete.
So here DB updated.
-------------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment