转 To instantiate any Business object in a Workflow

To instantiate any Business object in a Workflow

By Swetabh Shukla, Infosys from Link

1. Go to SWDD and create a new workflow. This workflow will have two steps. This is just for test purpose so we are not going to define any triggering event etc.  First step will instantiate (creating a runtime object) a business object and second step will use that runtime object to execute one of its method. We know that to instantiate any BO we need the object key to be passed. Key uniquely identifies a runtime instance of Business Object (henceforth we will refer it as BO or business object interchangeably). 
Note: BO = ‘Business Object’ in all the references below. 

For example use BO BUS1001006. This BO is for Standard Material. Let us consider a material number ‘ZSHUKSWE20’ in this case. The method DISPLAY of BO can be used to display the material passed in key field of the BO BUS1001006. We will try to instantiate the BO for object key = ZSHUKSWE20 which is material number in current scenario. 

We will use Business Object SYSTEM and method GENERICINSTANTIATE to instantiate any Business Object in workflow.


The workflow template will look like this.
 

2. Define a container element of Business Object type which you want to instantiate in a workflow.

We will define a container element of type business object BUS1001006.

 

3. Now Create an Activity type step and use Business Object SYSTEM and method GENERICINSTANTIATE.  This task will be background task since we don’t want any interaction with users.

 
Create the task from workflow builder directly.

 

In binding of the task with method pass variables objectkey and objecttype. These will be created automatically in Task container. The method will return runtime object in export parameter ‘OBJECTINSTANCE’.


Save the task and go back to workflow builder.

 

Now create binding between TASK and workflow. Now here you can pass hard coded values for OBJECTKEY = Material Number and OBJECTTYPE = BUS1001006
 

Save it and finally we have added a step which instantiates a business object. Let’s use this instance to display the material ZSHUKSWE20. This step will return runtime object of type ‘BUS1001006’ and key = ZSHUKSWE20.

4. Create a new activity type step and create a new task for this.

This task will just call method ‘DISPLAY’ of BO instantiated. The method takes some parameters as input but for our current scenario even if we don’t pass import parameter (non-mandatory) it will not be a problem. We are just checking runtime existence of Business Object. So we don’t have to worry about the binding between method and task. But in real scenario do create proper bindings to avoid any error. 

Also do not forget to make the task General task so that any one can execute. Also assign ‘Workflow Initiator’ as agent so that you can test in workflow builder. In real scenarios take care of agent assignment.



Now after we have created the task. Go back and then create binding between task and workflow. We just need to pass our Container element “MATERIAL’ to the task so that the task executes the method DISPLAY with the key ‘ZSHUKSWE20’ and displays the material.

Save the step and activate the workflow.

If we execute the workflow we can check the BO getting instantiated and material getting displayed. 

Directly execute the workflow and check. Go to Business workplace and check. You can see the work item

 

Execute the work item and then check


So we can see the material ZSHUKSWE20 getting displayed which proves that the BO BUS1001006 was instantiated in workflow.  

This way we have seen how to instantiate a Business Object in our workflows. The same we can replicate elsewhere and can utilize already existing Business Objects in our workflows.

猜你喜欢

转载自sapabap.iteye.com/blog/1881951