Posted on Mar. 03, 2009 06:11 AM, Kuala Lumpur, Malaysia
Have you heard about persistent and runtime references? What do they mean? Why do SAP requires both persistent and runtime reference? How do they affect the way we program the workflow? If you have these questions in your mind then you should continue reading this blog.
What is persistent and runtime object references?
In workflow runtime, BOR objects are represented by SWC_OBJECT variables. However, in order to save object references in the database and transport them beyond session limits, persistent object reference variables of the ABAP type SWOTOBJID are used.
Why do SAP requires both persistent and runtime reference?
The workflow system stores object references in the container. These object references must be saved in the database whenever there is a context change (switch from one step to the next). This mechanism ensures the workflow can be restarted in case of server down or system crash using transaction SWPC.
For this purpose, the workflow system converts the object references in the container from the runtime representation (blue areas) to the persistent representation (green areas) and back again, as required.
How do they affect the way we program the workflow?
One example is when you want to start the workflow directly from the function module, not through event. Since the workflow can only be started with the persistent object reference, then we need to convert the containers passed to the workflow into persistent object references, using macro SWC_CONTAINER_TO_PERSISTENT<CONTAINER>.
1. When calling the workflow from API
*create and populate runtime object reference
SWC_CREATE_OBJECT OBJECT 'Z00MARA' OBJKEY.
SWC_SET_ELEMENT WI_CONTAINER 'MaterialMaster' OBJECT.
*Convert references in container from runtime handle to persistent object reference
SWC_CONTAINER_TO_PERSISTENT WI_CONTAINER.
*start the workflow via the function API
CALLFUNCTION 'SWW_WI_START_SIMPLE'
EXPORTING
* CREATOR = ' '
* PRIORITY = NO_PRIO
TASK = TASK
* CALLED_IN_BACKGROUND = ' '
* DEADLINE_DATA = ' '
IMPORTING
WI_ID = WI_ID
* wi_header =
* RETURN =
* WI_RESULT =
TABLES
AGENTS = AGENTS " notneeded here
* DEADLINE_AGENTS =
* DESIRED_END_AGENTS =
* LATEST_START_AGENTS =
* EXCLUDED_AGENTS =
* NOTIFICATION_AGENTS =
* SECONDARY_METHODS =
WI_CONTAINER = WI_CONTAINER
EXCEPTIONS
ID_NOT_CREATED = 1
READ_FAILED = 2
IMMEDIATE_START_NOT_POSSIBLE = 3
EXECUTION_FAILED = 4
INVALID_STATUS = 5
OTHERS = 6.
Other example is when you want to use alternative binding, or programmed binding. Since the container is stored persistently when the workflow manager calls the programmed binding, then it's necessary to convert the container values to runtime first using SWC_CONTAINER_TO_RUNTIME <CONTAINER> after which we need to reconvert them back to persistent object references using SWC_CONTAINER_TO_PERSISTENT<CONTAINER> as discussed in the first example.
2. When using programmed binding
function z00_bind_wf_to_display_step.
*"----------------------------------------------------------------------
*"*"Localinterface:
*" IMPORTING
*" VALUE(DATAFLOW) LIKE SWABINDEF-DATAFLOW
*" TABLES
*" CALLED_CONTAINER STRUCTURE SWCONT
*" CALLING_CONTAINER STRUCTURE SWCONT
*"----------------------------------------------------------------------
data: mat_object type SWC_object.
data: mat_view like t132t-statm.
if dataflow eq 'E'.
" only consider export dataflow from wf to wi container
" read data from workflow (= calling) container
SWC_CONTAINER_TO_RUNTIME CALLING_CONTAINER.
SWC_CONTAINER_TO_RUNTIME CALLED_CONTAINER.
SWC_GET_ELEMENT_CALLING_CONTAINER 'MaterialMaster' mat_object.
SWC_GET_ELEMENT_CALLING_CONTAINER 'MaterialView' mat_view.
" write data to work item (= called) container
SWC_SET_ELEMENT_CALLED_CONTAINER wi_leading_object mat_object.
SWC_SET_ELEMENT_CALLED_CONTAINER 'MaterialView' mat_view.
SWC_CONTAINER_TO_PERSISTENT CALLING_CONTAINER.
SWC_CONTAINER_TO_PERSISTENT CALLED_CONTAINER.
endif.
endfunction.
Conclusion
1. Event manager/program always uses runtime object reference.
2. Workflow manager/program always works with persistent object reference.
3. Work item or BOR manager/program always works with runtime object reference.
4. Use macro SWC_CONTAINER_TO_PERSISTENT<CONTAINER> to convert runtime into persistent object reference
5. Use macro SWC_CONTAINER_TO_RUNTIME <CONTAINER> to convert persistent into runtime object reference
Ruslim Chang Senior Process Integrator
Add to: del.icio.us | Digg | Reddit
Hope the understanding of persistent and runtime objects helps you to program your workflow better.Comment on this weblog
Life is beautiful! Let's make it meaningful and colorful!