This blog is designed to help you understand and configure correlations in SAP Business Workflow. It does not describe the set-up of correlations in XI.
Correlations have been present in SAP Business Workflow since release 6.40 (NW04) and are intended to allow your workflow to wait for an event from a specific object for which it does not know the key. The example to be worked through was set up using the SAP on Linux Test-Drive (with the Windows SAPGUI hosted by a Virtual Machine) so there are only a few business objects to play with! The bare-bones scenario is:
1.A workflow is started for a person (PD-org type “External person”, ID 50000025).
2.This workflow is to be completed by a receiving wait step when a previously started absence request is approved.
The only link between the absence request and the External person is that this person ID was saved in the absence request form (Fig. 1). The object key for the approval event is of course the absence form number, in this example Number 5. Remember, the approval event contains no event parameters for the person number field, it exists only in the absence table. Thus the absence form must be correlated to the person number at run-time for our example workflow to detect an event from the correct absence object.
The traditional way of doing this set-up would be by recourse to coding. A new personnel event, from a delegation of an existing object (if one existed), would be triggered in the receiver function module of the original absence approval form event linkage in transaction SWE2. With correlations, no coding is now required, although interestingly, a special event receiver function module SWL_CORL_CORRELATE_BY_EVENT is inserted automatically into the event linkage table (Fig. 2).
To set up this scenario, the first step is to set up the workflow container definitions. I’ve set as a mandatory import element Person based on the generic object PDOTYPES. I’ve used this rather than the personnel number field SWXFORMABS-PERNR simply to help identify different elements in the bindings, and it is slightly more realistic to start the workflow with an object. Within the template, the containers Absence based on FORMABSENC and CorrelationObject based on CL_SWF_MOD_ CORRELATION are created. CorrelationObject contains the run-time correlation data between FORMABSENC and PDOTYPES.OBJID. Let’s start with defining the correlation with transaction SWF_CRL1. The online help is here.
The correlation consists of a component FORMABSENC that must be an object with an event, and the correlated element (which can’t be an object) from the FORMABSENC attributes, although you define it how you like so long as the binding is allowed. Double-clicking the component FORMABSENC, something that could be a bit clearer, activates the assignments frame (Fig. 3).
You can test the correlation using the object key of the component FORMABSENC, to make sure the settings have “stuck” – always a good check with workflow configurations! Your workflow key correlated to the absence business object is shown in XML format (Fig. 4).
Now to the workflow definition proper.
In the SAP library, it lists activating a correlation in a process control step straight after defining it with SWF_CLR1. However, I found that the entry fields are from drop-downs, and these are not populated until you define a version-dependant event in the workflow header (Fig. 5).
1.Click on the status button for a new event and enter a name, here “Absence”.
2.The wait type should be “Wait for Event By Using Correlation”.
3.Enter the event to be waited for, here FORMABSENC-APPROVED
4.Make the receiver type “Wait Step Event”
Now enter a step in the workflow for a process control (Fig. 6).
5.In the control tab function field, enter “Activate Correlation”
6.Select the name of event defined in step 1 above from the drop-down.
7.Enter the correlation name, here ZMY_FIRST_CORRELATION.
8.I’ve only got this to work only by using binding: Choose the binding from PERSON.OBJID from the import container, to PERSONNELNO in the correlation definition.
9.To complete the process definition, enter the correlation object container for the correlation instance.
We now need to define a wait step.
10. Define binding for event from &_EVT_OBJECT& to workflow container &ABSENCE& (Fig. 7)
11. Define binding for event from workflow import element &PERSON.OBJID& to correlation element &PersonnelNo&. (Fig. 8)
12. Activate the workflow. The information message number WD060 “The container element “CorrelationObject” is written, but not read or exported” is normal (Fig. 9).
That’s it. We can test the correlation.
13. Using transaction SWUS, I’ve started the workflow and entered the previously created object “External Person” (with transaction PP01), number 500000025 (Fig. 10)
14. The workflow log indicates that step 314 is now waiting for an event for an object that contains the personnel number 500000025 (Fig 11).
15. Let’s oblige by creating an APPROVED event from the previously saved absence form number 5 (Fig. 12).
16. Success! The wait event has recognized the absence form number 5 as correlated to the personnel number 500000025 (Fig. 13).
17. A quick look at the event logs (transaction SWEL) to see what has gone on in the background (Fig.14).