You are on page 1of 246

BC610 Workflow Development

BC610

R/3 System
Release 46B
27.09.2000

0
BC610 Workflow Development

BC610

Workflow Development
ã SAP AG 1999

n R/3: BC610 Workflow Development


n Rel.: 4.6 A
n Date: March 2000
n Mat. No.: 5003 4983

(C) SAP AG BC610 0-1


Copyright

Copyright 2000 SAP AG. All rights reserved.


Neither this training manual nor any part thereof may
be copied or reproduced in any form or by any means,
or translated into another language, without the prior
consent of SAP AG. The information contained in this
document is subject to change and supplement without prior
notice.

All rights reserved.

ã SAP AG 1999

n Trademarks:
n Microsoft ®, Windows ®, NT ®, PowerPoint ®, WinWord ®, Excel ®, Project ®, SQL-Server ®,
Multimedia Viewer ®, Video for Windows ®, Internet Explorer ®, NetShow ®, and HTML Help ®
are registered trademarks of Microsoft Corporation.
n Lotus ScreenCam ® is a registered trademark of Lotus Development Corporation.
n Vivo ® and VivoActive ® are registered trademarks of RealNetworks, Inc.
n ARIS Toolset ® is a registered Trademark of IDS Prof. Scheer GmbH, Saarbrücken
n Adobe ® and Acrobat ® are registered trademarks of Adobe Systems Inc.
n TouchSend Index ® is a registered trademark of TouchSend Corporation.
n Visio ® is a registered trademark of Visio Corporation.
n IBM ®, OS/2 ®, DB2/6000 ® and AIX ® are a registered trademark of IBM Corporation.
n Indeo ® is a registered trademark of Intel Corporation.
n Netscape Navigator ®, and Netscape Communicator ® are registered trademarks of Netscape
Communications, Inc.
n OSF/Motif ® is a registered trademark of Open Software Foundation.
n ORACLE ® is a registered trademark of ORACLE Corporation, California, USA.
n INFORMIX ®-OnLine for SAP is a registered trademark of Informix Software Incorporated.
n UNIX ® and X/Open ® are registered trademarks of SCO Santa Cruz Operation.
n ADABAS ® is a registered trademark of Software AG
n The following are trademarks or registered trademarks of SAP AG; ABAP™, InterSAP, RIVA, R/2,
R/3, R/3 Retail, SAP (Word), SAPaccess, SAPfile, SAPfind, SAPmail, SAPoffice, SAPscript,
SAPtime, SAPtronic, SAP-EDI, SAP EarlyWatch, SAP ArchiveLink, SAP Business Workflow, and
(C) SAP AG BC610 0-2
ALE/WEB. The SAP logo and all other SAP products, services, logos, or brand names included
herein are also trademarks or registered trademarks of SAP AG.
n Other products, services, logos, or brand names included herein are trademarks or registered
trademarks of their respective owners.

(C) SAP AG BC610 0-3


Business Integration Technologies I

Level 2 Level 3
BC600 2 days BC601 5 days BC610 3 days
SAP Business SAP Business Workflow
Workflow - SAP Business
Workflow - Introduction Workflow - Programming
Build and Use

BC615 3 days
SAP ArchiveLink

Archiving

BC660 3 days BC670 2 days


Data Archiving ADK - Retrieval
Programming

BC095 3 days BC440 5 days


Business Integration Developing R/3 Web Connection
Technology Internet Applications

ã SAP AG 1999

(C) SAP AG BC610 0-4


Prerequisites (BC610):

l Essential:
BC400 - Introduction to the ABAP Workbench
BC430 - ABAP Dictionary
BC600 - SAP Business Workflow - Introduction
BC601 - SAP Business Workflow - Build and Use
Good or very good knowledge of ABAP

l Recommended:
Basic knowledge of object-oriented programming
Basic knowledge of transaction concepts

ã SAP AG 1999

(C) SAP AG BC610 0-5


Target Audience (BC610)

l Workflow developers and consultants with good or


very good knowledge of ABAP

ã SAP AG 1999

(C) SAP AG BC610 0-6


Course Overview

l Course Goals
l Course Objective(s)
l Course Content
l Course Overview Diagram

ã SAP AG 1999

(C) SAP AG BC610 1-1


Course Goals

At the conclusion of this course, you will be able to:


l Perform workflow programming at all levels
l Manage and monitor the workflow runtime system

ã SAP AG 1999

(C) SAP AG BC610 1-2


Course Objectives (1)

At the conclusion of this course, you will be able to:


l Identify all points in the workflow system at which
programming is possible or necessary
l Create your own object types and extend existing
ones
l Create role function modules

l Program events
l Create check and receiver type function modules

ã SAP AG 1999

(C) SAP AG BC610 1-3


Course Objectives (2)

At the conclusion of this course, you will be able to:


l Create work items via API
l Administrate the workflow runtime system

l Create your own workflow analyses

ã SAP AG 1999

(C) SAP AG BC610 1-4


Course Content

Preface

Unit 1 Course Overview Unit 6 Event Definition and


Implementation
Unit 2 Introduction
Unit 7 Workflow Runtime
Unit 3 Object Definition and System
Implementation
Unit 8 Workflow Information
Unit 4 Activities System
Unit 5 Roles

Exercises
Solutions
Appendix

ã SAP AG 1999

(C) SAP AG BC610 1-5


Course Overview Diagram

Person Position/job Org. unit


Organization
Role Task

Processes WF definition Step

Attributes Events Methods


Business
objects
Object

ã SAP AG 1999

(C) SAP AG BC610 1-6


Main Business Scenario

ã SAP AG 1999

n Full text in appendix.

(C) SAP AG BC610 1-7


Introduction

Contents:
l Tasks of a workflow system
l SAP Business Workflow Architecture
l Programming in SAP Business Workflow

ã SAP AG 1999

(C) SAP AG BC610 2-1


Introduction: Unit Objectives

At the conclusion of this unit, you will be able to:

l Explain the SAP Business Workflow architecture


l Recognize the components of SAP Business
Workflow that enable or require programming by the
user

ã SAP AG 1999

(C) SAP AG BC610 2-2


What Is Workflow Management?

l A system that delivers work


n In the correct sequence
n With all the necessary information
n At the correct time
n To the people responsible

ã SAP AG 1999

n Linking work steps automatically


n Application-independent control of connected activities across transactions

(C) SAP AG BC610 2-3


Tasks of a Workflow Management System

l Process definition
"What happens in what order?"
Workflow builder, task definition
l Organization modeling
"Who does what?"
Organization model, role definition
l Application encapsulation
"Which objects are required?"
Business Object Builder, Business Object Repository

ã SAP AG 1999

n Process definition - "Work is delivered in the correct sequence ..."


n Organization modeling - "Work is delivered to the people responsible ..."
n Application encapsulation - "Work is delivered with all the necessary information ..."

(C) SAP AG BC610 2-4


Tasks of a Workflow Management System

l End user support


"What have I got to do today?"
Business Workplace
l Process control
"What happens when?"
Workflow manager, work item manager
l Process evaluation
"Who did what and when?"
Reporting and analysis

ã SAP AG 1999

n End user support - "Work is delivered to the people responsible at the correct time ..."
n Process control - "Work is delivered in the correct sequence at the correct time ..."

(C) SAP AG BC610 2-5


SAP Business Workflow: Definition Architecture

Person Position/job Org. unit


Organization
Role Task

Processes WF definition Step

Attributes Events Methods


Business
objects
Object

ã SAP AG 1999

n Explanation A –> B = A uses B


n Example:
Step definition uses attributes (container operation), events (wait steps), methods (secondary
methods).
Task uses workflow definition (in multistep tasks) or methods (in single-step tasks).

(C) SAP AG BC610 2-6


SAP Business Workflow: Programming

Person Position/job Org. unit


Organization
Role Task

Processes WF definition Step

Attributes Events Methods


Business
objects
Object

ã SAP AG 1999

n Other areas in which programming is possible:


Ÿ Administration
Ÿ Reporting
Ÿ Creation of work items

(C) SAP AG BC610 2-7


What Does Workflow Not Do?

l Simplify application transactions:


Complex application functions remain complex
application functions
l Provide efficient business processes automatically:
Business aspects must be catered for by modelers

ã SAP AG 1999

n Existing interfaces or menu structures cannot be affected through using workflow.


n As soon as the application is called via the workflow, only the application has control over which
actions can be performed.

(C) SAP AG BC610 2-8


Introduction: Unit Summary

l Explain the SAP Business Workflow architecture

l Name the components of SAP Business Workflow


that enable or require programming by the user

ã SAP AG 1999

(C) SAP AG BC610 2-9


Object Definition and Implementation

Contents:
l Motivation and basic concepts
l Object definition
l Object implementation

ã SAP AG 1999

(C) SAP AG BC610 3-1


Object Definition and Implementation: Unit
Objectives

At the conclusion of this unit, you will be able to:

l Explain the basic technical concepts of the Business


Object Repository
l Explain the dependencies between object definition
and implementation
l Create a new object type or extend an existing one
l Implement an object type using the object macros

ã SAP AG 1999

n BOR - Business Object Repository - Data


n BOB - Business Object Builder - Tool

(C) SAP AG BC610 3-2


Course Overview Diagram

Person Position/job Org. unit


Organization
Role Task

Processes WF definition Step

Attributes Events Methods


Business
objects
Object

ã SAP AG 1999

(C) SAP AG BC610 3-3


Objects - Motivation

Keys Attributes Methods

Business Object
Repository

Table 1 Table 2 TA01


Application
Key Fields Key Fields TA02

ReportXX

Change documents, status management ...

Events

ã SAP AG 1999

n Note: Events are dealt with later in a separate unit


n The application data (tables) and the changes and queries (transactions and reports) that can be
performed on this data are encapsulated in the Business Object Builder.
This encapsulation is used
Ÿ To simplify process modeling
Ÿ As a standard interface for the workflow runtime system

(C) SAP AG BC610 3-4


Using Objects

Step definition
Conditional Fork
branch

Loop

Container operation

Wait for
event
Event
creator

ã SAP AG 1999

n Objects are used in


Tasks à Executing methods
Control structures à Querying attributes
Container operation à Querying attributes
Wait steps, event creator à Triggering or receiving events
Check FM, receiver type FM à Querying attributes
Receiver function module à Receiving events
Roles à Querying attributes
Secondary methods à Calling methods

(C) SAP AG BC610 3-5


Object Types - Relationships

l Inheritance
Functional extension - "is a type of"
l Composition
Key extension - "is part of"
l Association
Foreign key relationship - "in relation to"

ã SAP AG 1999

n Example of inheritance: Accounting document à Customer document


n Key extensions are not allowed with inheritance. Interfaces can only be extended in an upward-
compatible manner (only possible to add new components or redefine existing ones).
n Example of composition: Order à Order item
n Example of association: Material à Purchase requisition

(C) SAP AG BC610 3-6


Object Type - Definition

Object type Program

Interfaces
Virtual attributes
Key Field references
fields
Object references
Attributes ABAP Code

Synchronous Transaction
Methods
Asynchronous Function module

Events Report

ã SAP AG 1999

n BOR is a client-independent directory of all defined object types


n Each object type is assigned to a development class and, therefore, indirectly to an application
component.

(C) SAP AG BC610 3-7


Objects: Properties

l Data encapsulation
l Inheritance
l Polymorphism

ã SAP AG 1999

n Object definitions and implementations can only be manipulated via the Business Object Builder.
n Data encapsulation - definition: Abstraction for the modeler, irrespective of the concrete SAP tables,
transactions, etc.
n Data encapsulation - runtime: A standard interface for calling application functionality is available to
the workflow runtime system, irrespective of the actual implementation.
n Inheritance: Object properties such as attributes, methods and events are passed on to subtypes.
Properties inherited can be redefined in the subtype.
n Polymorphism: Depending on the object type, the object manager always selects the relevant
implementation for the property requested. This property is implemented technically using the "late
binding" principle.
n Dynamic call interface for calls from the workflow runtime system.

(C) SAP AG BC610 3-8


Interfaces

l Assurance of a particular behavior


l Definitions of attributes, methods, events
l Specification of a default implementation
l Hierarchical structure
l Replacement for multiple inheritance

ã SAP AG 1999

n The implementation of an interface using an object type means the assurance of a particular
behavior.
n The definition of an interface can contain a specified default implementation that is used if the
including object type does not perform any implementation of its own.
n An object type that implements an interface must implement all the attributes and methods belonging
to the interface (unless there is a default implementation).
n At present, the Business Object Builder does not check whether all the components belonging to the
interface are actually implemented.
n Interfaces can also enter into inheritance relationships.
n Interfaces replace multiple inheritance. They offer the same options as multiple inheritance, but are
easier to handle (for example, no conflicts when method names are the same).

(C) SAP AG BC610 3-9


Interfaces - Example

Documents

FI MM SD

BKPF EKKO VBAK


IFARCH21
IFIDOCOUT
IFSTATUS

BUS2019 BUS2020 BUS2041 BUS2069 BUS2032

IFSTATUS IFIDOCOUT
BUS2029

ã SAP AG 1999

n BKPF Posting document


BUS2019 Customer document
BUS2020 Vendor document
BUS2041 Asset document
BUS2069 G/L account document
BUS2029 Price change
EKKO Purchasing document
VBAK Sales document
BUS2032 Sales order
n IFSTATUS Generate events from status management
IFARCH21 Archive Link Interface
IFIDOCOUT IDoc outbound processing

(C) SAP AG BC610 3-10


Key Fields

l Specification of object key


l Several key fields possible
l Reference to underlying application table(s)
l Client not necessary

ã SAP AG 1999

n The English ABAP Dictionary names are proposed automatically as the names of the key fields.
n Key fields must be character-based.
n The concatenated key fields can contain a maximum of 70 characters.

(C) SAP AG BC610 3-11


Attributes

l Database or virtual attributes


l Type information from ABAP Dictionary field or
object type
l Single-line and multiple-line attributes

ã SAP AG 1999

n Database attributes are read from the associated application table and buffered in the object. Source
code is generated beforehand by the Business Object Builder for this purpose.
n Virtual attributes are calculated on calling.
n There are different macros for single-line and multiple-line attributes.

(C) SAP AG BC610 3-12


Virtual Attributes

l Combination of other attributes or constants


l Explicit implementation required
l Calculation upon attribute access
l Buffering in the Business Object Builder

ã SAP AG 1999

n For performance reasons, virtual attributes are always preferable to reading background steps,
because the evaluation can take place directly in the workflow manager removing the need to create
a background step.
n The Business Object Builder cannot generate a source code for virtual attributes. The algorithm
required for calculation of the attribute value must therefore always be explicitly programmed.
n Typical examples:
§ language-dependent texts
§ time-dependent values
§ net/gross values
§ object references

(C) SAP AG BC610 3-13


Multiple-Line Attributes

l Correspond to internal tables


l Are almost always virtual attributes
l Can contain either database fields or object references

ã SAP AG 1999

n Example:
List of purchase requisitions for a material (BUS1001.PurchaseRequisition).

(C) SAP AG BC610 3-14


Synchronous/Asynchronous Methods

l Synchronous method
n Result returned directly to calling program
n Return of exceptions possible
l Asynchronous method
n Result can only be returned via an event
n Only restricted exceptions possible
n Method itself does not wait for a possible terminating event

ã SAP AG 1999

n (Import) parameters can be defined in both.


n Asynchronous methods are always necessary if the encapsulated application functionality uses
updating.
n Asynchronous methods can only trigger exceptions in the "dialog part".

(C) SAP AG BC610 3-15


Synchronous Methods

Method
Export
Import Result
Exceptions
Caller

Time

l All display methods


l All methods that do not write their changes to the
database via the update task

ã SAP AG 1999

n The solid arrows represent the control flow.


n The broken arrows represent the transfer of data and control flow.
n The dotted line represents the wait time of the caller.

(C) SAP AG BC610 3-16


Asynchronous Methods

Method Dialog Update

Import

Caller

Time

l All methods that write their changes to the database


via the update task
l Synchronization of processes is required

ã SAP AG 1999

n The solid arrows represent the control flow.


n The broken arrows represent the transfer of data.
n The dotted line represents the wait time of the caller.
n The distinction between synchronous and asynchronous applies to both dialog and background
methods.
n It is up to the caller to coordinate a resynchronization as necessary.
It is up to the method to make the resynchronization possible technically (à Events).

(C) SAP AG BC610 3-17


Communication Methods: Caller - Method

l Communication via parameters


n Import parameters
n Export parameters
l Communication via result
l Communication via exceptions
n Temporary error
n Application error
n System error
l Communication via event

ã SAP AG 1999

n Synchronous methods support communication via parameters, results and exceptions.


n Asynchronous methods support communication via import parameters. An event should be triggered
once they have been processed.
n Export parameters should be avoided. Use a result instead. The result can be multiple-line.
Parameters should be avoided completely if the value can also be read as an object attribute.
n If the result is based on a fixed value domain, automatic branching is possible via these values in the
WF definition.
n If object attributes on the database are changed in the method, the Business Object Builder object
buffer must be invalidated with the macro SWC_REFRESH_OBJECT.
n The type of exception subsequently determines error handling in the work item.
n Exceptions are generally triggered via the macro EXIT_RETURN. There are two special macros,
EXIT_OBJECT_NOT_FOUND and EXIT_CANCELLED, the latter is used to return a user
termination in a synchronous method. User terminations reported in this way are then treated as
temporary errors.

(C) SAP AG BC610 3-18


Reaction to Exception - Dialog Step

Step
(method)

Temp. Sys. Temp. Sys.


OK
error error error error

In process Error Subsequent Subsequent Subsequent


step step step

Not modeled Modeled

ã SAP AG 1999

In the workflow definition… The exception is defined for the object method…
…as a temporary exception: …as an application
or system error:
… a subsequent step is The status of the step changes
modeled for this exception to “completed” and the
subsequent step is executed

… no subsequent step is The step is not yet completed The status of the step
modeled for this exception and remains 'in process'.and associated
workflow changes to
“error”.

(C) SAP AG BC610 3-19


Reaction to Exception - Background Step

Step
(method)

Temp. Temp. Sys. Temp. Temp. Sys.


error OK error
error error error error

Without With counter Without counter With counter


counter
In process In process In process

Error Error Subsequent Subsequent Subsequent Subsequent


step step step step

Not modeled Modeled

ã SAP AG 1999

n Background steps also offer the option of modeling a repeat counter for a temporary error.
If this repeat counter is modeled and an error occurs, the step is repeated automatically as often as
defined, before either assuming "error" or "completed" status (with subsequent execution of the
subsequent step modeled).

(C) SAP AG BC610 3-20


Virtual Attributes - Background Method

Virtual Attributes Background Methods


Read or calculate individual values Read or calculate a list of
or a list of homogeneous values heterogeneous values

Calculate values which are not


dependent on other attributes or
system values
Change values

Evaluation and execution in Evaluation in workflow


workflow manager manager, execution in
work item manager
Buffering of the results in the No buffering of results
Business Object Builder
Fixed communication with the All communication methods
caller possible

ã SAP AG 1999

n The buffering of the virtual attributes must be programmed explicitly in the implementation of the
attribute.
n The return of the value of a virtual attribute to the caller corresponds, in principle, to a result value of
a method.

(C) SAP AG BC610 3-21


Events

l Definition and implementation are separate


l Default parameters need not be set explicitly
l User-defined parameters are set explicitly via container
macros
l Documentation is indispensable

ã SAP AG 1999

n Only definitions of events in the Business Object Builder.


n Default parameters are in the include RSWEINCL.
The following parameters are always incorporated:
§ Triggering object (type, key and object reference)
§ Name of event
§ Language, date and time
§ Triggering user.
n User-defined parameters are only possible for events that are programmed explicitly. Parameters
should not be object attributes of the triggering object.

(C) SAP AG BC610 3-22


Object Type - Release Status

l Modeled
Not accessible at runtime.
l Implemented
Only in tests or internal use, possibly unstable.
l Released
Released for use by the customer. Only upward-
compatible enhancements possible.
l Obsolete
The functionality has been replaced. The old
functionality is still supported for two releases.

ã SAP AG 1999

n The "modeled" status is the only status in which execution is not possible. Customers should,
however, only use components with the "released" status.
n The release information should be noted when a component's status changes to "obsolete".

(C) SAP AG BC610 3-23


Object Type - Default Settings

l Object name
Descriptive name for objects of this type
l Default method
Display for presenting an object instance
l Default attribute
Identifying attribute of an object instance

ã SAP AG 1999

n The object name is used as the element name in the container definition, for example.
n The default method is used, for example, when you double-click objects in a list of object links.
n The default attribute is used, for example, to display objects in lists.

(C) SAP AG BC610 3-24


Implementing Key Fields

Key Field SalesDocument x


include <object>.
Key field SalesDocument
Object type Bus2032 begin_data object. " Do not change.. DATA is generated
Release 21A
Status Released * only private members may be inserted
* into structure private
Texts
data:
Name Sales document
Description Sales document " begin of private,
" to declare private attributes remove comments and
Data type referen. " insert private attributes here ...
Reference table VBAK " end of private,
Reference field VBELN
begin of key,
Search help salesdocument like vbak-vbeln,
end of key,

end_data object. " Do not change.. DATA is generated

ã SAP AG 1999

n Each object type has a program that implements the object type.
n The macro instructions required for programming are incorporated via the include <object>.
n The Business Object Builder always works with object references. These references are used to read
and manipulate the actual application data. An object reference of this kind must be created in the
calling program with the macro SWC_CREATE_OBJECT before a method is called or an attribute
determined.
n Each object program contains the variable SELF which, in turn, contains a reference to the object
instance with which the program was called.
n The object-key-sales document variable (generally: object-key-<name of key>) is declared in
conjunction with the BEGIN_DATA OBJECT macro.
n The declaration between BEGIN_DATA and END_DATA is generated entirely from the definition
data.

(C) SAP AG BC610 3-25


Implementing Database Field Attributes

Attribute DocumentDate x
Attribute DocumentDate
Object type VBAK
Release 30A
Status Released
get_table_property vbak.

data subrc like sy-subrc.


Texts

Name Document date ** Fill


Fill TABLES
TABLES VBAK
VBAK to
to enable
enable Object
Object Manager
Manager
Description Document date (inbound or outbound) ** Access
Access to
to Table
Table Properties
Properties
perform select_table_vbak using subrc.
Source if subrc ne 0.
exit_object_not_found.
Virtual endif.
Database field
end_property.
Attribute properties form select_table_vbak using subrc like sy-subrc.
Multiple-line if object-_vbak-mandt is initial and
Mandatory object-_vbak-vbeln is initial.
Instance-independent select single * from vbak client specified
where mandt = sy-mandt and
vbeln = object-key-salesdocument.
Data type referen.
subrc = sy-subrc.
Dictionary if subrc ne 0. Exit. Endif.
Reference table object-_vbak = vbak.
VBAK
Reference field else.
AUDAT
Search help
subrc = 0.
vbak = object-_vbak.
endif.
Object type endform.
Inverse attribute

ã SAP AG 1999

n Source code is generated in the implementation program to read the date from the application table.
n The source code between GET_TABLE_PROPERTY and END_PROPERTY is generated entirely
from the definition data. The form select_table_<table name> is also generated automatically for the
actual database access.
n The macro EXIT_OBJECT_NOT_FOUND returns the exception "Object not found". This exception
corresponds to the T100 message OL826.

(C) SAP AG BC610 3-26


Implementing Database Field Attributes (Object)

Attribute SoldToParty x
Attribute OrderingParty
Object type VBAK
Release 30A get_table_property vbak.
Status Released
data subrc like sy-subrc.
Texts
* Fill TABLES VBAK to enable Object Manager
Name Ordering party * Access to Table Properties
Description Ordering party perform select_table_vbak using subrc.

Source if subrc ne 0.
exit_object_not_found.
Virtual endif.
Database field
end_property.

Attribute properties form select_table_vbak using subrc like sy-subrc.


if object-_vbak-mandt is initial and
Multiple-line
object-_vbak-vbeln is initial.
Mandatory select single * from vbak client specified
Instance-independent where mandt = sy-mandt and
vbeln = object-key-sealesdocument.
Data type referen. subrc = sy-subrc.
if subrc ne 0. Exit. Endif.
Dictionary object-_vbak = vbak.
Reference table VBAK else.
Reference field KUNNR subrc = 0.
Search help vbak = object-_vbak.
endif.
Object type Customer
endform.
KNA1
Inverse attribute

ã SAP AG 1999

n The source code between GET_TABLE_PROPERTY and END_PROPERTY is generated entirely


from the definition data.
n The macro EXIT_OBJECT_NOT_FOUND returns the exception "Object not found". This exception
corresponds to the T100 message OL826.
n An object reference is generated automatically as an attribute value. This procedure only works
correctly if the referenced object type has precisely one key field. Otherwise, the attribute must be
implemented itself.

(C) SAP AG BC610 3-27


Implementing Virtual Attributes

Attribute SalesGroup x
Attribute SalesGroup
Object type Z_Bus2032
Release 40A
Status Modeled

Texts

Name Sales group begin_data object.


Description Sales group (impl. as virt. attr.) begin of key,
...
Source end of key,
salesgroup type swc_object.
Virtual end_data object.
Database field
get_property salesgroup changing container.

Attribute properties select single * from vbak


where vbeln = object-key-salesdocument.
Multiple-line
Mandatory * create object(-reference)
Instance-independent swc_create_object
object-salesgroup 'TVKGR' vbak-vkgrp.
Data type referen.
* write object(-reference) into container
Dictionary swc_set_element container
Reference table 'SalesGroup' object-salesgroup.
Reference field
Search help end_property.

l Object type TUKGR Sales group


Inverse attribute

ã SAP AG 1999

n The data declaration is generated from the definition data and is used as a runtime buffer.
n The implementation between GET_PROPERTY and END_PROPERTY must be created manually,
since there is no other definition information. The object reference to be returned, in particular, must
be created explicitly via the macro SWC_CREATE_OBJECT.
n Both the Business Object Builder runtime buffer "object-salesgroup" and the associated container
element "SalesGroup" must be completed for data transfer.

(C) SAP AG BC610 3-28


Implementing Multiple-Line Virtual Attributes

Attribute Items x
Attribute Items begin_data object.
Object type VBAK
begin of key,
...
Release 30A
end of key,
Status Released
items type swc_object occurs 0.
end_data object.
Texts

Name
get_property items changing container.
Items
Description Sales document items
* Declare data
tables vbap.
Source data item type swc_object.
data: begin of vbap_key,
l Virtual vbeln like vbap-vbeln,
Database field posnr like vbap-posnr,
end of vbap_key.
data vbap_tab like vbap occurs 0 with header line.
Attribute properties
Multiple-line * Select data
Mandatory
select * from vbap into table vbap_tab
where vbeln = object-key-salesdocument.
Instance-independent
vbap_key-vbeln = object-key-salesdocument.
Data type referen. * Create object reference
Dictionary loop at vbap_tab.
Reference table vbap_key-posnr = vbap_tab-posnr.
Reference field
swc_create_object item 'VBAP' vbap_key.
append item to object-items.
Search help
endloop.

l Object type VBAP Sales item * Assign object reference to container element
Inverse attribute swc_set_table container 'Items' object-items.

end_property.

ã SAP AG 1999

n The data declaration is generated from the definition data and is used as a runtime buffer.
n The implementation between GET_PROPERTY and END_PROPERTY must be created manually,
since there is no other definition information. The object reference to be returned, in particular, must
be created explicitly via the macro SWC_CREATE_OBJECT.
n Both the Business Object Builder runtime buffer "object-salesgroup" and the associated container
element "SalesGroup" must be completed for data transfer.
n The actual implementation of the attribute also contains a query as to whether the runtime buffer is
completed.

(C) SAP AG BC610 3-29


Implementing Synchronous Methods

Method Display x

Method Display
Object type Z_Bus2032
Release 40A
Status Implemented

Method Display x

Method Display
Name Object type Z_Bus2032
Description Release 40A
General Status
ResultABAP
type Implemented begin_method display changing container.

Name Display set parameter id 'AUN' field object-key-salesdocument.


Dialog Description Display object call transaction 'VA03' and skip first screen.
Synchron
General
Result para Result type ABAP end_method.

Instance-ind Function module


API function
VA02 Transaction
Dialog module
Report
Miscellaneous
Name VA03

ã SAP AG 1999

n The implementation between BEGIN_METHOD and END_METHOD is generated from the


definition data.
n The macro SWC_REFRESH_OBJECT must also be called after the application functionality for
synchronous methods that can change object attributes, in order to delete the object buffer.

(C) SAP AG BC610 3-30


Implementing Asynchronous Methods

Method DeliveryBlockReset x

Method DeliveryBlockReset
Object type Z_Bus2032
Release 40A
Status Implemented

Method Edit x

Method DeliveryBlockReset
Name Object type Z_Bus2032
Description Release 40A begin_method deliveryblockreset changing container.
General Status
ResultABAP
type Implemented
select single * from vbak
where vbeln = object-key-salesdocument.
Name ResetDelBlock
Description
if vbak-lifsk <> space.
Dialog Reset delivery block
* invoke method only if delivery lock is set
Synchron
General Result type ABAP set parameter id 'AUN'
Result para
field object-key-salesdocument.
call transaction 'VA02' and skip first screen.
Instance-ind Function module endif.
API function
VA02 Transaction end_method.
Dialog module
Report
Miscellaneous
Name VA02

ã SAP AG 1999

n The implementation between BEGIN_METHOD and END_METHOD is generated from the


definition data. The generated source text has been extended so that the transaction is only called if a
delivery block is set.
n It is not necessary to call the macro SWC_REFRESH_OBJECT in this case, because the object
context is always lost in an asynchronous method
n The terminating event must be triggered within the transaction called.
n The single-step task that encapsulates this method requires at least one terminating event.

(C) SAP AG BC610 3-31


Implementing Exceptions in Methods

Object Type BUS1001: Display Exceptions For Method GETMISSEDVIEWS


Object Edit Goto Utilities View System Help

Exceptions
No. Object type Temp. App. Syst. AppArea Message Message text
1000 BUS1001 MA 279 & blocked by another user
7000 BUS1001 M3 195 No selectable views

Exception 1000 begin_method getmissedviews changing container.


Exception 1000 ...
call function 'ENQUEUE_EMMARAE'
Object type BUS1001 exporting
Release 30D matnr = object-key-material
_scope = '2'
Error type _wait = 'X'
Temporary error exceptions
Application error foreign_lock = 1.
System error if sy-subrc ne 0.
* temporary error - material currently locked by another user
exit_return 1000 object-key-material space space space.
Message endif.
Application area ...
MA
end_method.
Message 279
& blocked by another user

ã SAP AG 1999

n No source code is generated for triggering an exception.


n Every exception must correspond to a T100 message.
n Up to four parameters, which correspond to the four parameters of the T100 message, can be
transferred with the EXIT_RETURN macro.
n The triggering of exceptions is the same for all error types.

(C) SAP AG BC610 3-32


Implementing Parameter Transfer

Object Type BUS2032: Edit Parameters for Method CREATE


Object Edit Goto Utilities View System Help

Other view Program Exceptions

Overview

Parameter Object type Creation rel. Impl. Man. Exp.

SalesDocumentType VBAK 21A begin_method create changing container.


TransactionCode VBAK 21A
data: salesdocumenttype like tvak-auart,
Parameter SalesDocumentType transactioncode like t180-tcode.
Object type VBAK
Release 21A
swc_get_element container
. Texts 'SalesDocumentType' salesdocumenttype.
Name Sales document type
set parameter id 'AAT' field salesdocumenttype.
Description Sales document type
swc_get_element container
'TransactionCode' transactioncode.
Parameter properties

Import Mandatory set parameter id 'AAT' field salesdocumenttype.


Export call transaction transactioncode.
Multiple-line .
.
.
Data type reference

Dictionary
Reference table TVAK
Reference field AUART
Search help

Object type

ã SAP AG 1999

n The parameter transfer source code is generated entirely from the definition data.
n Single-line input parameters are generally read via the macro SWC_GET_ELEMENT, and output
parameters written via the macro SWC_SET_ELEMENT.
The macros SWC_GET_TABLE and SWC_SET_TABLE are used for multiple-line parameters.

(C) SAP AG BC610 3-33


Implementing the Return of Results

Method
Method Approve
Approve x
Method Approve begin_method approve changing container.
Object type FORMABSENC
data: proc_state like swxformabs-procstate.
Release 30A
Status Released
call function 'SWX_FORMABS_APPROVE'
exporting
formnumber = object-key-number
Name Approve importing
Description Approve form proc_state = proc_state
exceptions
form_not_found = 01
General Result type ABAP
aborted = 02.
case sy-subrc.
Dictionary
Dictionary when 00.
swc_set_element container result proc_state.
Reference table SWXFORMABS
when 01.
Reference field PROCSTATE exit_return 1301 space space space space.
Search help when 02.
¡
¡ Object
Object type
type exit_cancelled.
endcase.

Multiple-line
Multiple-line end_method.

ã SAP AG 1999

n The result parameter must be set explicitly under the name "result" using the macro
SWC_SET_ELEMENT. The constant "result" is predefined and need not be defined explicitly.

(C) SAP AG BC610 3-34


Implementing Attribute Access

Attribute SalesGroup x
Attribute SalesGroup
Object type Z_Bus2032
Release 40A
Status Modeled

Texts

Name Sales group include <CNTN01>.


Description Sales group (impl. as virt. attr.)
parameters: sales_order_key like vbak-vbeln.
Source
data: sales_order type swc_object,
sales_group type swc_object.
Virtual
Database field
* create object(-reference)
swc_create_object
sales_order 'Z_BUS2032' sales_order_key.
Attribute properties
Multiple-line if sy-subrc ne 0.
Mandatory ” do your own error handling
Instance-independent endif.

Data type referen. * read attribute SalesGroup of order


swc_get_property sales_order 'SalesGroup' sales_group.
Dictionary
Reference table
Reference field
Search help

Object type TUKGR Sales group


Inverse attribute

ã SAP AG 1999

n The include <cntn01> must always be incorporated in the calling program. This include is also
incorporated in the implementation program via the include <object>.
n Before attribute access, an object reference must be created by calling the macro
SWC_CREATE_OBJECT. Error handling measures must be incorporated if the object reference
cannot be created.
n Attribute access for single-line attributes uses the macro SWC_GET_PROPERTY, and for multiple-
line attributes the macro SWC_GET_TABLE_PROPERTY - irrespective of whether a virtual or a
database attribute is read.
n Attributes cannot be set via macros. Object values can only be changed via methods.

(C) SAP AG BC610 3-35


Implementing Method Calls

Object Type BUS2032: Display Parameters For Method CONVERTTOCOMPCURRENT


Object Edit Goto Utilities View System Help

Other view Program Exceptions Parameter CompCurrent


Parameter CompCurrency
Overview
Object type VBAK
Parameter Object type Created Release 40A
CompCurrency VBAK 40A
NetvalueInCompCurr VBAK 40A Texts
Name Comparison currency
Description Comparison currency
include <CNTN01>.

data: sales_order type swc_object, Parameter properties


comp_curreny like vbak-waerk default ...,
new_value like vbak-netwr. Import Mandatory
swc_container method_container. Export
Multiple-line
* create object(-reference)
swc_create_object sales_order Data type reference
'BUS2032' sales_oder_key.
if sy-subrc ne 0. Dictionary
” do your own error handling Reference table VBAK
endif. Reference field WAERK
Search help
* set import parameters for this method Dictionary
swc_set_element method_container
'CompCurrency' comp_currency.

* call method now


swc_call_method sales_order
'ConvertToCompCurrency' method_container.

* read export parameter


swc_get_element method_container
ã SAP AG 1999
'NetvalueInCompCurrency' new_value.

n The include <cntn01> must always be incorporated in the calling program. This include is also
incorporated in the implementation program via the include <object>.
n Before attribute access, an object reference must be created by calling the macro
SWC_CREATE_OBJECT. Error handling measures must be incorporated if the object reference
cannot be created.
n The import parameters of the method must also be completed before the method call.
n The actual method call is implemented with the macro SWC_CALL_METHOD.
n The export parameters can be read after the call.

(C) SAP AG BC610 3-36


Macros - Summary

l Macros for object processing in include <cntn01>


n Container macros, for example setting or reading container
elements
n Object macros, for example creating objects or reading
attribute values
l Objects can also be manipulated outside the
workflow via macros

ã SAP AG 1999

n The macro number must always be included if you are working in a program with objects. The
macro is included automatically in the Business Object Builders implementation programs via
<object>.
n Only macros from <cntn01> may be used to manipulate objects and containers.

(C) SAP AG BC610 3-37


Macros for Object Definition and Creation

l Object reference
n Declaration
DATA: <obj_ref> TYPE SWC_OBJECT
n Creation
SWC_CREATE_OBJECT <obj_ref> <obj_type> <obj_key>

ã SAP AG 1999

n When SWC_CREATE_OBJECT is called, the method "ExistenceCheck" of the associated object


type is always called implicitly, in order to prevent references to non-existent objects.

(C) SAP AG BC610 3-38


Macros for Attributes and Methods

l Attribute access
n SWC_GET_[TABLE_]PROPERTY <obj_ref> <attribute> <value>
l Method call
n SWC_CALL_METHOD <obj_ref> <method> <container>

ã SAP AG 1999

n An object reference must be created before an object macro is called (for example, for attribute
access or method call).
n These macros are not usually used in object implementation, but are required in the program that the
object uses.
n If the <method> is SPACE for SWC_CALL_METHOD, the default method is executed.

(C) SAP AG BC610 3-39


Macros for Triggering Exceptions

l Triggering exceptions
n EXIT_RETURN <exception_no> <var1> ... <var4>
n EXIT_OBJECT_NOT_FOUND
n EXIT_CANCELLED

ã SAP AG 1999

n EXIT_RETURN - trigger general exceptions (similar to T100 messages).


n EXIT_OBJECT_NOT_FOUND - specified object instance not found.
n EXIT_CANCELLED - action cancelled by user (for example, in methods after BACK).
n It is not necessary to define the exceptions EXIT_OBJECT_NOT_FOUND and
EXIT_CANCELLED explicitly in a method.
n Customer-defined exceptions must be in the customer name range.

(C) SAP AG BC610 3-40


Macros for Managing the Object Reference

l Type and key


n SWC_GET_OBJECT_TYPE <obj_ref> <obj_type>
n SWC_GET_OBJECT_KEY <obj_ref> <obj_key>
l Refreshing object types
n SWC_REFRESH_OBJECT <obj_ref>

ã SAP AG 1999

n When a work item is executed, the objects in the associated container are automatically refreshed.

(C) SAP AG BC610 3-41


Container Macros

l Definition and initialization


n SWC_CONTAINER <cont>
n SWC_CREATE_CONTAINER <cont>
l Reading and setting elements
n SWC_GET/SET_ELEMENT <cont> <element> <value>
n SWC_GET/SET_TABLE <cont> <element> <int_tab>

ã SAP AG 1999

n The container macros are also located in the include <cntn01>.


n All types of container are manipulated via these macros (for example, task, role, event).

(C) SAP AG BC610 3-42


Delegation

Process definition BOB


BUS1001
TS0001 TS0002
SAP BUS1001. BUS1001. Edit
Standard Edit Display Display

BUS1001

Edit
Display
TS9001 TS9002 TS9003
Inheritance ZBUS1001. ZBUS1001. ZBUS1001.
Edit Display Release ZBUS1001

Edit
Display
Release

BUS1001
BUS1001

Edit
Display
TS0001 TS0002 TS9004
Delegation BUS1001. BUS1001. BUS1001.
Edit Display Release ZBUS1001

Edit
Display
Release
ã SAP AG 1999

n Problem:
How can customers use their own object extensions with the tasks, events, etc. supplied by SAP
§ Without having to change the application program where events are triggered,
§ Without having to redefine existing tasks.
n Solution:
Define subtype and delegation.
Delegation "covers" the original supertype.
Continue to use the supertype.
n Gray/Top: Behavior without inheritance
Red/Middle: Behavior with inheritance
Blue/Bottom:Behavior with delegation - the object type BUS1001 is regarded as having the
properties of Z_BUS1001 (that is, additional events, attributes and methods).
n In the Business Object Builder itself, you can only see from the basic data for a supertype whether a
delegation has been defined.

(C) SAP AG BC610 3-43


Object Definition and Implementation: Unit Summary

l Explain the basic technical concepts of


the Business Object Builder
l Explain the dependencies between object definition
and implementation
l Explain the points to note when creating or
extending an object type

ã SAP AG 1999

(C) SAP AG BC610 3-44


Object Definition and Implementation Exercises

Unit: Object Definition and Implementation


Section: Motivation and Properties of Object Types

After completion of these exercises, you will be able to:


• Navigate in the Business Object Builder
• Change the default settings and release status of an object type

As a member of the workflow development group in your enterprise, you


must:
• Understand the basic technical concepts of the BOB
• Master the search and navigation options in the BOB
• Be familiar with the various statuses of an object type

Note: After every implementation step in the following tasks, note


the changes of color, status and icons. For example, the various
statuses are represented with different icons.

1-1 Familiarize yourself with the Business Object Repository.


1-1-1 Find and check your object type Z##MARA. The ‘##’ characters refer to
your group number.
1-1-2 Set the default attribute to MaterialDescription.
Note: You can find the default settings of an object type via ‘Goto >
Basic data’ on the ‘Change object type’ screen.

1-1-3 Change the status of your object type to ‘released’. You can ignore the
message ”The method ExistenceCheck is not redefined”.
Note: If you have not completed this step, you cannot use your
object type in a task or role.

(C) SAP AG BC610 3-45


Unit: Object Definition and Implementation
Section: Object definition

After completion of these exercises, you will be able to:


• Define a new object type

When implementing a workflow you will notice that not all customer-
specific business processes can be modeled using a business object
supplied by SAP. In these cases, you must create a new object type.

2-1 Create a new business object type


2-1-1 Create a new business object type ZPLANT##, where ‘##’ stands for your
group number. Complete the basic data of this object type as below.

Supertype Please do not complete this field!


Object type ZPLANT##
Object name Plant_##
Name Plant ##
Short description Plant for group ##
Program ZPLANT##
Application S

Note: The names of the object type and the program must be in the
customer namespace.
Note: The object type, object name and program name must not
contain any blank characters.

2-1-2 You must define a key field for your new object type. In a second session,
look at the key of table T001W, the lines of which each represent a plant.
Define the key of your business object based on the key of this underlying
application table.
2-1-3 Create a new attribute Name based on the field NAME1 of table T001W.
Generate the implementation for your definition with the Business Object
Builder.
2-1-4 Redefine the method Display. Do not define the method with reference to a
transaction or a function module. First, look at the implementation proposal
generated by the Business Object Builder. Then complete the
(C) SAP AG BC610 3-46
implementation of this method by copying the missing lines from the
method Display of the object type BUS0008 supplied by SAP.

Note: You must declare the view V_T001W in the implementation


program of your object type.

(C) SAP AG BC610 3-47


Unit: Object Definition and Implementation
Section: Object implementation

After completion of these exercises, you will be able to:


• Create a new object type as subtype of an existing object type

When implementing a workflow you will notice that the object types
supplied by SAP do not meet your requirements fully. In these cases, you
must extend an existing object type by creating a customer-specific
subtype for it.

3-1 Create a subtype of your material object type.


3-1-1 Create a subtype ZMARA##A for your object type Z##MARA. Complete
the basic data of your new object type as below.

Supertype Z##MARA
Object type ZMARA##A
Object name MARA_##_Version_A
Name MARA ## Version A
Short description Material group ## Version A
Program ZMARA##A
Application S

Note: The names of the object type and the program must be in the
customer namespace.
Note: The object type, object name and program name must not
contain any blank characters.

3-2 Extend your new object type so that it meets additional requirements.

Note: After each definition step, also check the source code in the
implementation program of the object type.

(C) SAP AG BC610 3-48


3-2-1 For the workflow development, you require events as triggering or
terminating events for your tasks.
Create two new events BasicMaterialChanged and OldMaterialChanged
for your object type.
3-2-2 Change the status of the two events to ‘implemented’.
3-2-3 Implement the two events using event creation from change documents. The
change document required is MATERIAL. Restrict the triggering of the
event for BasicMaterialChanged to the field MARA-WRKST and for
OldMaterialChanged to MARA-BISMT.
3-2-4 Define another event DeadlineTest for your object type with a parameter
LatestEndDate that refers to the field SYST-DATUM. This parameter will
be used later to transfer an “end” deadline for a step within a workflow.
3-2-5 Create a new attribute ChangedBy based on the field MARA-AENAM.
This attribute specifies the user who last changed the underlying material.
You will use this attribute later to filter out ‘your’ material.
3-2-6 Create a new method Change on the basis of transaction MM02.

Note: The transaction MM02 writes your changes to the database via
an update task.

3-2-7 Create a new method ChangeDocDisplay.


This method is to display all change documents for a particular material and
hence make the change history visible. Use the transaction MM04 for the
implementation.
3-2-8 Create a new method DisplayView.
The purpose of this method is to display a material from a particular view.
The desired view is to be transferred via the input parameter MaterialView.
Use the implementation to ensure that value "K" (corresponds to view
"Basic data 1") is accepted as the default for this parameter.
The actual view is displayed using transaction MM03.

Note: Transaction MM03 recognizes a SET/GET parameter MXX


via which the view used to start the transaction can be controlled.
Supply this SET/GET parameter with your input parameter value.
Note: The MaterialView input parameter must be defined with
reference to the database field T132T-STATM.
3-2-9 Create a (virtual object-value) attribute Plant for one of the plants
connected with the material.
Use the field MARC-WERKS for the implementation of the attribute to
determine the plants in which the particular material is defined. Return the
first plant found in this manner in the form of an object reference from your
object type ZPLANT## as a value of the attribute.

3-3 Optional extensions

(C) SAP AG BC610 3-49


3-3-1 Create a (virtual database field) attribute IndustryName for the long text
for the value of the existing attribute Industry. This industry name can be
read from the field MBBEZ of table T137T on a language-specific basis.
3-3-2 Create a (virtual, multiline and object-value) attribute QMessages that lists
all quality notifications in which the current material is used.

Note: Use the field MATNR in table QMEL to find the quality
notifications. The object type BUS2078 supplied by SAP
implements the quality notifications.

3-3-3 Create a new method CreateMaterialFromReference.


Using a material number transferred via the input parameter
ReferenceMaterialNumber, this instance-independent asynchronous
method is intended to generate a new material for which the material type
and the industry from the reference material are transferred. If no material
exists for the transferred reference material number, an exception is to be
triggered with reference to the T100 message M3 305 ("The material & is
not available").
To create the material, use transaction MM01.

Note: Transaction MM01 recognizes the following three SET/GET


parameters:
1) RMA – to set the reference material number
2) MTA – to set the material type
3) MTP – to set the industry
Supply these SET/GET parameters with the values from your input
parameters.
Note: The ReferenceMaterialNumber input parameter must be
defined with reference to the database field MARA-MATNR.

(C) SAP AG BC610 3-50


Object Definition and Implementation - Solutions

Unit: Object Definition and Implementation


Topic: Motivation and Properties of Object Types

1-1 Familiarize yourself with the Business Object Builder.

Solution:
Object type Z00MARA

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools > Business
Object Builder
Note: Test materials (for all following tasks as well):
200-100 as material of type HALB
200-101 as material of type FERT
200-210 as material of type ROH

(C) SAP AG BC610 3-51


***** Implementation of object type Z00MARA *****
INCLUDE <OBJECT>.
BEGIN_DATA OBJECT. " Do not change.. DATA is generated
* only private members may be inserted into structure private
DATA:
" begin of private,
" to declare private attributes remove comments and
" insert private attributes here ...
" end of private,
BEGIN OF KEY,
MATERIAL LIKE MARA-MATNR,
END OF KEY,
PLANT TYPE SWC_OBJECT.
END_DATA OBJECT. " Do not change.. DATA is generated

BEGIN_METHOD CHANGEDOCDISPLAY CHANGING CONTAINER.


SET PARAMETER ID 'MAT' FIELD OBJECT-KEY-MATERIAL.
CALL TRANSACTION 'MM04' AND SKIP FIRST SCREEN.
END_METHOD.

GET_PROPERTY PLANT CHANGING CONTAINER.


DATA: FIRST_PLANT LIKE MARC-WERKS OCCURS 0 WITH HEADER LINE.
IF OBJECT-PLANT IS INITIAL. " check buffer contents.
" find one arbitrary plant related to this material
SELECT WERKS FROM MARC CLIENT SPECIFIED
INTO TABLE FIRST_PLANT
UP TO 1 ROWS
WHERE MANDT = SY-MANDT AND
MATNR = OBJECT-KEY-MATERIAL.
" create an object reference using the found plant key
" if we found no such plant, we'll implicitly create an empty ref
READ TABLE FIRST_PLANT INDEX 1.
SWC_CREATE_OBJECT OBJECT-PLANT 'ZPLANT00' FIRST_PLANT.
ENDIF.
SWC_SET_ELEMENT CONTAINER 'Plant' OBJECT-PLANT.
END_PROPERTY.

BEGIN_METHOD DISPLAYVIEW CHANGING CONTAINER.


DATA:MATERIALVIEW LIKE T132T-STATM.
SWC_GET_ELEMENT CONTAINER 'MaterialView' MATERIALVIEW.
IF MATERIALVIEW IS INITIAL.
MATERIALVIEW = 'K'. " display basic view
ENDIF.
SET PARAMETER ID 'MAT' FIELD OBJECT-KEY-MATERIAL.
SET PARAMETER ID 'MXX' FIELD MATERIALVIEW.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
END_METHOD.

BEGIN_METHOD CHANGE CHANGING CONTAINER.


SET PARAMETER ID 'MAT' FIELD OBJECT-KEY-MATERIAL.

(C) SAP AG BC610 3-52


CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.
END_METHOD.

(C) SAP AG BC610 3-53


Unit: Object Definition and Implementation
Section: Object definition

After completion of these exercises, you will be able to:


• Define a new object type

When implementing a workflow you will notice that not all customer-
specific business processes can be modeled using a business object
supplied by SAP. In these cases, you must create a new object type.

2-1 Create a new business object type

Solution:
Object type ZPLANT00

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools > Business
Object Builder

(C) SAP AG BC610 3-54


***** Implementation of object type ZPLANT00 *****
INCLUDE <OBJECT>.
BEGIN_DATA OBJECT. " Do not change.. DATA is generated
* only private members may be inserted into structure private
DATA:
" begin of private,
" to declare private attributes remove comments and
" insert private attributes here ...
" end of private,
BEGIN OF KEY,
PLANT LIKE T001W-WERKS,
END OF KEY,
_T001W LIKE T001W.
END_DATA OBJECT. " Do not change.. DATA is generated

TABLES: T001W, V_T001W.

GET_TABLE_PROPERTY T001W.
DATA SUBRC LIKE SY-SUBRC.
* Fill TABLES T001W to enable Object Manager Access to Table Properties
PERFORM SELECT_TABLE_T001W USING SUBRC.
IF SUBRC NE 0.
EXIT_OBJECT_NOT_FOUND.
ENDIF.
END_PROPERTY.

* Use Form also for other Properties to fill TABLES T001W


FORM SELECT_TABLE_T001W USING SUBRC LIKE SY-SUBRC.
IF OBJECT-_T001W-MANDT IS INITIAL AND
OBJECT-_T001W-WERKS IS INITIAL.
" read data from database table, if BOR buffer is empty
SELECT SINGLE * FROM T001W CLIENT SPECIFIED
WHERE MANDT = SY-MANDT
AND WERKS = OBJECT-KEY-PLANT.
SUBRC = SY-SUBRC.
IF SUBRC NE 0. EXIT. ENDIF.
OBJECT-_T001W = T001W.
ELSE. " read data from BOR buffer
SUBRC = 0.
T001W = OBJECT-_T001W.
ENDIF.
ENDFORM.

(C) SAP AG BC610 3-55


BEGIN_METHOD DISPLAY CHANGING CONTAINER.
" coding copied from BUS0008
CLEAR V_T001W.
V_T001W-MANDT = SY-MANDT.
V_T001W-WERKS = OBJECT-KEY-PLANT.
CALL FUNCTION 'VIEW_MAINTENANCE_SINGLE_ENTRY'
EXPORTING
ACTION = 'SHOW'
VIEW_NAME = 'V_T001W'
CHANGING
ENTRY = V_T001W.
END_METHOD.

(C) SAP AG BC610 3-56


Unit: Object Definition and Implementation
Section: Object implementation

After completion of these exercises, you will be able to:


• Create a new object type as subtype of an existing object type

When implementing a workflow you will often notice that the object
types supplied by SAP do not meet your requirements fully. In these
cases, you must extend an existing object type by creating a customer-
specific subtype for it.

3-1 Create a subtype of your material object type.


3-2 Extend your new object type so that it meets additional requirements.

Solution:
Object type Z00MARA

Path (via SAP Easy Access):


§ To create/change the object type
Tools > SAP Business Workflow > Development > Definition tools > Business Object
Builder
§ For the linkage between event execution and a change document
Tools > SAP Business Workflow > Development > Definition tools > Events > Event
creation > Change documents > Linkage
3-3 Optional extensions
Solution:
Object type ZRGMARA

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools > Business
Object Builder

(C) SAP AG BC610 3-57


***** Implementation of object type ZRGMARA *****
INCLUDE <OBJECT>.
BEGIN_DATA OBJECT. " Do not change.. DATA is generated
* only private members may be inserted into structure private
DATA:
" begin of private,
" to declare private attributes remove comments and
" insert private attributes here ...
" end of private,
BEGIN OF KEY,
MATERIAL LIKE MARA-MATNR,
END OF KEY,
QMESSAGES TYPE SWC_OBJECT OCCURS 0,
INDUSTRYNAME LIKE T137T-MBBEZ.
END_DATA OBJECT. " Do not change.. DATA is generated

TABLES: T137T.
TABLES: QMEL.
TABLES: MARA.
TABLES: T006.

GET_PROPERTY INDUSTRYNAME CHANGING CONTAINER.


DATA: GETINDUSTRYNAME LIKE T137T-MBBEZ.
DATA: INDUSTRY_KEY LIKE MARA-MBRSH.
IF OBJECT-INDUSTRYNAME EQ SPACE. " check buffer contents
SWC_GET_PROPERTY SELF 'Industry' INDUSTRY_KEY.
SELECT SINGLE * FROM T137T
WHERE SPRAS = SY-LANGU AND
MBRSH = INDUSTRY_KEY.
IF SY-SUBRC EQ 0.
OBJECT-INDUSTRYNAME = T137T-MBBEZ.
ELSE.
OBJECT-INDUSTRYNAME = SPACE.
ENDIF.
ENDIF.
SWC_SET_ELEMENT CONTAINER 'IndustryName' OBJECT-INDUSTRYNAME.
END_PROPERTY.

(C) SAP AG BC610 3-58


BEGIN_METHOD GETINDUSTRYNAME CHANGING CONTAINER.
DATA: GETINDUSTRYNAME LIKE T137T-MBBEZ.
DATA: INDUSTRY_KEY LIKE MARA-MBRSH.
SWC_GET_PROPERTY SELF 'Industry' INDUSTRY_KEY.
SELECT SINGLE * FROM T137T
WHERE SPRAS = SY-LANGU AND
MBRSH = INDUSTRY_KEY.
IF SY-SUBRC EQ 0.
GETINDUSTRYNAME = T137T-MBBEZ.
ELSE.
GETINDUSTRYNAME = SPACE.
ENDIF.
SWC_SET_ELEMENT CONTAINER RESULT GETINDUSTRYNAME.
END_METHOD.

GET_PROPERTY QMESSAGES CHANGING CONTAINER.


DATA: LOCAL_QMEL LIKE QMEL OCCURS 0 WITH HEADER LINE.
DATA: THIS_QMEL TYPE SWC_OBJECT.
DATA: LINENO LIKE SY-TFILL.
DESCRIBE TABLE OBJECT-QMESSAGES LINES LINENO. " check buffer contents
IF LINENO = 0. " read from database
SELECT * FROM QMEL INTO TABLE LOCAL_QMEL
WHERE MATNR = OBJECT-KEY-MATERIAL.
LOOP AT LOCAL_QMEL.
SWC_CREATE_OBJECT THIS_QMEL 'BUS2078' LOCAL_QMEL-QMNUM.
IF SY-SUBRC EQ 0.
APPEND THIS_QMEL TO OBJECT-QMESSAGES.
ENDIF.
ENDLOOP.
ENDIF.
SWC_SET_TABLE CONTAINER 'QMessages' OBJECT-QMESSAGES.
END_PROPERTY.

(C) SAP AG BC610 3-59


BEGIN_METHOD CREATEMATERIALFROMREFERENCE CHANGING CONTAINER.
DATA: REFERENCEMATERIALNO LIKE MARA-MATNR,
INDUSTRY LIKE MARA-MBRSH,
MAT_TYPE LIKE MARA-MTART.
DATA: REF_MAT TYPE SWC_OBJECT.
SWC_GET_ELEMENT CONTAINER 'ReferenceMaterialNo'
REFERENCEMATERIALNO.
SWC_CREATE_OBJECT REF_MAT 'Z00MARA' REFERENCEMATERIALNO.
IF SY-SUBRC NE 0.
EXIT_RETURN 2000 REFERENCEMATERIALNO SPACE SPACE SPACE.
ENDIF.
SWC_GET_PROPERTY REF_MAT 'Industry' INDUSTRY.
SWC_GET_PROPERTY REF_MAT 'MaterialType' MAT_TYPE.
SET PARAMETER ID 'RMA' FIELD REFERENCEMATERIALNO.
SET PARAMETER ID 'MTA' FIELD MAT_TYPE.
SET PARAMETER ID 'MTP' FIELD INDUSTRY.
CALL TRANSACTION 'MM01'.
END_METHOD.

BEGIN_METHOD COPYMATERIAL CHANGING CONTAINER.


DATA: INDUSTRY LIKE MARA-MBRSH,
MAT_TYPE LIKE MARA-MTART.
SWC_GET_PROPERTY SELF 'Industry' INDUSTRY.
SWC_GET_PROPERTY SELF 'MaterialType' MAT_TYPE.
SET PARAMETER ID 'RMA' FIELD OBJECT-KEY-MATERIAL.
SET PARAMETER ID 'MTA' FIELD MAT_TYPE.
SET PARAMETER ID 'MTP' FIELD INDUSTRY.
CALL TRANSACTION 'MM01'.
END_METHOD.

(C) SAP AG BC610 3-60


Tasks

Contents
l Single-step tasks
l Multistep tasks

ã SAP AG 1999

(C) SAP AG BC610 4-1


Tasks: Unit Objectives

At the conclusion of this unit, you will be able to:

l Explain the difference between a single-step task and


a multistep task
l Define and start single-step and multistep tasks

l Recognize and define the bindings within a multistep


task

ã SAP AG 1999

(C) SAP AG BC610 4-2


Tasks: Overview Diagram

Person Position/job Org. unit


Organization
Role Task

Processes WF definition Step

Attributes Events Methods


Business
objects
Object

ã SAP AG 1999

(C) SAP AG BC610 4-3


Single-Step Tasks

Single-Step Task Organization


BOB
model
Object type:

Attributes l Texts Org. unit


Method l Object methods
Job
Event l Triggering, terminating
events Position
l Task profile Employee
l Default role
User

ã SAP AG 1999

n The default role is evaluated if the task is used either outside a workflow or in a step definition
without agent assignment.
n The following texts can be defined:
§ Work item text (worklist in the Business Workplace)
§ Task description
§ Text for completion
§ Text for latest end
§ Text for latest start
§ Text for requested end

(C) SAP AG BC610 4-4


Synchronous / Asynchronous Tasks

l Single-step task referring to synchronous method


n Single-step task is terminated when method reports back to
caller
n Binding between task container and method container in
both directions
l Single-step task referring to asynchronous method
n Method started by workflow system
n Results have to be returned via a completed event
n Single-step task is terminated when a terminating event
occurs

ã SAP AG 1999

n Communication between single-step tasks and object method:


§ Synchronous:
The method is called, takes over the process control and reports back to the caller after processing.
§ Asynchronous:
The method is called and runs without any connection to the caller. It does not report back to the
caller.
n Note the following about synchronous/asynchronous calling and synchronous/asynchronous
reporting back in the step definition of a workflow:
§ The task method is always called synchronously (in the same session as the caller).
§ Before and after methods are always called synchronously.
§ Secondary methods are always called asynchronously (in a new external session).
§ Reports back to the workflow are only made from the task method. Secondary methods are only
for display purposes.
n An explicit confirmation can be modeled in the step definition for both synchronous and
asynchronous tasks.
n Synchronous tasks can also have terminating events. The task is then terminated either when it is
successfully executed or when the terminating event is received. In this case, the terminating event
cannot be triggered within the associated object method.

(C) SAP AG BC610 4-5


Synchronous Tasks

Method
Export
Import Result
Exceptions
WIM

Time

ã SAP AG 1999

n The task is started via the work item manager (WIM).


n The method is started within the task. The WIM caters for the input parameters of the method.
n The WIM waits until execution of the method is terminated.
n Once execution of the method is terminated, the WIM receives the export parameters or exceptions
of the method.

(C) SAP AG BC610 4-6


Asynchronous Tasks

Dialog Update
Method
Termination
Import of the
event
WIM

EM
Enter linkage for Delete linkage for
terminating event terminating event

Time

ã SAP AG 1999

n The task is started via the work item manager (WIM). When the associated work item is created, the
WIM writes the linkages for the terminating events.
n The method is started within the task. The WIM caters for the input parameters of the method.
n The WIM waits for the end of the synchronous part of the method execution (this part takes place
within a dialog process) and can then execute actions that are independent of the terminating event.
n Once the asynchronous part of the method execution is terminated (usually within an updating
process), the WIM receives a terminating event of the task, deletes all linkages and then continues.

(C) SAP AG BC610 4-7


Workflow Definition Steps

Workflow template Workflow definition Step

• Reference to
Workflow definition • Activity (task reference)
• Condition
• Definition of triggering • Multiple condition
events • Event creator
• Definition of the • Wait for event
interface (Import and • Process control
export parameters as • Container operation
elements of the • User decision
workflow container)
• Assignment of initial • Loop (until)
values • Loop (while)
• Agent assignment • Fork
for starting from the • Document from
WF development template
environment

ã SAP AG 1999

n The steps can be arranged in sequence or in parallel.


n Each step is a determining component of its own block. Operations carried out on individual steps
always affect the entire block in which the step is located.

(C) SAP AG BC610 4-8


Using the Workflow Container

Workflow
Container

1
Start via event

2
Container operation

3
Condition

4
Wait step
5
Activity

6
Deadline monitoring

ã SAP AG 1999

n The workflow container is basically used to determine the import and export parameters of the entire
workflow and to exchange data between the individual steps.
n (1) Data from the triggering event is transferred to the workflow container as input parameters.
n (2) In a container operation as well, data is both read from (right-hand side of the allocation) and
written to (left-hand side of the allocation) the workflow container.
n (3) Data is read from the workflow container in a branch control condition.
n (4) In a wait step, data is both read from (for example, to set up the instance linkage for the event to
be received) and written to (for example, data received with the event) the workflow container.
n (5) In an activity as well, data is both read from (for example, the input parameters of the task to be
executed) and written to (for example, the output parameters of this task) the workflow container.
In addition, data is read from the workflow container to resolve the role used in the step for agent
determination.
n (6) Data is read from the workflow container for deadline monitoring (for example, the latest end).

(C) SAP AG BC610 4-9


Containers and Binding

Workflow Roles Work Item Methods event


Container Container Container Container Container

2
Triggering
event 1

3
Role

4 5
Sync. Sync.
Task Method
7 6
8
Role

9 10 11
Async. Async. Terminating
Task Method event
13
12
ã SAP AG 1999

n (1) (11) Event creator fills event container using container macros; no binding.
n (2) Binding between triggering event and workflow containers. This binding is essential.
n (3) (8) Binding between workflow container and role container for setting the role input parameters.
This binding is essential. (This only applies if the role was entered in the step definition. In the case
of a default role in the task definition, the parameters are supplied from the work item container.)
n (4) (7) (9) (13) Binding between workflow container and task container (work item container) for
setting the input and reading the output parameters of the task. For this binding, it is irrelevant
whether the underlying task is synchronous or asynchronous. The workflow builder generates a
proposal for this binding in the step definition.
n (5) (6) (10) Binding between task and method containers. For synchronous tasks, there is a binding
for both the import and export parameters (5) and (6); for asynchronous tasks, only for import
parameters (10). If this binding is not defined in the respective task, the task container is copied to
the method container at runtime.
n (12) Binding between event and task containers. This binding is necessary if the event contains data
that was not previously contained in the task container (for example, with events from create
methods).

(C) SAP AG BC610 4-10


Alternative Binding - Idea

l Binding between structures and scalar values


l Binding between multiple-line and single-line values
l Programming via function module with fixed interface
l Can be defined for all bindings

ã SAP AG 1999

n Required with binding for BAPI methods, for example, since BAPIs generally work with structures
while container definitions cannot contain any structures (e.g. binding between workflow and single-
step task).
n Function module entries in the binding editor via the "alternative binding" context menu.

(C) SAP AG BC610 4-11


Alternative Binding - Example

Step 21
TS20000203 ABAP Dictionary
WS20000102 KNA1.CreateFromData Structure
Workflow Container Task container BAPIKNA101

Name BAPIKNA101-NAME PiAddress BAPIKNA101 NAME

FirstName BAPIKNA101-... ... FIRST_NAME

Street BAPIKNA101-... Return BAPIRETURN STREET

City BAPIKNA101-CITY CITY

Language BAPIKNA101-LANGU LANGUAGE

...

Function
Function module
module
VSSF_DATAFLOW_WS20000084
VSSF_DATAFLOW_WS20000084

ã SAP AG 1999

n Example in step 21 of the multistep task WS20000102 (creating a customer via web form): The
workflow container only contains scalar values, which must be grouped together for BAPI method
KNA1.CreateFromData for structure BAPIKNA101.

This is mapped in function module VSSF_DATAFLOW_WS20000084. The scalar values from the
workflow container here are written to the appropriate structure fields of the PiAddress variables
using the container macros SWC_GET_ELEMENT and SWC_SET_ELEMEMT.

(C) SAP AG BC610 4-12


Alternative Binding - Function Module Interface

l Interface
function prog_binding
importing dataflow like swabindef-dataflow
tablescalled_container structure swcont
calling_container structure swcont

Binding

‘E’ = Export

‘I’ = Import

calling_container called_container

ã SAP AG 1999

n The DATAFLOW variable can only accept the values 'E' (export, in other words binding from the
Calling_Container to the Called_Container) and 'I' (import, in other words binding from the
Called_Container to the Calling_Container).
n The FM must not trigger exceptions.
n The FM must not trigger commits or rollbacks.

(C) SAP AG BC610 4-13


Starting Tasks

l Via the step definition within a multistep task


l Via the workflow development environment
l Via the System menu
l Via the API of the work item manager
l Via a triggering event of the task

ã SAP AG 1999

n Tasks are usually started via the step definition.


n For test purposes, tasks are started via the WF development environment. The current user must be a
possible agent of the task.
n Tasks can be started via the "Workflow" entry in the System menu from the application transaction,
if an appropriate link is provided by the application.
This link is already implemented in the following applications:
Accounting (FI and CO)
Logistics - Purchasing
Logistics - Master Data
Plant Maintenance
Quality Management
Service Management
n Starting tasks via the WIM API is discussed in the unit dealing with the runtime system.
n Starting tasks via an event is discussed in the unit dealing with the event manager.

(C) SAP AG BC610 4-14


Tasks: Unit Summary

l Explain the difference between a single-step task and


a multistep task
l Define and start both a single-step task and a
multistep task

ã SAP AG 1999

(C) SAP AG BC610 4-15


Exercises

Unit: Tasks
Topic: Single-Step Tasks

After completion of these exercises, you will be able to:


• Create new single-step tasks

You have either found or created all the object types that you
want to use in your business process with the associated attributes
and methods in the Business Object Builder. Now you want to
create single-step tasks based on the object methods that you can
use later in your workflow definition.

Note: All tasks are based on the object type ZMARA##A.

1-1 Create a new standard task for displaying a material master.


1-1-1 Create the task Z##MatDisp with the method Display. Define the task as a
general task. Specify both a work item text and a task description. Output
the material number in both texts.
1-1-2 Test the task by starting it via the workflow development environment.

1-2 Create a new standard task for changing a material master.


1-2-1 Create the task Z##MatEdit with the method Change. Define the task as a
general task. Specify a work item text, a text for latest end and completion,
and a task description. In addition to the material number, also output the
number and name of the plant for this material in all texts.
1-2-2 As this task is asynchronous, you must define at least one terminating event.
Use the event BasicMaterialChanged. In this case, the event does not require
a binding definition.

1-2-3 Test the task in two steps. Start the task in the first step as usual, but do not
change the field ‘basic material’. Instead, initiate the transaction again. Now
view the instance linkages from the work item display.
1-2-4 In the second step, change the field ‘basic material’ and search again for the
instance linkages.

(C) SAP AG BC610 4-16


1-2-5 Check the event trace to ensure that the terminating event really was
triggered.
1-3 Create a new standard task for displaying a material master from a particular view.
1-3-1 Create the task Z##MatDispV with the method DisplayView. Define the
task as a general task. Specify both a work item text and a task description.
Output the material number in both texts.
1-3-2 Define view "K" (corresponds to "Basic data 1") as the default value for the
parameter for controlling the view called for the material.
1-3-3 Test the task by starting it via the workflow development environment.

(C) SAP AG BC610 4-17


Unit: Tasks
Section: Multistep Tasks

After completion of these exercises, you will be able to:


• Create new multistep tasks

You have either found or created the single-step tasks that represent the
steps in your business process. Now you want to incorporate these single-
step tasks into a workflow definition.

Note: If not specified otherwise, the workflow initiator is always to


be the agent responsible for a step. Agent assignment via role
resolution is dealt with in the next unit.
Note: Each time a new step is inserted, you should check, save,
activate, and test your workflow definition again.

2-1 Define a workflow with a triggering event.


2-1-1 Create the workflow template Z##MSIPROC1 for changing a material
master. Define the input parameters required for this workflow. Define
OldMaterialChanged as triggering event for your workflow. Implement the
binding between the triggering event and the workflow and activate the
event linkage.
2-1-2 Incorporate the single-step task Z##MatDisp into your workflow definition.
2-1-3 Check, save, and activate your workflow definition.
Test your workflow with your material by starting it from the workflow
development environment.
2-1-4 Add the single-step task Z##MatEdit to your workflow definition as a new
first step. Define the workflow initiator as the message recipient for
completed processing.

2-1-5 This step is to have deadline monitoring. Activate deadline monitoring for
the latest end. This is to be triggered if processing of the step is not finished
after 5 minutes. Define the workflow initiator as the message recipient if the
latest end is missed.

(C) SAP AG BC610 4-18


2-1-6 For the display step, also define a secondary method, which displays all
change documents belonging to the current material in a separate session.
2-1-7 Check, save, activate and test your workflow again. Check whether, after
the “Edit” step, you have the notification of completion in your Business
Workplace.
2-2 Optional extensions: Create and change a second workflow.
2-2-1 Copy your first workflow template Z##MSIPROC1 to the new workflow
template Z##MSIPROC2.
2-2-2 Change the message recipient for completion for the "Edit" step. The
manager of the workflow initiator is now to receive the notification of
completion.

Note: Use the role AC00000168 to determine the manager of a


specific user. Read the documentation on this role in order to define
the binding from the workflow to the role container correctly.

2-2-3 Define another input parameter LatestEndDate for your workflow. This
parameter is used to determine the latest end for the ”Edit” step.
2-2-4 Define another input parameter MaterialView for your workflow. This
parameter is used to control the view in the display step of the process.
Define view "K" as the default for this parameter.
2-2-5 Define DeadlineTest as another triggering event for your new workflow.
Define the binding between the event parameters and the input parameters
of the workflow. Activate the event linkage.
2-2-6 The latest end for the ”Edit” step should be on the date determined via
LatestEndDate, five minutes after the current time. Ensure in your
workflow definition that this parameter cannot contain a deadline in the
past.
2-2-7 In the display step, replace the original task Z##MatDisp with the task
Z##MatDispV Supply the step parameter for controlling the display view
with the value of the MaterialView parameter from the workflow container.
2-2-8 Check, save, activate and test your new workflow both by starting it from
the development environment and by triggering the new triggering event
explicitly.
2-3 Optional extensions: Alternative binding
2-3-1 Create a function module Z##_BIND_WF_TO_DISPLAY_STEP for an
alternative binding between the workflow container and the task container
of the display step.

Note: You only require one binding from the workflow to the task
container of task Z##MatDispV.

2-3-2 Enter your new function module as an alternative binding for the display
step in your workflow definition Z##MSIPROC2.

(C) SAP AG BC610 4-19


(C) SAP AG BC610 4-20
Solutions

Unit: Tasks
Topic: Single-Step Tasks

1-1 Create a new standard task for displaying a material master.

Solution:
TS30900005 – Z00MatDisp

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools > Tasks/Task
groups > Create

1-2 Create a new standard task for changing a material master.

Solution:
TS3090006 – Z00MatEdit

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools > Tasks/Task
groups > Create

1-3 Create a new standard task for displaying a material master from a particular view.

Solution:
TS98000008 – Z00MatDispV

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools > Tasks/Task
groups > Create

(C) SAP AG BC610 4-21


Unit: Tasks
Section: Multistep Tasks

After completion of these exercises, you will be able to:


• Create new multistep tasks

You have either found or created the single-step tasks that represent the
steps in your business process. Now you want to incorporate these single-
step tasks into a workflow definition.

2-1 Define a workflow with a triggering event.


Solution:
WS96000011 – Z00MSIPROC1

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools > Tasks/Task
groups > Create

2-2 Optional extensions: Create and change a second workflow.


Solution:
WS96000012 – Z00MSIPROC2

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools > Tasks/Task
groups > Copy

2-3 Optional extensions: Alternative Binding


Solution:
Z##_BIND_WF_TO_DISPLAY_STEP

Path (via SAP Easy Access):

§ To create the function module


Tools > ABAP Workbench > Development > Function Builder

§ To incorporate the function module in the step definition


Tools > SAP Business Workflow > Development > Definition tools > Tasks/Task groups
> Change

(C) SAP AG BC610 4-22


Function module Z00_BIND_WF_TO_DISPLAY_STEP

FUNCTION Z00_BIND_WF_TO_DISPLAY_STEP.
*"----------------------------------------------------------------------
*"*"Local interface:
*" 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_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.
ENDIF.
ENDFUNCTION.

(C) SAP AG BC610 4-23


Roles

Contents:
l Determining agents via role function modules

ã SAP AG 1999

(C) SAP AG BC610 5-1


Roles: Unit Objectives

At the conclusion of this unit, you will be able to:

l Define and use a role via a role function module


l Implement a role function module

ã SAP AG 1999

(C) SAP AG BC610 5-2


Roles: Overview Diagram

Person Position/job Org. unit


Organization
Role Task

Processes WF definition Step

Attributes Events Methods


Business
objects
Object

ã SAP AG 1999

(C) SAP AG BC610 5-3


Role Resolution

l Evaluation using organization model


n Superior of...
Head of organizational unit
Departmental secretary
l Evaluation using master data
n Person responsible for material
Customer service employee
l Evaluation using Customizing data
n Accounting clerk
Person responsible for release

ã SAP AG 1999

n Roles are used to restrict or define more closely the number of recipients according to business
considerations.
n Benefits:
Ÿ dynamic restriction of the number of possible agents
Ÿ actual organizational plan does not need to be known
Ÿ agents determined according to current conditions (role resolution at runtime)
n The definition of a role contains
Ÿ the specification of the rules for role resolution (–> function module), and
Ÿ the specification of the runtime-dependent role parameters required for role resolution.
n Role definition, use of roles and role resolution using the role "Superior of…." as an example.
n The roles "Manager" and "sap_org_unit" are supplied by SAP.

(C) SAP AG BC610 5-4


Addressing via Function Modules

l Role function modules can be used for any evaluations


l Role function modules must be written by the customer
l Interface
function role_fm
tables actor_tab structure swhactor
ac_container structure swcont
exceptions nobody_found
l Container contains the parameters defined for the role

ã SAP AG 1999

n The role container must be filled with a binding. If the role is used in a step, data can be transferred
from the workflow container. If the role is used as the default role of the task, data can be transferred
from the task container.
n The function module must have the interface outlined above.

(C) SAP AG BC610 5-5


Structure of a Role Function Module

include <CNTN01>.

l Read role parameters function swx_dli_read_for_role.


*”------------------------------------------------------
from role container *”
*”
TABLES
ACTOR_TAB STRUCTURE SWHACTOR
*” AC_CONTAINER STRUCTURE SWCONT
l Evaluate internal *”
*"
EXCEPTIONS
NOBODY_FOUND
*”------------------------------------------------------
application data for data:
dli_name like soobjinfi1-obj_name,
agent determination dli_entries like sodlienti1 occurs 0 with header line.

clear actor_tab. refresh actor_tab.


l Return agents found swc_get_element ac_container 'DLI_NAME' dli_name.
or call function 'SO_DLI_READ_API1'
exporting dli_name = dli_name

l Trigger exception tables


exceptions
dli_entries = dli_entries
others = 99.

nobody_found if sy-subrc ne 0. raise nobody_found. endif.

loop at dli_entries.
where member_typ eq space.
actor_tab-otype = 'US'.
actor_tab-objid = dli_entries-member-nam.
append actor_tab.
endloop.

if actor_tab[] is initial. raise nobody_found. endif.

endfunction.

ã SAP AG 1999

n The actual function module SWX_DLI_READ_FOR_ROLE is more extensive - this is only an


extract. The function module is used for agent determination on the basis of a distribution list.
n The result of a role resolution does not necessarily have to be a user - it can also be any
organizational object (for example, an organizational unit, a position, etc).

(C) SAP AG BC610 5-6


Resolution of Addressing

l First level:
Task profile

l Second level:
Determination of the agent responsible or
default role of task
l Third level:
Removal of excluded agents

ã SAP AG 1999

n The next level above may only contain one further restriction of the level below. Therefore, if the
first level is missing because the task profile was not maintained, agents cannot be found in the
subsequent levels.
n Unlike Emails, the work items derived from the tasks are not delivered as copies. Instead, precisely
one work item exists for all recipients who only have one view of it.
n The explicit definition of possible agents in the task definition can be replaced by the classification
as a "general task". In this case, all users known in the system can process the task.
n If a role is specified both in the step definition and in the task definition, the role in the step
definition overrides the default role from the task definition.
n Users that are not a possible agents of the task can never see the WI, even if they are agents
responsible because of a role resolution.
n The default role of a task is also evaluated if the agent determination via a role in the step definition
ends without a result, and the flag "cancel if role resolution has no result" is not set for this role.

(C) SAP AG BC610 5-7


Roles: Unit Summary

l Define and use a role defined via a role function


module
l Implement a role function module

ã SAP AG 1999

(C) SAP AG BC610 5-8


Exercises

Unit: Roles
Topic: Role Definition and Implementation

After completion of these exercises, you will be able to:


• Create role definitions
• Create a role function module

The flow of the business process is now stored in the workflow


definition. You now want to assign the individual dialog steps
based on the current data of the object to be processed to the
correct recipients.

1-1 Create a new role Z##MatDispAc using a role function module.


1-1-1 Create a role function module Z##_MM_MGR_OR_USER_GET. This
function module returns the “manager of” the initiator of the workflow as
agent if the material type of the material entered has the value ROH (raw).
Otherwise the initiator is returned.
Note: Use the function module from role AC00000168 to determine
the manager of a specific user. Read the documentation on this role
in order to provide the role container correctly with the input data.

1-1-2 Now define the role using the new function module. Define the parameters
for this role according to the implementation of your function module.
Note: The role parameters are defined via the role container.
Note: The workflow initiator can be defined with reference either to
field WFSYST-INITIATOR or to RHOBJECTS-OBJECT.

1-1-3 Use the newly created role for the agent assignment of the “display” step in
your workflow Z##MSIPROC2.

1-1-4 Check, activate and test your workflow Z##MSIPROC2 again.

(C) SAP AG BC610 5-9


Solutions

Unit: Roles
Topic: Role Definition and Implementation

1-1 Create a new role Z##MatDispAc using a role function module.

Solution:
AC30900129 – Z00MatDispAc
Function module Z00_MM_MGR_OR_USER_GET
Organizational structure
O 00003100 Plant Chicago
----- S 50014947 Project Leader Engineering
----- P 00010810 Kimberley Hughes
----- US WF-BC-MGR Kimberley Hughes
----- S 50011158 Electrical Engineer
----- P 00010812 Caroline Douglas
----- US WF-BC-CLERK Caroline Douglas

Path: (via SAP Easy Access)

§ For the role


Tools > SAP Business Workflow > Development > Definition tools > Standard roles >
Create

§ For the function module


Tools > ABAP Workbench > Development > Function Builder

§ For the organizational structure


Tools > SAP Business Workflow > Development > Definition tools > Organizational
Management > Organizational plan > Display

FUNCTION Z00_MM_MGR_OR_USER_GET.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" ACTOR_TAB STRUCTURE SWHACTOR

(C) SAP AG BC610 5-10


*" AC_CONTAINER STRUCTURE SWCONT
*" EXCEPTIONS
*" NOBODY_FOUND
*"----------------------------------------------------------------------

DATA: MATERIAL_TYPE LIKE MARA-MTART. " type of changed material


DATA: WF_INITIATOR LIKE SWHACTOR. " workflow initiator
DATA: COUNTER TYPE I.

REFRESH ACTOR_TAB. CLEAR ACTOR_TAB.

* get type of material under consideration


SWC_GET_ELEMENT AC_CONTAINER 'MaterialType' MATERIAL_TYPE.
SWC_GET_ELEMENT AC_CONTAINER 'WorkflowInitiator' WF_INITIATOR.

CASE MATERIAL_TYPE.
WHEN 'ROH'. " get manager of wf_initiator from role
SWC_SET_ELEMENT AC_CONTAINER 'ORG_OBJECT' WF_INITIATOR.
CALL FUNCTION 'SWX_GET_MANAGER'
TABLES
ACTOR_TAB = ACTOR_TAB
AC_CONTAINER = AC_CONTAINER
EXCEPTIONS
NOBODY_FOUND = 1.
IF SY-SUBRC NE 0.
RAISE NOBODY_FOUND.
ENDIF.
WHEN OTHERS.
ACTOR_TAB = WF_INITIATOR.
APPEND ACTOR_TAB.
ENDCASE.

* check if we have found any agents at all


DESCRIBE TABLE ACTOR_TAB LINES COUNTER.
IF COUNTER = 0.
RAISE NOBODY_FOUND.
ENDIF.

ENDFUNCTION.

(C) SAP AG BC610 5-11


Event Definition and Implementation:

Contents:
l Event Manager
l Triggering events explicitly
l Receiving events

ã SAP AG 1999

(C) SAP AG BC610 6-1


Event Definition and Implementation: Unit
Objectives

At the conclusion of this unit, you will be able to:

l Explain the basic concepts of the event manager


l Trigger an event explicitly by programming

l Evaluate and receive an event

ã SAP AG 1999

(C) SAP AG BC610 6-2


Event Definition and Implementation: Overview

Person Position/job Org. unit


Organization
Role Task

Processes WF definition Step

Attributes Events Methods


Business
objects
Object

ã SAP AG 1999

(C) SAP AG BC610 6-3


Events: Motivation

l Shift of complexity
l Greater flexibility
l Easier to extend and integrate
l Greater transparency

ã SAP AG 1999

n The complexity and management of general information are shifted from the applications to a central
component. The information on possible linkages is no longer in the applications.
n Linkages can be easily activated and deactivated at runtime.
n New linkages can be easily integrated without changing the source code of the application. External
components can also be connected.
n The transparency of the entire system is enhanced by disclosing general information.
n Examples of applications include:
Ÿ Starting workflows from the application (flexible linkage)
Ÿ Terminating steps with updating (integration)
Ÿ Waiting for concurrent actions (integration, transparency)

(C) SAP AG BC610 6-4


Event Linkage: Basic Concepts

l Publish and subscribe


l ECA paradigm
l Static or dynamic evaluation
l Time-independent
l Linkage mode sequential-dependent

ã SAP AG 1999

n Linkages are entered according to the principle of "publish and subscribe", meaning that the creator
publishes the event without considering possible receivers. The number of receivers makes no
difference for the creator.
Interested receivers have to "subscribe" with the event manager (EM).
n Linkages are evaluated by the EM according to the ECA paradigm. The event is triggered (E), the
linkage tables are checked and, if necessary, check function modules are called (C), and finally the
receivers found are notified (A).
In accordance with the object-oriented approach for the creators, a hierarchical evaluation of the
linkage is implemented.
n By means of the check and receiver type determination function modules, an option exists for a
dynamic evaluation of the linkage.
n Triggered events are evaluated immediately, meaning the receiver is called immediately. The events
are not stored temporarily.
n The event is only triggered by an SAP Commit (ABAP keyword COMMIT WORK); an implicit
database commit is not sufficient. Triggering does not take place after a ROLLBACK WORK.
n Event linkages from the workflow that have errors are deactivated automatically when an error is
discovered. In addition, a mail is sent to the system administrator for workflow.

(C) SAP AG BC610 6-5


Transactional RFC Basic Design

l Dependent on explicit COMMIT WORK


l New login
l Error handling via separate log

ã SAP AG 1999

n Without an explicit commit work, the events "do not take place" (transactional property).
n A new login is carried out for the event receivers with each destination (RFC property).
n The transactional RFC (tRFC) log can be read via transaction SM58.

(C) SAP AG BC610 6-6


Events: Creator and Receiver Context

Application 1 (Creator) Event Manager Application 2 (Receiver)

FB swe_event_create Evaluation of
linkage tables

Call receiver
type FM

Call
check FM
Commit Work

Call
receiver FM

Creator context Receiver context

FMs provided by event FMs provided by


manager receiver
ã SAP AG 1999

n The receiver type FM and check FM run in the creator's context in order to avoid superfluous tRFCs.

(C) SAP AG BC610 6-7


Events: Type Linkage Table

l Linkage between triggering object type and receiving object


type
l Maintenance either explicit via view maintenance or via
function modules
l Transport of 'Enabled' flag only on request

ã SAP AG 1999

n An entry in the type linkage table is always required if a receiver is to be notified. Maintenance takes
place either explicitly or internally via FMs. The latter is always the case if task-related linkages are
entered (for example, for triggering or terminating events of tasks). When making entries within the
task definition, the linkage has to be activated explicitly.
The table entries can be transported, but the transport is usually carried out without the 'Enabled'
flag. Therefore the linkages usually have to be activated explicitly in the target system.
n If the 'Enabled' flag is explicitly to be transported, this is possible via the general transport
connection of the generated view maintenance.
n All linkages are client-specific.
n Type linkages for triggering events are entered by the workflow definition system when the linkage
is activated in the task definition, if no check or receiver type function modules are used. If at least
one such function module is required, the linkage must always be entered manually (as part of
Customizing for the respective workflow).
n Type linkages for terminating events are entered automatically by the workflow runtime system
when the associated work item is created, if no check or receiver type function modules are used. If
at least one such function module is required, the linkage must always be entered manually (as part
of Customizing for the respective workflow).

(C) SAP AG BC610 6-8


Events: Instance Linkage Table

l Linkage between triggering object instance and receiving


object instance
l Display explicit via workflow development environment or
via work item display
l Maintenance only implicit via function modules
l No transport

ã SAP AG 1999

n The instance linkage table is only evaluated if the associated type linkage is active and not global.
Maintenance only takes place via function modules, the corresponding WF-related entries (for
example, for terminating events of a step) are entered and deleted automatically by the WF runtime
system.
The table entries are never transported.
n All linkages are client-specific.

(C) SAP AG BC610 6-9


Event Manager - Processing Logic

l Search for all active type linkages


l Evaluate dynamic receiver determination
l If global linkage:
n Call receiver FM
n Call check FM
l Otherwise:
n Search for all instance linkages
n Call check FM for each instance linkage
n Call receiver FM for each instance linkage

ã SAP AG 1999

(C) SAP AG BC610 6-10


Events: Event Trace

l All triggered events logged


l Activate, deactivate and display via workflow
development environment
l Entries do not specify behavior of receiver
l The event trace function should be deactivated in the
live system

ã SAP AG 1999

n All triggered events are entered, irrespective of whether and how many receivers were found. A
separate entry is made for each receiver.
Errors in the check and receiver type function modules are also logged.
n Internally, the trace is regarded as an additional receiver which is always triggered. It is independent
of the commit behavior of other (explicit) receivers.
n Updating and writing the trace is time consuming because a separate tRFC is triggered. For this
reason, the trace should be deactivated in live systems (see note 46358).
n You can restrict the writing of the trace to selected object types or events.

(C) SAP AG BC610 6-11


Events: Defining / Triggering

l Define events in the Business Object Builder


l Trigger event
n Implicitly via generic tools, for example
change documents or
status management or
message control
n Explicitly via function module
SWE_EVENT_CREATE or
SWE_EVENT_CREATE_IN_UPD_TASK or
SWE_EVENT_CREATE_FOR_UPD_TASK

ã SAP AG 1999

n Events must be defined in the Business Object Builder for the relevant object type. Not all defined
events must be triggered, but all triggered events must be defined.
n Implicit triggering via change documents does not require any ABAP coding. Customizing activities
for the triggering application are necessary instead.
Explicit triggering via function modules requires the source code of the application to be changed or
extended.
Important: the function module SWE_EVENT_CREATE can trigger exceptions. If these are not
caught by the triggering application, a runtime error occurs.
n The triggering modules do not execute COMMIT WORKs themselves. It is the task of the triggering
application to issue a COMMIT WORK at the right time.
n Events with user-defined parameters must always be triggered explicitly if these parameters are to be
set.
n SWE_EVENT_CREATE - event triggered immediately. SWE_EVENT_CREATE_IN_UPD_TASK
- as SWE_EVENT_CREATE, but defined as updating function module.
SWE_EVENT_CREATE_FOR_UPD_TASK - as SWE_EVENT_CREATE, but is required if the
object that triggers the event is not generated via the application until the update.
n Explicit triggering via function modules usually takes place in customer systems by the customer
programming an existing user exit.

(C) SAP AG BC610 6-12


Triggering an Event Explicitly

l Fill event container with include <CNTN01>.


data: begin of asset_key,
event parameters company_code like anla-bukrs,
asset_no like anla-anln1,
sub_number like anla-anln2,
l Compose object key for end of asset_key.
data: object_key like sweinstcou-objkey.
triggering object swc_container evt_container.
* Write parameters into event container
l Call swe_event_create swc_set_element evt_container 'flag_equi_aendern' 'X'.
* Compose object key
l FM call error handing
asset_key-company_code = '0001'.
asset_key-asset_no = '000000123456'.
asset_key-sub_number = '0100'.
object_key = asset_key.
l Trigger event with * Trigger the event
explicit commit work call function 'SWE_EVENT_CREATE'
exporting
objtype = 'BUS1022'
objkey = object_key
event = 'changed'
tables
event_container = evt_container
exceptions
others = 01.
if sy-subrc ne 0.
“ do your own error handling
endif.
* start tRFC processing
commit work.

ã SAP AG 1999

n Important:
If the event is triggered in a user exit, a COMMIT WORK usually must not be programmed here,
since this would destroy the commit logic of the application.

(C) SAP AG BC610 6-13


Inheritance: Triggering - Supertype

Object type Event Receiver type


BUS1001 Created WS00005711
Z_BUS1001 Created WS97000313

include <CNTN01>.

data: object_key like sweinstcou-objkey.


swc_container evt_container.
object_key = '000012345678'.
* Trigger the event
call function 'SWE_EVENT_CREATE'
exporting
objtype = 'BUS1001'
objkey = object_key
event = 'created'
tables
event_container = evt_container
exceptions
others = 01.
* start tRFC processing
commit work.

ã SAP AG 1999

n The event is only triggered for the supertype.

(C) SAP AG BC610 6-14


Inheritance: Triggering - Subtype

Object type Event Receiver type


BUS1001 Created WS00005711
Z_BUS1001 Created WS97000313

include <CNTN01>.
data: object_key like sweinstcou-objkey.
swc_container evt_container.
object_key = '000012345678'.
* Trigger the event
call function 'SWE_EVENT_CREATE'
exporting
objtype = 'Z_BUS1001'
objkey = object_key
event = 'created'
tables
event_container = evt_container
exceptions
others = 01.

* start tRFC processing


commit work.

ã SAP AG 1999

n The event is triggered for the subobject type as well as for all supertypes for which the event is
defined.

(C) SAP AG BC610 6-15


Receiver Function Module

l Interface
function receiver_fm
importing objtype like swetypecou-objtype
objkey like sweinstcou-objkey
eventlike swetypecou-event
rectype like swetypecou-rectype
tables event_container structure swcont
l Process in separate context

ã SAP AG 1999

n If possible, the function module should not trigger any exceptions, since these are only recorded
directly in the tRFC log. If this occurs, workflow receiver function modules send an error message to
the system administrator for workflow.
n Example of a function module: SWW_WI_START_VIA_EVENT
n In the case of propagated events, the default parameter _EVT_OBJTYPE contains the triggering
object type (that is, the subtype), while the interface parameter OBJTYPE contains the propagated
object type (that is, the supertype).
This also applies to the check and receiver type function modules.
n _EVT_OBJECT always contains the triggering object type!

(C) SAP AG BC610 6-16


Check Function Module

l Test for relevance for receiver


l Interface
function check_fm
importing objtypelike swetypecou-objtype
objkey like sweinstcou-objkey
eventlike swetypecou-event
rectype like swetypecou-rectype
tables event_container structure swcont
exceptions others
l Process in creator context

ã SAP AG 1999

n The check FM cannot commit (nor rollback).


n Exceptions are recorded in the event trace.

(C) SAP AG BC610 6-17


Implementing a Check Function Module

function check_object_type_idocappl.
l Read event parameters *************************************************
* importing objtype like swetypecou-objtype
from event container *
*
objkey
event
like
like
sweinstcou-objkey
swetypecou-event
* rectype like swetypecou-rectype
l Check condition * tables event_container structure
* exceptions check_failed
swcont
*************************************************

l Trigger an exception or include <CNTN01>.

end function module constants:


c_otype_appl like swetypecou-objtype value 'IDOCAPPL',
c_evt_otype like swcont-element value '_EVT_OBJTYPE'.

data: initiating_otype like swetypecou-objtype.


* Implementation of check fm
* Read originating objtype from event container
swc_get_element event_container
c_evt_otype initiating_otype .
* check if initiating objtype is desired one
if initiating_otype <> c_otype_appl.
raise check_failed.
endif.
endfunction.

ã SAP AG 1999

n Other typical contents of a check function module


§ Default parameter query (for example, date, time, object type)
§ Object attribute query using the macro SWC_GET_PROPERTY
§ Write additional values to the event container.
n If the event is triggered before the object data is written to the database, the object attributes are not
yet available for querying, since the database is accessed when the attributes are evaluated by the
Business Object Builder.
This may occur, for example, if the event is triggered implicitly when generating the object (that is,
via change documents, status management, etc.) and the object is not generated until later in
updating.

(C) SAP AG BC610 6-18


Receiver Type Function Module

l Dynamic determination of receiver type dependent on event data


l Interface
function rectypeget_fm
importing objtype like swetypecou-objtype
objkey like sweinstcou-objkey
event like swetypecou-event
rectype like swetypecou-rectype
tablesevent_container structure swcont
l Process in creator context

ã SAP AG 1999

n The receiver type FM cannot commit (nor rollback).


n The table entry "receiver type" (rectype) from the type linkage table can be used as an input
parameter generic_rectype for the function module.
n Exceptions are recorded in the event trace.

(C) SAP AG BC610 6-19


Implementing a Receiver Type Function Module

function cvwf_event_rec_dokst_get.
********************************************************
* importing objtype like swetypecou-objtype
l Read event parameters *
*
objkey
event
like sweinstcou-objkey
like swetypecou-event
* generic_rectype like swetypecou-rectype
from event container * exporting rectype like swetypecou-rectype
* tables event_container structure swcont
* exceptions no_rectype
l Determine the receiver ********************************************************
include <CNTN01>.
type on the basis of data: l_dokst like draw-dokst.
application-specific data: begin of drawkey,
dokar like draw-dokar,
doknr like draw-doknr,
settings dokvr like draw-dokvr,
doktl like draw-doktl,
l Trigger an exception or
end of drawkey.
* Implementation of receiver type fm
end function module * Read document status from event container
swc_get_element event_container
'DOCUMENTSTATUS' l_dokst.
drawkey = objkey.

* read receiver type from table tdws


select single * from tdws
where dokar = drawkey-dokar and
dokst = l_dokst.
If sy-subscr ne 0.
Raise no_rectype.
Else.
Rectype = tdws-otype.
Rectype+2 = tdws-objid.
Endif.
endfunction.

ã SAP AG 1999

n If the event is triggered before the object data is written to the database, the object attributes are not
available yet for querying, since the database is accessed when the attributes are evaluated by the
Business Object Builder.
This may occur, for example, if the event is triggered implicitly when generating the object (that is,
via change documents, status management, etc.) and the object is not generated until later in
updating.

(C) SAP AG BC610 6-20


Event Definition and Implementation:
Unit Objectives

l Explain the basic concepts of the event manager

l Explain how an event can be triggered explicitly by


programming
l Explain how an event can be evaluated and received

ã SAP AG 1999

(C) SAP AG BC610 6-21


Event Definition and Implementation Exercises

Unit: Event Definition and Implementation


Section: Event Manager

After completion of these exercises, you will be able to:


• Display the event linkage tables
• Display the event trace
• Simulate an event

You have completed your workflow definition and assigned the


individual dialog steps to the correct agents. Now you want to check
whether your workflow is started correctly via events.

1-1 Recall the effect of the entries in the type linkage table.
1-1-1 Ensure that your two workflows are correctly linked to the event
OldMaterialChanged of your object type.
1-1-2 Simulate the event OldMaterialChanged. Check the output of the simulation
tool.
1-1-3 Check the event trace for entries for the event DeadlineTest for your object
type that you had triggered in an earlier task.

(C) SAP AG BC610 6-22


Unit: Event Definition and Implementation
Section: Implementing an Event

After completion of these exercises, you will be able to:


• Trigger an event explicitly (by programming)
• Create a check and receiver type function module

The event linkage to your workflow definitions is created correctly. Now


you want to start workflows via an event that is triggered explicitly in an
ABAP program you have written.

2-1 Trigger an event explicitly.


2-1-1 Create a report Z##EVTCR that calls the function module
SWE_EVENT_CREATE, in order to trigger the event DeadlineTest for
your object type.
2-1-2 Check whether your workflow is triggered irrespective of whether you are
the last person to change the material or not.

2-2 Create a check function module to filter out irrelevant events.


2-2-1 Create a check function module
Z##_CHECK_MATERIAL_CHANGEDBY. This function module is
intended to ensure that your workflow is only started if you trigger the event
for one of "your" materials (T-BBC##, T-FBC##) and if you are the last
person who changed the material.
Check in the function module whether the transferred material number
represents one of your materials and whether the object attribute ChangedBy
has your login ID as a value. If this is not the case, an exception should be
triggered.
2-2-2 Insert the check function module into the existing linkages from the event
OldMaterialChanged of your object type to your two workflow definitions
Z##MSIPROC1 and Z##MSIPROC2.
2-2-3 Now check whether your workflow is only triggered when you are the last
person to change the material.

(C) SAP AG BC610 6-23


2-3 Optional extensions: Create a receiver type function module to decide depending on
runtime data which of your two workflow definitions is to be started.
2-3-1 Create a receiver type function module
Z##_RECTYPE_DETERMINE_MATTYPE. This function module
determines the workflow to be started based on the material type of the
triggering object. If the object attribute MaterialType has the value ‘FERT’
(finished), the workflow Z##MSIPROC1 should be started, otherwise
Z##MSIPROC2.
2-3-2 Change the type linkage table again so that the workflow to be started is
now determined via the receiver type function module for the event
OldMaterialChanged of your object type.
2-3-3 Now check whether the workflow associated with the material type of the
triggering material is started.

(C) SAP AG BC610 6-24


Event Definition and Implementation Solutions

Unit: Event Definition and Implementation


Topic: Event Manager

1-1 Recall the effect of the entries in the type linkage table.
1-1-1 Ensure that your two workflows are correctly linked to the event
OldMaterialChanged of your object type.

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools >
Events > Event links > Type linkages
1-1-2 Simulate the event OldMaterialChanged. Check the output of the simulation
tool.

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Utilities > Events >
Simulate event
1-1-3 Check the event log for entries for the event DeadlineTest for your object
type, that you had triggered in an earlier task.

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Utilities > Events >
Event log > Display event log

(C) SAP AG BC610 6-25


Unit: Event Definition and Implementation
Section: Implementing an Event

After completion of these exercises, you will be able to:


• Trigger an event explicitly (by programming)
• Create a check and receiver type function module

The event linkage to your workflow definitions is created correctly. Now


you want to start workflows via an event that is triggered explicitly in an
ABAP program you have written.

2-1 Trigger an event explicitly.

Solution:
Z00EVTCR

Path (via SAP Easy Access):


Tools > ABAP Workbench > Development > ABAP Editor
*&----------------------------------------------------------------------
*& Explicit triggering of Z00MARA.DEADLINETEST
*&----------------------------------------------------------------------

REPORT Z00EVTCR.

INCLUDE <CNTN01>. " include container macros

DATA: OBJKEY LIKE SWEINSTCOU-OBJKEY,


EVENTID LIKE SWEDUMEVID-EVTID.
DATA: EVENT_CONTAINER LIKE SWCONT OCCURS 0 WITH HEADER LINE.

PARAMETERS:
OBJTYPE LIKE SWETYPECOU-OBJTYPE DEFAULT 'Z00MARA',
MATERIAL LIKE MARA-MATNR,
EVENT LIKE SWETYPECOU-EVENT DEFAULT
'DEADLINETEST',
END_DATE LIKE SYST-DATUM DEFAULT SPACE.

OBJKEY = MATERIAL.
(C) SAP AG BC610 6-26
* write parameter into event container
IF EVENT EQ 'DEADLINETEST' AND END_DATE EQ SPACE.
END_DATE = SY-DATUM + 1.
ENDIF.
SWC_SET_ELEMENT EVENT_CONTAINER 'LatestEndDate' END_DATE.

CALL FUNCTION 'SWE_EVENT_CREATE'


EXPORTING
OBJTYPE = OBJTYPE
OBJKEY = OBJKEY
EVENT = EVENT
IMPORTING
EVENT_ID = EVENTID
TABLES
EVENT_CONTAINER = EVENT_CONTAINER
EXCEPTIONS
OBJTYPE_NOT_FOUND = 1.

IF SY-SUBRC NE 0.
WRITE : / 'Object type', OBJTYPE, 'unknown'.
ELSE.
IF EVENTID NE 0.
WRITE : / 'At least one receiver found'.
COMMIT WORK.
ELSE.
WRITE : / 'No receivers found'.
ENDIF.
ENDIF.

2-2 Create a check function module to filter out irrelevant events.

Solution:
Z00_CHECK_MATERIAL_CHANGEDBY

Path (via SAP Easy Access):

§ For the function module


Tools > ABAP Workbench > Development > Function Builder

§ For the linkage between event and workflow


Tools > SAP Business Workflow > Development > Definition tools > Events > Event links
> Type linkages

FUNCTION Z00_CHECK_MATERIAL_CHANGEDBY
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(OBJTYPE) LIKE SWETYPECOU-OBJTYPE

(C) SAP AG BC610 6-27


*" VALUE(OBJKEY) LIKE SWEINSTCOU-OBJKEY
*" VALUE(EVENT) LIKE SWETYPECOU-EVENT
*" VALUE(RECTYPE) LIKE SWETYPECOU-RECTYPE
*" TABLES
*" EVENT_CONTAINER STRUCTURE SWCONT
*" EXCEPTIONS
*" OBJECT_NOT_FOUND
*" INVALID_USER
*" INVALID_MATERIAL
*"----------------------------------------------------------------------
* This check fm checks, if the user who triggered the event (USER) is
* the same person who is related to the sample material and if
* the material changed is really one of my sample materials.

CONSTANTS:
MY_SAMPLE_MATERIAL_ROH LIKE MARA-MATNR VALUE '200-110',
MY_SAMPLE_MATERIAL_FERT LIKE MARA-MATNR VALUE '200-101',
MY_SAMPLE_MATERIAL_HALBLIKE MARA-MATNR VALUE '200-100',
MY_OWN_USER LIKE SY-UNAME VALUE
'WF-BC-CLERK'.

DATA:
MY_SAMPLE_MATERIALS LIKE MARA-MATNR OCCURS 3 WITH HEADER LINE.
DATA: OBJECT TYPE SWC_OBJECT.
DATA: CHANGER LIKE MARA-AENAM,
USER_ACT LIKE SWHACTOR,
USER LIKE SY-UNAME.

* build int table with my sample materials


MOVE MY_SAMPLE_MATERIAL_ROH TO MY_SAMPLE_MATERIALS.
APPEND MY_SAMPLE_MATERIALS.
MOVE MY_SAMPLE_MATERIAL_HALB TO MY_SAMPLE_MATERIALS.
APPEND MY_SAMPLE_MATERIALS.
MOVE MY_SAMPLE_MATERIAL_FERT TO MY_SAMPLE_MATERIALS.
APPEND MY_SAMPLE_MATERIALS.

* check, if the triggering material is one of my materials


READ TABLE MY_SAMPLE_MATERIALS WITH KEY = OBJKEY.
IF SY-SUBRC NE 0.
RAISE INVALID_MATERIAL.
ENDIF.

* create the material object for later attribute access


SWC_CREATE_OBJECT OBJECT OBJTYPE OBJKEY.
IF SY-SUBRC NE 0.
RAISE OBJECT_NOT_FOUND.
ENDIF.

(C) SAP AG BC610 6-28


* read attribute 'ChangedBy' from material object
SWC_GET_PROPERTY OBJECT 'ChangedBy' CHANGER.
IF SY-SUBRC NE 0.
RAISE OBJECT_NOT_FOUND.
ENDIF.

* check if my sample user and material changer are identical


IF CHANGER NE MY_OWN_USER.
RAISE INVALID_USER.
ENDIF.
ENDFUNCTION.

2-3 Optional extensions: Create a receiver type function module to decide depending
on runtime data which of your two workflow definitions is to be started.

Solution:
Z00_RECTYPE_DETERMINE_MATTYPE

Path (via SAP Easy Access):

§ For the function module


Tools > ABAP Workbench > Development > Function Builder

§ For the linkage between event and workflow


Tools > SAP Business Workflow > Development > Definition tools > Events > Event links
> Type linkages

FUNCTION Z00_RECTYPE_DETERMINE_MATTYPE.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(OBJTYPE) LIKE SWETYPECOU-OBJTYPE
*" VALUE(OBJKEY) LIKE SWEINSTCOU-OBJKEY
*" VALUE(EVENT) LIKE SWETYPECOU-EVENT
*" VALUE(GENERIC_RECTYPE) LIKE SWETYPECOU-RECTYPE
*" EXPORTING
*" VALUE(RECTYPE) LIKE SWEINSTCOU-RECTYPE
*" TABLES

(C) SAP AG BC610 6-29


*" EVENT_CONTAINER STRUCTURE SWCONT
*" EXCEPTIONS
*" OBJECT_NOT_FOUND
*"----------------------------------------------------------------------
* This receiver type fm determins the process to be started by the
* material type

DATA: OBJECT TYPE SWC_OBJECT.


DATA: MTYPE LIKE MARA-MTART.

* create the material object


SWC_CREATE_OBJECT OBJECT OBJTYPE OBJKEY.
IF SY-SUBRC NE 0.
RAISE OBJECT_NOT_FOUND.
ENDIF.

* check material typ and set receiver type depending on value


SWC_GET_PROPERTY OBJECT 'MaterialType' MTYPE.
IF MTYPE EQ 'FERT'.
RECTYPE = 'WS96000011'. " Z00MSIPROC1
ELSE.
RECTYPE = 'WS96000012'. " Z00MSIPROC2
ENDIF.
ENDFUNCTION.

(C) SAP AG BC610 6-30


Workflow Runtime System

Contents:

l Components and architecture


l Work items
l Deadline monitoring and error handling
l Administration functions
l Performance

ã SAP AG 1999

(C) SAP AG BC610 7-1


Workflow Runtime System: Unit Objectives

At the conclusion of this unit, you will be able to:

l Explain the components of the runtime system and


how they interact in a workflow
l Generate and execute work items via the work item
manager API
l Explain deadline monitoring and error handling and
use the options provided to control deadline
monitoring

ã SAP AG 1999

(C) SAP AG BC610 7-2


Workflow Runtime System: Unit Objectives (2)

At the conclusion of this unit, you will be able to:

l Use the administration functions of the runtime


system
l Avoid modeling and configuration settings that
unnecessarily slow down the runtime system

ã SAP AG 1999

(C) SAP AG BC610 7-3


WF Runtime System: (A)synchronous Case -
Create

Definition
Task Workflow
BOR System
definition definition

create
Object Work item Workflow Runtime
manager manager manager System

Application Event
manager

ã SAP AG 1999

(C) SAP AG BC610 7-4


WF Runtime System: (A)synchronous Case
- Execute

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager manager manager System

Application Event
manager

ã SAP AG 1999

(C) SAP AG BC610 7-5


WF Runtime System: Asynchronous Case - Invoke

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager manager manager System

invoke

Application Event
manager

ã SAP AG 1999

(C) SAP AG BC610 7-6


WF Runtime System: Asynchronous Case - Result

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager manager manager System

invoke

Application Event
result manager

ã SAP AG 1999

(C) SAP AG BC610 7-7


WF Runtime System: Asynchronous Case - Event

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager manager manager System

invoke result

Application Event
result manager

ã SAP AG 1999

(C) SAP AG BC610 7-8


WF Runtime System: Asynchronous Case -
Callback

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager manager result manager System

invoke result

Application Event
result manager

ã SAP AG 1999

(C) SAP AG BC610 7-9


WF Runtime System: Synchronous Case - Invoke

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager manager manager System

invoke

Application Event
manager

ã SAP AG 1999

(C) SAP AG BC610 7-10


WF Runtime System: Synchronous Case - Result

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager manager manager System

invoke result

Application Event
manager

ã SAP AG 1999

(C) SAP AG BC610 7-11


WF Runtime System: Synchronous Case - Result 2

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager result manager manager System

invoke result

Application Event
manager

ã SAP AG 1999

(C) SAP AG BC610 7-12


WF Runtime System: Synchronous Case - Callback

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager result manager result manager System

invoke result

Application Event
manager

ã SAP AG 1999

(C) SAP AG BC610 7-13


Workflow Runtime System - Overview

Definition
Task Workflow
BOR System
definition definition

execute create
Object Work item Workflow Runtime
manager result manager result manager System

invoke result result

Application Event
result manager

ã SAP AG 1999

n The workflow manager (WFM) reads the workflow definition and the step definition and creates one
work item (WI) per step using the work item manager (WIM). The WFM is then finished.
n The WIM manages the WI and triggers the application via the object manager (OM).
n If the underlying method is synchronous, the result and the export parameters of the method are
returned to the WIM via the OM.
If the underlying method is asynchronous, the result of the method is returned to the WIM via an
event that is triggered in the event manager (EM). This event must be defined as a "terminating
event" for the step.
n After receiving the return parameters, the WIM checks the return code and, if successful, returns the
data to the WFM.
n This loop continues until the end of the workflow is reached.
n Event creator, conditions, process control and container operations are executed locally in the WFM
without a work item being created.

(C) SAP AG BC610 7-14


Workflow Manager: Tasks

l Control execution of the workflow definition


l Data transfer between individual steps of a workflow
definition
l Provide initial data for a workflow
l Deadline calculation for steps in a workflow
definition
l Role resolution on step level
l Execution of container operations, process control
and event creators
l Evaluation of conditions

ã SAP AG 1999

(C) SAP AG BC610 7-15


Workflow Manager: Workflow Log

l Record the workflow execution process:


n Work items: when created/processed/done
n Process: branches, loops, start/end of forks, subworkflows
l Status of workflow execution
l Log operations on the workflow:
n Stop/continue process
n Abort work item/whole process
l Entry point for troubleshooting

ã SAP AG 1999

(C) SAP AG BC610 7-16


Work Item Manager: Tasks

l Monitor processing of individual steps in a workflow


definition
l Deadline monitoring of individual steps in a workflow
definition
l Agent assignment for individual steps in a workflow
definition
l Logging all activities executed on a step in a
workflow definition
l Default role resolution

ã SAP AG 1999

n A work item (WI) is created for every activity in a workflow.


n Processing is monitored using the individual WI statuses. The processing sequence is determined by
the statuses and the possible transitions. The WI is also locked at the same time via the individual
statuses while it is being processed.
n Deadline monitoring is performed via the background job SWWDHEX and the report RSWWDHEX
(see below).
n For a precise evaluation of the agent assignment, see the unit on "Roles".
An agent who is not a possible agent for the task underlying the WI never sees the WI in the
Business Workplace, even if he or she was the result of a role resolution.
n All of the user's activities are logged with the WI, with the result that each WI has a complete
processing history.
n During execution, all secondary methods are started in addition to the methods from the task.
Secondary methods run in a separate mode.
n Before the method from the task is executed, the before methods are executed in an arbitrary
sequence. After the main method has been executed, the after methods are executed in an arbitrary
sequence.

(C) SAP AG BC610 7-17


Work Item Types

l A - Work queue work item


l B - Background work item
l C - Container anchor work item
l D - Deadline monitoring work item
l E - Wait step work item
l F - Workflow work item
l W - Dialog work item

ã SAP AG 1999

n A work queue work item is a "logical unit" of objects and tasks that are to be executed together. Both
objects and tasks can be different.
n A background work item is used to execute tasks that do not require dialog. They are automatically
executed by the WF system and do not appear in the Business Workplace.
n A container anchor work item serves as logical link joining several associated objects. It corresponds
to the assignment table from WF21. It does not possess its own semantics and never appears in the
Business Workplace.
n A deadline monitoring work item is created by default when the WF system detects that a deadline
has been missed.
n A wait step work item receives events generated externally or by other WIs. A wait step has no
processing logic and does not appear in the Business Workplace.
n A workflow work item represents a workflow to be processed, the definition of which is then
processed via the WFM.
n A dialog work item represents a step in a WF that is to be executed by a user.

(C) SAP AG BC610 7-18


Work Item Language

l Each work item has a language


l The language of a work item is derived from the
language of the superordinate workflow
l The workflow language can be set during creation
l The language of an event can be set as a default
parameter

ã SAP AG 1999

n The WI language determines the language of the short text and the status texts. The language of the
long text is determined by the user's logon language.
n When a workflow is started via an event, the language of the event is passed on to the workflow.
n Under "Personal workflow settings" in the Business Workplace, the user can set whether his or her
work items in the Business Workplace always appear in the logon language. In this case, all WI texts
are put into the user's current logon language when the Business Workplace is compiled. This setting
reduces performance considerably, however.

(C) SAP AG BC610 7-19


Work Item Status

l WAITING - waiting
l READY - ready
l SELECTED - reserved
l STARTED - in process
l COMMITTED - executed
l ERROR - error
l COMPLETED - completed
l CANCELLED - logically deleted

ã SAP AG 1999

n A WI has the status WAITING if its requested start has not yet been reached. With this status it
cannot be seen by any user.
n A WI with status READY appears in the Business Workplace of the recipients. WIs running in the
background with this status are executed immediately.
n The status SELECTED only applies to dialog and work queue work items. It means that the WI has
been reserved by one of the recipients and therefore disappears from the Business Workplace of the
others.
n When the underlying method has been started but not yet completed, the WI has the status
STARTED. The WI remains in the Business Workplace of the current agent.
n If the underlying method has been executed successfully but the WI has to be set to 'done' manually,
it has the status COMMITTED.
n If, during execution of the method, a return code not modeled in the related workflow was returned
or irreparable damage occurred in the WIM, the WI is assigned the status ERROR.
n If processing of the WI has been completed successfully, it is assigned the status COMPLETED.
n If the WI is no longer required within the flow logic of the workflow, it is assigned the status
CANCELLED.

(C) SAP AG BC610 7-20


Status Transitions

Cancelled Error

Waiting Ready Started Completed

Selected Committed

ã SAP AG 1999

n Not all work item types can assume all statuses (for example, SELECTED only for dialog and work
queue work items, COMMITTED only for dialog work items).
n The start statuses are WAITING or READY.
n The end statuses are CANCELLED or COMPLETED.
n The change from one status into another always happens implicitly on the basis of an executed
activity (for example, "reserve" in the Business Workplace).

(C) SAP AG BC610 7-21


Status Transitions - Dialog Work Item

Canceled Error

Waiting Ready Started Completed

Selected Committed

ã SAP AG 1999

(C) SAP AG BC610 7-22


Status Transitions - Background Work Item

Canceled Error

Waiting Ready Started Completed

Selected Committed

ã SAP AG 1999

(C) SAP AG BC610 7-23


WIM API - Function Modules

l Create a work item


SWW_WI_CREATE(_SIMPLE)
l Execute a work item
SWW_WI_WITHOUT_WLC_EXECUTE
l Start a work item (create and execute immediately)
SWW_WI_START(_SIMPLE)
l General API functions
Function group SWWA

ã SAP AG 1999

n Important: the function modules in the function group SWWA are not officially released externally,
meaning that their interface may change. However, all efforts are being made to keep enhancements
upwardly compatible.
Only the function module WORKITEM_ARCHIVE_OBJECT for archiving a work item is officially
released.
n When a work item is started or created, the caller must first fill the task container with the input
parameters of the task according to the task definition.
The caller must also incorporate error handling measures if the WI cannot be created or started.
n Before a work item is executed, the caller must check whether all the prerequisites for execution
have been fulfilled (for example, is the current user permitted to execute the WI).
n All administration function modules (SWW_WI_ADMIN_*), for example, are in the SWWA
function group.
n All function modules of the SAP WAPI interface can also be used (SAP_WAPI_*). These are in
function groups SWRC and SWRR.

(C) SAP AG BC610 7-24


SAP WAPI Function Modules

l Function group SWRC


Function modules for processing the worklist of a user
l Function group SWRI
Function modules for selecting work items according to
various criteria (e.g. for reporting and analysis)
l Function group SWRR
Function modules for starting a workflow or for triggering
an event

ã SAP AG 1999

n SAP WAPI is an SAP-specific API based on the interface definitions of the Workflow Management
Coalition.
n The SAP WAPI function modules call again the function modules internally from SWWA. The
functionality is the same, but the interface is different.
n If possible, the function modules from SWRI should be used instead of direct table access (e.g. to
tables SWWWIDEADL and SWWWIRET) for work item selection within analysis and reporting.

(C) SAP AG BC610 7-25


WIM API - Tables

l Released header data


View SWWVPUBLIC
l Deadline data
Table SWWWIDEADL
l Return data from method execution
Table SWWWIRET
l Objects in work item container
Table SWW_CONTOB
l Non-objects in work item container
Table SWW_CONT

ã SAP AG 1999

n The entire header data is located in the table SWWWIHEAD. The view SWWVPUBLIC contains
the elements that are available for general selection and do not represent internal administrative data
of the WIM.
n Changes to the structure of the SWWVPUBLIC view are only upward compatible. The structures of
the remaining tables and others are not guaranteed. If data of a known work item is to be read, the
function modules SWW_WI_HEADER_READ, SWW_WI_DEADLINES_READ and
SWW_WI_RETURN_READ from the SWWA function group should be used (or as of 4.5A,
SWW_WIS_*_READ, if the data from several work items is to be imported).
n If the container of a known work item is to be read, the function module
SWW_WI_CONTAINER_READ in the function group SWWA should always be used.
n Non-objects in the work item container include scalar values (char, integer) and structures.
n Changes to work items must never be made by direct table changes, but always via the function
modules in the function group SWWA.

(C) SAP AG BC610 7-26


Object References

l Runtime handles (RHs)


n Used in BOR
n Valid during runtime of creating program
l Persistent object references (PORs)
n Used in workflow
n Can be saved in the database

ã SAP AG 1999

n The BOR only recognizes RHs (for example, as a result of macro SWC_CREATE_OBJECT, as
input for method calls, and so on). An RH is only valid during the runtime of the creating program
and expires immediately afterwards.
n This is not sufficient for the workflow, since there may be program changes or several days between
the individual steps. For this reason, there must also be a persistent presentation. This presentation is
visible, for example, when you look at the work item container.
n All BOR macros expect an RH; all workflow FMs expect PORs.
n The workflow ensures correct conversion automatically. An explicit conversion is always necessary
when you write your own FMs that are called on the interface between the workflow system and the
BOR (for example, check FMs in the event manager).
The explicit conversion takes place using the macros SWC_CONTAINER_TO_RUNTIME and
SWC_CONTAINER_TO_PERSISENT from the include <cntn01>.

(C) SAP AG BC610 7-27


Object References in the Workflow Context

30/31/40A 40B

Event Manager
ReceiverTypeFM Runtime handle
CheckFM

Persistent
RFC
object reference
WF
BOR/Application Runtime handle

Persistent
WF object reference

BOR/Application Runtime handle

Persistent
WF object reference

BOR/Application Runtime handle


WF

ã SAP AG 1999

n User-controlled conversion is always necessary when the caller requires a different type of
presentation than the current one.
n With every user-controlled conversion, the caller must ensure that a "re-conversion" takes place
afterwards, since the original presentation is expected again in the subsequent context.
n When a workflow is started directly via the API, the RHs created in the program using the BOR
macros must also be converted to PORs before SWW_WI_CREATE (or SWW_WI_START) is
called.

(C) SAP AG BC610 7-28


User-Defined Work Item Display

l Additional tab in the work item display


l Subscreen contains its own flow logic
l Subscreen communicates with superordinate work
item display

ã SAP AG 1999

n Process or step-specific data can be displayed on the additional tab.


n The user-defined tab is never visible in processing chains, since the object method underlying the
step is executed immediately.

(C) SAP AG BC610 7-29


Reference in the Step Definition

Enter your subscreen

ã SAP AG 1999

n The screen entered must be defined as a "subscreen".

(C) SAP AG BC610 7-30


Flow Logic of the Screen

l Initializing the data for PBO


l Status-dependent refreshing of the data for PBO (optional)
l Reaction to OK Code for PAI
n Either
Direct processing in the subscreen
n Or
Transfer of the OK code to the superordinate WI standard screen

ã SAP AG 1999

n The programming is carried out via macros from the <widisp> include. This include must be
included in the module pool.
n The online documentation contains complete documentation on the macro.

(C) SAP AG BC610 7-31


Initializing the Screen for PBO

Query the initial run

Set the title

Query the associated WI ID

Query the associated


application object

Read the attributes of the


associated application
object

ã SAP AG 1999

n The SAP_WAPI_* function modules implement the WfMC Interface 2 and are in the SWRC
function group.
n SAP_WAPI_GET_OBJECTS returns the leading object as a POR. A transformation to an RH must,
therefore, take place before the BOR macro is called by calling
SWC_OBJECT_FROM_PERSISTENT.
n To use the BOR macro, the include <cntn01> must be incorporated.

(C) SAP AG BC610 7-32


Reaction to OK Code for PAI

Query the OK code

Transfer the OK code to the


superordinate WI screen

Process the OK code


directly

Delete the OK code

ã SAP AG 1999

n The online documentation contains the complete list of IDs for transferring the OK codes.

(C) SAP AG BC610 7-33


Runtime Display

"Data for process" tab is


inserted for specific steps

Access to step-specific
object attributes

Access to functions in the


work item display

ã SAP AG 1999

n The "Data for process" is always displayed as the first tab.


n The "Resubmit approval" button is mapped to OK code 0002.
The "Add attachment" button is mapped to OK code 0018.
The "Display application" button is handled directly using the SHOW_FORM form.

(C) SAP AG BC610 7-34


Deadline Monitoring

l Monitoring four deadlines


n Requested start (resubmission)
n Latest start
n Requested end
n Latest end
l Monitoring all deadlines using a background job
n Either periodically on a regular basis
n Or only as required (default)

ã SAP AG 1999

n All deadlines are monitored using the background job SWWDHEX with job class A. The job calls
the report RSWWDHEX.
n You can choose between deadline monitoring on an individual or on a periodic basis. Individual
monitoring is active by default.
n With individual monitoring, the background job is rescheduled for the next deadline to be monitored
and is updated if a new deadline is entered for a WI that is sooner than any others. The background
job therefore, only runs if it is really needed.
Important: if the background job aborts for any reason, it must be rescheduled by starting the above
report.
n This procedure is not economical for monitoring a large number of deadlines. In this case, you
should switch to periodic deadline monitoring (for example, every three minutes).
n You can switch between the two monitoring types at any time via SWWA or using the report
RSWWDHIN.

(C) SAP AG BC610 7-35


Deadline Monitoring Inheritance

l Deadline data and monitoring activity inherited by


dependent work items from workflow
l Definition of monitoring activity for dependent work
item overwrites inheritance
l Check deadline data in dependent work item against
inherited deadlines

ã SAP AG 1999

n Inheritance only applies on creation of the subordinate work item. Subsequent changes to data in the
superordinate workflow are not passed on to existing dependent work items.
n Every change in the data in the dependent work item is checked against the superordinate workflow.
It is not possible to postpone beyond the inherited deadlines.

(C) SAP AG BC610 7-36


Deadline Monitoring - Special Situations

l Many deadlines
Switch from single case based to permanent
l Several instances of SWWDHEX
Delete all instances via job overview
Reschedule
l No instances of SWWDHEX
Check selection for job overview
Reschedule

ã SAP AG 1999

n SWWDHEX is rescheduled via transaction SWWB.


n When many deadlines are to be monitored, a conflict may arise with background job
SAP_REORG_JOBS. In this case, deadline monitoring should be suppressed while
SAP_REORG_JOBS is running.
n When displaying background jobs in the job overview, remember that this is a cross-client display.
You should therefore check whether the background jobs displayed are actually scheduled in the
current client.

(C) SAP AG BC610 7-37


Error Handling

Error situation Error correction

1
1 Correction
WI ERROR WI Error Restart
4
2 3
3 2
FI ERROR FI Error Restart

ã SAP AG 1999

n Error situation
1) The status of the work item changes to ERROR.
2) The error is propagated to the superordinate workflow.
3) The status of the superordinate workflow also changes to ERROR.
n Error correction
1) The work item is corrected (for example, by correcting the work item container).
2) A "restart after error" is executed on the superordinate workflow.
3) The superordinate workflow propagates the restart to the work item.
4) A "restart after error" is executed on the work item implicitly.
n When an error occurs, it is propagated "bottom up" to all superordinate workflows.
n To correct the error, the WI is first repaired locally.
n Then the workflow is restarted from the top down and all work items belonging to the workflow are
also restarted. The restart must always be performed at the highest level workflow, and never from
the WI with the error.
n Work items with errors should not be restarted with SM58 (prior to 4.0A), since steps already
executed may be executed a second time.
n All correction actions on work items should be performed with great caution to avoid side effects.

(C) SAP AG BC610 7-38


Behavior With Unmodeled Errors

Temporary error Non-temporary


error

Background STARTED status, ERROR status,


work items restart with send an
SWWERRE error mail to
Workflow
WF administrator
work items

STARTED status, ERROR status,


Dialog executed again WI remains in
work items by the user Business Workplace
of the user

ã SAP AG 1999

n Behavior with unmodeled errors


n The method definition determines whether an error is temporary or not.
n The background activities are monitored by the job RSWWERRE.
n The status of background work items and workflow work items changes to ERROR after the nth
unsuccessful execution.

(C) SAP AG BC610 7-39


Error Handling - Deadline Monitoring

SWWERRE SWWDHEX

Trigger Work item status Deadline data


Action Predefined action, Predefined or user-
trigger via tRFC defined action, trigger via
tRFC
Job Job class C, Job class A,
periodic job self scheduling job
Interval Configurable or
Configurable
dependent on deadlines

Authorization Normal authorization Check


check deactivated

Scheduling Customizing or Customizing or


auto-customizing auto-customizing

ã SAP AG 1999

n Neither job allows real-time control since background jobs that are running are not interrupted.

(C) SAP AG BC610 7-40


Work Item Manager: Logging

l Write temporary log entry for all user activities if


successful
l Write temporary log entry for all activities if errors
occur
l Write permanent log entry after explicit instruction

ã SAP AG 1999

n Initially, only temporary log entries are written to a buffer so that the commit logic of the caller is
not destroyed.
n A log entry is written for all activities that can be triggered by a user (including) via the user
interface, if successful (FM SWW_WI_LOG_WRITE_SUCCESS).
n A log entry is always written if an error occurs so that the call hierarchy can be traced to the point of
error (FM SWW_WI_LOG_WRITE_EXCEPTION).
n The function module SWW_WI_LOG_FLUSH must be called before the database commit, so that
the temporary log entries can be written from the buffer to the database.
n If work items are created via the WIM API (or, more generally, the work items are controlled via the
WIM API) and the commit is controlled by the creator (that is, the parameter DO_COMMIT was set
to SPACE), the creator must call the function module SWW_WI_LOG_FLUSH before commit
work. In all other cases, the call is performed by the workflow runtime system.

(C) SAP AG BC610 7-41


Work Item Administration

l Initiate waiting WIs


l Release reserved WIs
l Restart a WI after errors
l Logical deletion of a WI
l Explicit successful completion of a WI

ã SAP AG 1999

n All administrator FMs are checked with regard to authorization. They are used to process a WI in
exceptions.
Note: the necessary authorizations are contained in the authorization profile S_WF_WF_ADMIN.
n When a waiting WI is initiated, its status is changed from WAITING to READY. This function can
be executed if deadline monitoring is not running due to overloading of the background queue or an
error in the background system.
n The status of the WI is changed from SELECTED or STARTED to READY again. This function can
be used in order to make a WI that is blocked by an absentee visible for other recipients.
n When restarting after an error, the status of the WI is changed from ERROR to STARTED, the
underlying method may be executed automatically.
n Logical deletion changes the status of the WI to CANCELLED.
n The system administrator for WF can explicitly change the status of a WI to COMPLETED, but is
responsible for filling the container of the WI with the expected return parameters of the method
beforehand.

(C) SAP AG BC610 7-42


Work Item Manager: Asynchronous
Communication

l Required for transition from dialog to background


processing
l Use of transactional RFC (tRFC)
l Maintenance of logical destination
WORKFLOW_LOCAL _<Clnt> required

ã SAP AG 1999

n tRFC is a Basis component (CALL FUNCTION ... IN BACKGROUND TASK). The FM called is
triggered after the next SAP Commit (see unit on events).
n The logical destination WORKFLOW_LOCAL<Clnt> is maintained for the WF runtime system
within Customizing via the transaction SWUB. The user entered there must have all authorizations
and should therefore, for security reasons, be a background user.
Important: If the password of this user is changed within user administration, this change must also
be made in SWUB.
Important: The logical destination WORKFLOW_LOCAL<Clnt> cannot be maintained via the
transaction SM59.
n The tRFCs issued are logged until they are executed. If execution is successful, these entries are
deleted. If an error occurs during execution, this is also recorded in the log.
Only up to 3.1G: The log can be viewed via SM58. It is accessed with the name of the user who
called the tRFC. For the WF system, it is normally the user who is entered in the destination
WORKFLOW_LOCAL_<Clnt>.
n There is another access possibility from the workflow development environment via "RFC monitor".

(C) SAP AG BC610 7-43


Finding Work Items

l Selection report for finding work items


n ID
n Work item type
n Status
n Task
l Display and change work items of all types

ã SAP AG 1999

n After the work item has been selected, the users can change and/or process the work item if they are
assigned to the underlying task via the task profile and the work item is not already reserved by
another recipient.
n If the work item is not task-based (for example, wait steps, work queues, and so on), the user can
change and/or process it if it is not already reserved by another recipient.

(C) SAP AG BC610 7-44


Workflow Diagnosis Tool

l Access to workflow and work item debugging


n Verification of workflow Customizing
n Problem: Task not started
n Problem: Workflow hanging
n Test environment (special test tools)
l Context-sensitive diagnosis of workflow instances

ã SAP AG 1999

n Access either via Utilities in the workflow development environment or directly via the transaction
SWUD.
n All the tools and procedures that will be described in detail can be executed via this tool.
n Problems triggering events can also be investigated via this tool.

(C) SAP AG BC610 7-45


Work Item Debugging

l Workflow log evaluation


l Workflow trace evaluation

ã SAP AG 1999

n The workflow log is always written and cannot be switched off. It follows the database commit and
writes to the database.
n The workflow trace must be switched on explicitly. It is not dependent on the database commit and
writes to the file system of the application server.
n The workflow trace is helpful with regard to problems in background work items or binding.

(C) SAP AG BC610 7-46


Troubleshooting - Starting a Workflow

l Workflow does not start


n Check the Customizing settings
n Check event trace for initiator
n Check event linkage (exists and active)
n Check tRFC log under initiator's login
n Check tRFC log under user's login from
WORKFLOW_LOCAL_<Clnt>
n Check workflow definition (active version)

ã SAP AG 1999

n The consistency check for Customizing must be carried out before you first work with SAP Business
Workflow.
n Note: Linkages with errors are deactivated automatically and a mail is sent to the system
administrator for workflow.

(C) SAP AG BC610 7-47


Troubleshooting - Work Item Cannot Be Found

l Work item is not in the Business Workplace


n Check whether work item created correctly (see above)
n Search for work item via work item selection
n Check agent assignment via task profile and step definition
n Check role definition and/or role function module

ã SAP AG 1999

n The buffer for organizational assignments may have to be refreshed.

(C) SAP AG BC610 7-48


Troubleshooting - Work Item Not in End Status

l Work item cannot be completed


n Workflow log check
M Application or temporary error
n If background step, check via report RSWWERRE
n Check whether the system administrator for workflow has
received mail
n If asynchronous step, check event instance linkage
n Initiate test execution
n Check container contents

ã SAP AG 1999

n A breakpoint should be set in the method implementation before the "test execution".
n If the instance linkage table is filled correctly, the terminating event can also be triggered via the
workflow development environment for test purposes.

(C) SAP AG BC610 7-49


Troubleshooting - Workflow Hanging

l Work item completed but workflow not continuing


n Workflow log check
M Preceding step completed correctly
M Status transition implemented correctly
M No waiting for event in a parallel branch
M Work item for next step created correctly
n Check whether step task is locked against instantiation
n Check whether the system administrator for workflow has
received mail
n Search for created work item (see above)

ã SAP AG 1999

(C) SAP AG BC610 7-50


Archiving and Deleting Work Items

l Delete in test system via reports RSWWWIDE and


RSWWHIDE
l Delete in live system only via archiving object
WORKITEM

ã SAP AG 1999

n Reports RSWWWIDE and RSWWHIDE are only for internal purposes. The work items are deleted
from the database without further query or authority checks. They can be started via the
Administration menu in the workflow development environment.
These reports should always be called with the "display only" flag set first to check them. The actual
deletion should be executed via a background job.
n Workflow work items automatically delete their dependent work items as well.
n In a live system, the work items must be archived before they can be deleted (transaction SARA).
The contents of the archive file can then be deleted later.
n Archived work items can be read, but not restored for security reasons. The read program must be
written individually by the customer. An example program is supplied by SAP (RSWWARCR).
n Other archiving objects can also archive work items using the archive class WORKITEM. Work
items cannot, however, be deleted in this manner for reasons of data consistency.
n Container anchor work items should be deleted via the report RSWWCIDE.

(C) SAP AG BC610 7-51


Read Archived Work Items

l Read program RSWWARCR


n Sequential reading of the entire archive
n Template for own read programs
l Read program RSWWARCP
n Read a process for a particular object
n Workflow log formatting

ã SAP AG 1999

n RSWWARCR can be used as a template for user-defined programs. The user source code begins
after calling the function module SWW_WI_LIST_ARCHIVED_READ, which imports the whole
archive to internal tables. The tables contain all processes in a depth-first storage format.
n RSWWARCP is a special case of a self-written read program. It searches for the associated process
for a particular application object and restructures the workflow log for this process (as far as
possible).
n The archive data cannot be reloaded to the original WI tables, since the runtime system reuses the
WI numbers (i.e. data could be overwritten when reloaded).

(C) SAP AG BC610 7-52


Comparison Archiving - Deleting

Report RSWWWIDE Archiving object


WORKITEM
Possible in every status Only possible in COMPLETED
or CANCELLED status
Direct start without Authorization check via
authorization check transaction SARA
Direct deletion from Archiving and deleting
database in two separate steps
Execute in dialog or Execute in background
in background later
Log data not deleted Log data also
archived and deleted

ã SAP AG 1999

n WI data must never be deleted directly in tables, only via the function module SWW_WI_DELETE.
n Large amounts of data should always be deleted in the background.
n Report RSWIWADO can be used to determine if archiving or deletion are necessary.
n If only the workflow log is to be deleted, report RSWWHIDE can be used.

(C) SAP AG BC610 7-53


Improving Performance - tRFC

l Replace reading/calculating background methods


with virtual attributes
l No workflows that check input data in the first step
l No workflow starts via event from user written report
l Combine "smaller" background methods into
"larger" units
l Packaging of input data into smaller units

ã SAP AG 1999

n Packaging is particularly relevant if large quantities of data are imported into the system (for
example, with a batch input).
n A check function module can be implemented instead of a "check step" in the workflow when the
workflow is started via an event, for example.
n The WIM API can be used instead of an event if a workflow is started from a user-defined report that
is scheduled as a background job.
n A destination can be specified for each event receiver in the type linkage table. Specific events can
then be received on a specific application server (to keep the other application servers free, for
example).

(C) SAP AG BC610 7-54


Improving Performance - Business Workplace

l Detailed task assignment in the organization model


l Do not display deadline or grouping data in the
standard configuration
l Display work items in creation language rather than
logon language
l Allow buffering of organizational data
l Delete work items no longer required

ã SAP AG 1999

n General tasks should not be used if at all possible. If they are, a restrictive agent assignment should
be performed in the step definition.
n The following lead to subsequent selection if they are adopted in the standard configuration:
Ÿ Object _WI_OBJECT_ID
Ÿ Group _WI_GROUP_ID
Ÿ Task text WI_RHTEXT (if work item display in logon language)
Ÿ To do by (date) WI_LED
Ÿ To do by (time) WI_LET
n The buffering of organizational data can be controlled via the table T77S0.
Please refer to note 98407.

(C) SAP AG BC610 7-55


Workflow Runtime System: Unit Summary (1)

l Explain the components of the runtime system and


how they interact in a workflow
l Control the creation and execution of work items with
the work item manager API
l Explain deadline monitoring and error handling as
well as the options for controlling deadline
monitoring

ã SAP AG 1999

(C) SAP AG BC610 7-56


Workflow Runtime System: Unit Summary (2)

l Use the administration functions to correct a


workflow with errors, continue it, and archive it
once it is terminated.
l Name the modeling and configuration settings that
unnecessarily slow down the runtime system.

ã SAP AG 1999

(C) SAP AG BC610 7-57


Workflow Runtime System Exercises

Unit: Workflow Runtime System


Topic: Work Item Manager API

After completion of this exercise, you will be able to:


• Create a work item via the API of the work item manager

You want to start a workflow not via an event, but directly via the API
of the work item manager (for example for performance reasons).

1-1 Start a workflow via the work item manager API.


1-1-1 Create a report Z##START that starts your workflow Z##MSIPROC1 by
calling the API function module SWW_WI_START_SIMPLE .

(C) SAP AG BC610 7-58


Unit: Workflow Runtime System
Section: User-Defined Work Item Display

After completion of this exercise, you will be able to:


• Implement a subscreen for a user-defined work item display
• Incorporate a subscreen for a user-defined work item display in your
process.

You want to display process-specific data for the end user before the
work item is executed.

2-1 Optional extensions: Define a subscreen for a user-defined work item display.
2-1-1 Create a screen 0100 in your function group that displays the following
data from the material master:
+ Material number
+ Last person to change the material
+ Material type
+ Lab/office of the material.
The user is also to be able to display the material stock at the click of a
button

Note: The screen entered must be defined as a "subscreen". In this


case, the OK code does not have to be declared explicitly as a field
in the screen layout.
Note: The material stock can be displayed via transaction MMBE.

2-1-2 Change the display step in your process Z##MSIPROC1 in such a way
that a user-specific work item is displayed using the subscreen that you
implemented previously.

Note: If you have not implemented your own screen, you can use the
screen SAPLZ610 0100.
Note: To make the user-defined screen visible when it is displayed,
you must choose the “User view without ActiveX” for the “Work
item display” under “User-defined workflow settings”.

(C) SAP AG BC610 7-59


Unit: Workflow Runtime System
Section: Administrative Functions

After completion of these exercises, you will be able to:


• Execute administrative functions such as selecting or deleting work
items

Several workflows have been successfully executed. After a time, you


want to delete these workflow instances.
Some workflows seem to have been running for an unusually long time
without terminating and you require detailed information about these
workflow instances.

3-1 Search for the work items based on specific criteria.


3-1-1 Create a report Z##TODAY that lists all workflow instances started today
by a specific user. The list is to display the initiator, the status and the task
ID for each instance of this kind.
Note: The initiator is saved in the table SWW_CONT, and all other
data in the table SWWWIHEAD (or in view SWWVPUBLIC).

3-1-2 Using the report RSWWWIDE, delete all the work items you created on
the first day of the workshop.

Note: First execute the report with the flag “Display list only” set.
Only if the list contains exclusively your work items, remove the
flag for the second run of the report and actually delete the work
items.

Important: Once you have deleted the work items, they are lost
irretrievably.

3-2 Optional extensions


3-2-1 Create a report Z##WEEKL that lists all unterminated workflow
instances started more than a week ago. The list is to display the task ID,
the status and the creation date for each instance of this kind.

(C) SAP AG BC610 7-60


Workflow Runtime System - Solutions

Unit: Workflow Runtime System


Topic: Work Item Manager API

1-1 Start a workflow via the work item manager API.

Solution:
Z00START

Path (via SAP Easy Access):


Tools > ABAP Workbench > Development > ABAP Editor

REPORT Z00START .

INCLUDE <CNTN01>. " definition of container and object macros

PARAMETERS: OBJKEY LIKE MARA-MATNR DEFAULT '200-100'.

DATA:TASK LIKE SWWVPUBLIC-WI_RH_TASK VALUE 'WS96000011',


WI_ID LIKE SWWVPUBLIC-WI_ID,
OBJECT TYPE SWC_OBJECT.
DATA:AGENTS LIKE SWHACTOR OCCURS 0 WITH
HEADER LINE,
WI_CONTAINER LIKE SWCONT OCCURS 0 WITH HEADER
LINE.

* set the import parameter for flow Z00MSIPROC1


* first: create object reference (runtime handle)
SWC_CREATE_OBJECT OBJECT 'Z00MARA' OBJKEY.
* second: write reference to work item container using parameter def
SWC_SET_ELEMENT WI_CONTAINER 'MaterialMaster' OBJECT.
* third: convert references in container from runtime handle to
* persistent object reference
SWC_CONTAINER_TO_PERSISTENT WI_CONTAINER.

(C) SAP AG BC610 7-61


* start the workflow via the function API
CALL FUNCTION '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 " not
needed 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.
IF SY-SUBRC NE 0. " error message
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE. " success message
MESSAGE ID 'WZ' TYPE 'S' NUMBER '703' WITH WI_ID.
ENDIF.

(C) SAP AG BC610 7-62


Unit: Workflow Runtime System
Section: User-Defined Work Item Display

After completion of this exercise, you will be able to:


• Implement a subscreen for a user-defined work item display
• Incorporate a subscreen for a user-defined work item display in your
process.

You want to display process-specific data for the end user even before the
work item is executed.

2-1 Optional extensions: Define a subscreen for a user-defined work item display.
2-1-1 Create a screen 0100 in your function group.

Solution:
SAPLZ610 0100

Path (via SAP Easy Access):


Tools > ABAP Workbench > Development > User Interface > Screen
Painter
2-2-2 Change the display step in your process Z##MSIPROC1 in such a way that
a user-specific work item is displayed using the subscreen that you
implemented previously.

Solution:
WS96000011 – Z00MSIPROC1

Path (via SAP Easy Access):


Tools > SAP Business Workflow > Development > Definition tools >
Tasks/Task groups > Change

MODULE INIT_0100 OUTPUT.

(C) SAP AG BC610 7-63


*- ask frame dynpro if this is the first call of this subscreen...
SWL_WIDISP_GET_INIT INIT_D0100.

CHECK INIT_D0100 IS INITIAL.


INIT_D0100 = 'X'.

*- set a title heading this subscreen on the tabstrip control...


SWL_WIDISP_SET_TITLE 'Process data'.

*- ask frame dynpro for the ID of workitem in display...


CLEAR G_WI_ID.
SWL_WIDISP_GET_WI_ID G_WI_ID.

*- now we get the data to be displayed...


*- we want to show some data concerning the material, which is connected
* to the workitem as an object.
* therefore, we use a released interface to get the workitem's object.
CALL FUNCTION 'SAP_WAPI_GET_OBJECTS'
EXPORTING
WORKITEM_ID = G_WI_ID
IMPORTING
LEADING_OBJECT = G_MATERIAL.
* return_code =
* TABLES
* OBJECTS =
* MESSAGE_LINES =
* MESSAGE_STRUCT =.

*- from the material object we can get the data we want to show
CLEAR G_OBJECT. CLEAR MARA.
MOVE G_MATERIAL-OBJECT_ID TO G_OBJECT.
SELECT SINGLE * FROM MARA
WHERE MATNR = G_OBJECT-OBJKEY.
* we do not use a possible attribute access here, because the attribute
* 'BasicMaterialNumber' does not exist and 'Laboratorty' is defined
* as an object based attribute, so we'd need to implement another
* attribute access for object type T024L
* clear g_runtime.
* swc_object_from_persistent g_object g_runtime.
* swc_get_property g_runtime 'Material' mara-matnr.
* swc_get_property g_runtime 'ChangedBy' mara-aenam.
* swc_get_property g_runtime 'MaterialType' mara-mtart.
* swc_get_property g_runtime 'OldMaterial' mara-bismt.
* swc_get_property g_runtime 'BasicMaterialNumber' mara-wrkst.
* swc_get_property g_runtime 'Laboratory' mara-labor.
ENDMODULE. " INIT_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT.


(C) SAP AG BC610 7-64
DATA: OKAY LIKE SY-UCOMM.
SWC_CONTAINER L_CONTAINER.

SWL_WIDISP_GET_OKCODE OKAY.
CASE OKAY.
*- we implement just one function of our own...
WHEN 'DISM'. " this is the only OK code, ignore anything else
*- we want to show the material, which is related to the work item
* therefore, we use a released interface to get the workitem's object.
IF G_MATERIAL IS INITIAL.
CALL FUNCTION 'SAP_WAPI_GET_OBJECTS'
EXPORTING
WORKITEM_ID = G_WI_ID
IMPORTING
LEADING_OBJEC = G_MATERIAL.
* return_code =
* TABLES
* OBJECTS =
* MESSAGE_LINES =
* MESSAGE_STRUCT =.
ENDIF.
*- we show the material stock using ta mmbe
CLEAR G_OBJECT.
MOVE G_MATERIAL-OBJECT_ID TO G_OBJECT.
SET PARAMETER ID 'MAT' FIELD G_OBJECT-OBJKEY.
CALL TRANSACTION 'MMBE' AND SKIP FIRST SCREEN.
*- now it's more secure to clear the okcode to the frame dynpro,
* because it must not be handled again overthere...
SWL_WIDISP_CLEAR_OKCODE.
ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

(C) SAP AG BC610 7-65


Unit: Workflow Runtime System
Section: Administrative Functions

After completion of these exercises, you will be able to:


• Execute administrative functions such as selecting or deleting work
items

Several workflows have been successfully executed. After a time, you


want to delete these workflow instances.
Some workflows seem to have been running for an unusually long time
without terminating and you require detailed information about these
workflow instances.

3-1 Search for the work items based on specific criteria.

3-1-1 Create a report Z##TODAY that lists all workflow instances started today
by a specific user.

Solution:
Z00TODAY
View Z00VHEACON

Path (via SAP Easy Access):


§ For the report
Tools > ABAP Workbench > Development > ABAP Editor
§ For the view
Tools > ABAP Workbench > Development > ABAP Dictionary
3-1-2 Using the report RSWWWIDE, delete all the work items you created on the
first day of the workshop.

Path (via SAP Easy Access):


Tools > ABAP Workbench > Development > ABAP Editor

(C) SAP AG BC610 7-66


REPORT Z00TODAY LINE-SIZE 512 .
INCLUDE RSWWINCL.
TABLES: Z00VHEACON. " view over SWWWIHEAD and _WF_INITIATOR
PARAMETERS: USER LIKE SY-UNAME DEFAULT SY-UNAME.
DATA: CAND_WIS LIKE Z00VHEACON OCCURS 0 WITH HEADER LINE,
INITIATOR LIKE SWHACTOR,
LINE_NO LIKE SY-TFILL.

* determine intitiator
INITIATOR-OTYPE = 'US'.
INITIATOR-OBJID = USER.
* search list of candidate wis
IF USER NE SPACE. " search for flows of this user
WRITE: / 'Number of flows started today by user ', USER, ':'.
SELECT * FROM Z00VHEACON INTO TABLE CAND_WIS
WHERE WI_CD EQ SY-DATUM AND
WI_CHCKWI EQ SPACE AND " top level flows only
VALUE EQ INITIATOR.
ELSE. " search for flows independent of user
WRITE: / 'Number of flows started today by all users :'.
SELECT * FROM Z00VHEACON INTO TABLE CAND_WIS
WHERE WI_CD EQ SY-DATUM AND
WI_CHCKWI EQ SPACE. " top level flows only
ENDIF.

DESCRIBE TABLE CAND_WIS LINES LINE_NO.


WRITE: LINE_NO.
SORT CAND_WIS BY WI_RH_TASK VALUE.
* display result list
LOOP AT CAND_WIS.
WRITE : / CAND_WIS-WI_ID, CAND_WIS-WI_RH_TASK, CAND_WIS-WI_STAT,
CAND_WIS-WI_CD, CAND_WIS-VALUE.
ENDLOOP.

(C) SAP AG BC610 7-67


3-2 Optional extensions
3-2-1 Create a report Z##WEEKL that lists all unterminated workflow instances
started more than a week ago.

Solution:
Z00WEEKL

Path (via SAP Easy Access):


Tools > ABAP Workbench > Development > ABAP Editor

REPORT Z00WEEKL LINE-SIZE 512.


INCLUDE RSWWINCL.
TABLES: Z00VHEACON. " public view on work item header data
PARAMETERS: TASK LIKE SWWWIHEAD-WI_RH_TASK,
DAYS_AGO LIKE SWWWIHEAD-RETRY_CNT DEFAULT
'07'.
DATA: CAND_WIS LIKE Z00VHEACON OCCURS 0 WITH
HEADER LINE.
DATA: START_DATE LIKE SY-DATUM.
WRITE : / 'List of flows started longer than ', DAYS_AGO, ' days ago:'.
* determine start date for candidate work flows
START_DATE = SY-DATUM - DAYS_AGO.
* search list of candidate flows
IF TASK NE SPACE. " search for a specific task
SELECT * FROM Z00VHEACON INTO TABLE CAND_WIS
WHERE WI_RH_TASK EQ TASK AND
WI_CD <= START_DATE AND
WI_CHCKWI EQ SPACE AND " top-level flows only
( WI_STAT NE WI_STATUS_COMPLETED AND
WI_STAT NE WI_STATUS_CANCELLED ) .
ELSE. " search for all tasks
SELECT * FROM Z00VHEACON INTO TABLE CAND_WIS
WHERE WI_CD <= START_DATE AND
WI_CHCKWI EQ SPACE AND " top-level flows only
( WI_STAT NE WI_STATUS_COMPLETED AND
WI_STAT NE WI_STATUS_CANCELLED ) .
ENDIF.

* display result list


LOOP AT CAND_WIS.
WRITE : / CAND_WIS-WI_ID, CAND_WIS-WI_RH_TASK, CAND_WIS-WI_STAT,
CAND_WIS-WI_CD, CAND_WIS-VALUE.
ENDLOOP.

(C) SAP AG BC610 7-68


Workflow Information System

Contents:
l Architecture
l Customer-specific analyses

ã SAP AG 1999

(C) SAP AG BC610 8-1


Workflow Information System: Unit Objectives

At the conclusion of this unit, you will be able to:

l Explain the Workflow Information System architecture


l Implement a customer-specific analysis in the
Workflow Information System

ã SAP AG 1999

(C) SAP AG BC610 8-2


Architecture

Information Structures

LIS

Update rules

Characs. Time base Key figures Field catalogs Characs. Time base Key figures

LIS
Background job SAP report event User exit
"AA"

Data retrieval Data retrieval


SAP Communication structure Customer
SAP fields Customer fields

Generic data Customer-specific data


Such as: Such as:
Workflow Runtime Material
Frequency
Duration System Quantity
Agent Price

ã SAP AG 1999

n The communication structure and LIS event form the LIS inbound interface for external data.
n Data retrieval is carried out via batch job RMCADATA that triggers the LIS event and also fills the
communication structure. This background job must be scheduled explicitly. In scheduling, ensure
that no data is transferred twice when setting the evaluation period.
n The LIS generates a function group for the LIS event. The event is actually triggered by calling a
particular function module in this function group and transferring the internal tables previously
filled.
n The communication structures (for generic data), data retrieval program and function group are
supplied by SAP.
n A user exit is provided to allow customers to fill their own fields in the communication structure.
n Field catalogs, information structures and update rules are defined in LIS Customizing (see online
documentation or documentation on the course LO930: Logistics Information System)
n The Workflow Information System can be accessed via Reporting in the workflow development
environment or directly via the transaction MCA1.

(C) SAP AG BC610 8-3


Architecture - Customer Extensions

Information Structures

LIS

Update rules

Characs. Time base Key figures Field catalogs Characs. Time base Key figures

LIS
Background job SAP report event User exit
"AA"

Data retrieval Data retrieval


SAP Communication structure Customer
SAP fields Customer fields

Generic data Customer-specific data


Such as: Such as:
Workflow Runtime Material
Frequency
Duration System Quantity
Agent Price

ã SAP AG 1999

n Application number 20 is reserved for WIS extensions within LIS.

(C) SAP AG BC610 8-4


Customer Analysis Steps

l Extension of communication structure


l Programming and activating user exit
l Creating field catalogs
l Creating info structures
l Creating update rules

ã SAP AG 1999

n These five steps must be performed in order.

(C) SAP AG BC610 8-5


Extension of Communication Structure

l Determine the customer-specific data for the


evaluation
l Extend the SAP communication structure to
include the relevant data fields

ã SAP AG 1999

n Customer-specific data is generally process-specific container elements or attributes of objects in the


container.
n The extension is implemented technically by means of "append structures" in the ABAP dictionary.
The extension may only be made from MCWF_TRANS.
n Example: Extension of MCWF_TRANS to include MCWF_TEMPL.

(C) SAP AG BC610 8-6


Programming and Activating User Exits

l User exits contain the selection logic for the new


fields in the communication structure
l Only one user exit for all extensions
l Activate user exit with customer-defined project

ã SAP AG 1999

n The include incorporated in the function module EXIT_SAPLMCWF_001 must be changed. ALL
selections for ALL extensions must be programmed in this include.
n See WI_CODING_TEMPLATE in the function group MCWF for a user-programmed selection
example. The loop implemented here can be used as a template for user-defined database selections.
n The function modules SWI_READ_CONTAINER_ELEMENT (read a container element) and
SWI_READ_CONTAINER_ATTRIBUTE (read an attribute of an object in the container) can be
used for user-defined selections.
n Activate the user exit via the transaction CMOD. The extension WISEXIT supplied by SAP must be
entered here for the customer-defined project.

(C) SAP AG BC610 8-7


Creating Field Catalogs

l Categorization of new fields


n Characteristics
n Time
n Key figures

ã SAP AG 1999

n Characteristics are information that is suitable for grouping or classification purposes (for example,
plant, material, storage location).
n Key figures are significant (and measurable) business values (for example, quantities, amounts,
costs).
n Time values are used to assign the characteristics periodically. The key figure values are aggregated
periodically for each characteristic.
n The above categorization is set out by the LIS. Additional categorizations can also be defined (for
example, according to application).
n Field catalogs are client-specific.
n Example: field catalog FWFB

(C) SAP AG BC610 8-8


Creating Info Structures

l Create the LIS tables in which the customer-


specific data is to be stored
l Transfer the data from the communication
structures
l Table structure depends on analysis to be
performed

ã SAP AG 1999

n Both selected data and total values are stored. As a result, both characteristics and key figures can be
defined. The key figures contain aggregate values that can be analyzed individually for every
characteristic.
n The fewer characteristic columns in the info structures, the higher the degree of 'grouping' of the key
figures.
Example: (number, agent) is 'grouped' to a greater degree than (number, agent, process).
n The associated tables must only ever be edited via the LIS, and never directly with the ABAP
Dictionary.
n Example: S304 - evaluation of the number of notifications of absence and the total absence time per
employee.

(C) SAP AG BC610 8-9


Creating Update Rules

l Define mapping rules for data transfer between


communication structure and info structure
n Mapping rules for key figures
n Mapping rules for characteristics

ã SAP AG 1999

n Rules proposed by the system can generally be adopted.


n If you set the INIT flag for the characteristics rule, the value is only adopted if it is not blank or 0.
n After the update rules have been created, the update must be generated and explicitly activated.

(C) SAP AG BC610 8-10


Workflow Information System: Unit Summary

l Explain the Workflow Information System architecture

l Implement a customer-specific analysis in the


Workflow Information System

ã SAP AG 1999

(C) SAP AG BC610 8-11


Exercises

Unit: Workflow Information System


Topic: User-Defined Analyses

After completion of these exercises, you will be able to:


• Implement a user-defined analysis

You want to analyze your terminated workflows on the basis of user-


defined and workflow-specific criteria, for example, how many
workflows were executed for finished products, how many for semi-
finished products.

1-1 Create your own analysis to analyze how many instances of the process
Z##MSIPROC1 were executed for each material type. Output the number and the
cumulative total time of the processes, that is, use these two values as key figures.
1-1-1 Execute the individual steps for implementing a user-defined analysis as
described in the course material.
1-1-2 After implementing the communication structure, the field catalog, the
information structure, the update rules and the user exit, you must transfer the
data from the workflow tables to the LIS tables by executing the report
RMCADATA manually.
1-1-3 Check the results of your user-defined analysis.

(C) SAP AG BC610 8-12


Workflow Information System - Solutions

Unit: Workflow Information System


Section: User-Defined Analyses

1-1 Create your own analysis to analyze how many instances of the process
Z##MSIPROC1 were executed for each material type. Output the number and the
cumulative total time of the processes, that is, use these two values as key figures.
1-1-1 Execute the individual steps for implementing a user-defined analysis as
described in the course material.
Solution:
§ Communication structure
Z00MCWF_TRANS in MCWF_TRANS
§ User exit
EXIT_SAPLMCWF_001
§ Field catalog
Z610
§ Info structure
S610
§ Update rules
S610 (info structure), 100 (update group)
Path:
§ WIS in general
Tools > SAP Business Workflow > Development > Reporting > Workflow
Information System (WIS)
§ For the communication structure
Tools > SAP Business Workflow > Development > Reporting > Workflow
Information System (WIS) > Environment > Enhancements > Append
structure
§ For the user exit
Tools > SAP Business Workflow > Development > Reporting > Workflow
Information System (WIS) > Environment > Enhancements > Selection
program
§ For the communication structure
Tools > SAP Business Workflow > Development > Reporting > Workflow
Information System (WIS) > Environment > Enhancements > Append
structure
§ For the info structure
Tools > SAP Business Workflow > Development > Reporting > Workflow
Information System (WIS) > Environment > Info structures > Create
§ For the update rules
Tools > SAP Business Workflow > Development > Reporting > Workflow
Information System (WIS) > Environment > Updating > Create

(C) SAP AG BC610 8-13


1-1-2 After implementing the communication structure, the field catalog, the
information structure, the update rules and the user exit, you must transfer
the data from the workflow tables to the LIS tables by executing the report
RMCADATA manually.

Path:
Tools > SAP Business Workflow > Development > Reporting > Workflow
Information System (WIS) > Environment > Administration > Transfer data
1-1-3 Check the results of your user-defined analysis.

Solution:
Application 20, info structure S610

Path:
Tools > SAP Business Workflow > Development > Reporting > Workflow
Information System (WIS) > Standard analyses > User-Defined Analysis

*----------------------------------------------------------------------*
* INCLUDE ZXMCAU01 *
*----------------------------------------------------------------------*
DATA: MTART LIKE MARA-MTART.
LOOP AT XMCWF_TRANS. " xmcwf_trans is defined in fm interface
IF XMCWF_TRANS-WI_RH_TASK = 'WS96000011'.
" look for all instances of process Z00MSIPROC1
" this is the only flow dealing with materials of type FERT
CALL FUNCTION 'SWI_READ_CONTAINER_ATTRIBUTE'
EXPORTING
WI_ID = XMCWF_TRANS-WI_ID
ELEMENT = 'MATERIALMASTER' " must be capital letter
TAB_INDEX = 000000 " single line attribute
ATTRIBUTE = 'MATERIALTYPE' " must be capital letter
IMPORTING
VALUE = MTART
EXCEPTIONS
READ_FAILED = 1.
IF SY-SUBRC = 0.
XMCWF_TRANS-MTART = MTART.
MODIFY XMCWF_TRANS.
ENDIF.
ENDIF.
ENDLOOP.

(C) SAP AG BC610 8-14


Appendix

l This section contains supplementary material


to be used for reference
l This material is not part of the standard course
l Therefore, the instructor might not cover this
during the course presentation

ã SAP AG 1999

(C) SAP AG BC610 9-1


Abbreviation List
Abbreviation Long text First mention
API Application Programming Interface Unit 3
BI Background Work Item Unit 6
BOB Business Object Builder Unit 2
BOR Business Object Repository Unit 2
ECA Event Condition Action Unit 5
EM Event Manager Unit 3
FM Function Module Unit 2
FG Function Group Unit 6
FI Workflow Work Item Unit 6
RH Runtime Handle Unit 2
LIS Logistics Information System Unit 7
LUW Logical Unit of Work Unit 5
POR Persistent Object Reference Unit 2
RFC Remote Function Call Unit 5
tRFC Transactional RFC Unit 5
WF Workflow Unit 1
WI Work Item (General) Unit 6
WIM Work Item Manager Unit 3
WIS Workflow Information System Unit 7
ã SAP AG 1999

(C) SAP AG BC610 9-2


Addressing Via SAP Organizational Objects

l Using object-based attributes for agent


determination
l Linking the Business Object Repository and the
organizational structure
l No programming required

ã SAP AG 1999

(C) SAP AG BC610 9-3


Definition of an SAP Organizational Object

BUS1001 T024L Object type

Material Laboratory Keys


Laboratory Description
PlantStock Attributes BOR
...
Edit Display Methods
... ExistenceCheck
Created Events
...

O - Z_Dep_DesignOffice1
T7791
SO T024L/KB1
OrgObjTyp ObjTyp ... S - Z_Job2 -- USHill
S - Z_Job1 -- USMiller
T024L 0 ...
O - Z_Dep_DesignOffice2 PD ORG
... ... SO T024L/KB2
S - Z_Job3 -- USJones
S - Z_Job4 -- USSmith
Potential assignment
to organizational units Assignment to a concrete organizational
unit
ã SAP AG 1999

n 1) Definition of the object type to be used subsequently as an SAP organizational object (in this case,
T024L) to determine the agent assignment.
n 2) Definition of an attribute that is mapped on this object type for the object type used in the
workflow in which agent assignment is required (in this case, the laboratory attribute for the object
type BUS1001, because the underlying workflow operates with the object type BUS1001 or one of
its subtypes).
n 3) Definition of the BOR object type from 1) as an SAP organizational object in PD Org and
determination of the potential links in the organization model via entry in table T7791 (in this case,
T024L is only to be linked with organizational object type O, that is organizational units).
n 4) Link an instance of the SAP organizational object with an organizational unit from the
organization model (here link laboratory KB1 with organizational unit Z_Dep_DesignOffice1 and
laboratory KB2 with C_Dep_DesignOffice2)

(C) SAP AG BC610 9-4


SAP Organizational Object in Role and Step
Definition

l Role definition with reference to SAP organizational


object type
l Step definition with reference to this role
l Binding must write SAP organizational object to
role container

ã SAP AG 1999

n Binding in step definition between workflow container and (implicit) role container: the attribute
containing the SAP organizational object (in this case, BUS1001.Laboratory) must be written to the
role container.

(C) SAP AG BC610 9-5


Evaluation of SAP Organizational Object at
Runtime

BUS1001 T024L Object type

100-300 KB1 Keys


KB1 DesignOffice1
3000 Attributes BOR
...
Edit Display
Methods
... ExistenceCheck
Created Events
...

O - Z_Dep_DesignOffice1
T7791
SO T024L/KB1
OrgObjTyp ObjTyp ... S - Z_Job2 -- USHill
S - Z_Job1 -- USMiller
T024L 0 ...
O - Z_Dep_DesignOffice2 PD Org
... ... SO T024L/KB2
S - Z_Job3 -- USJones
S - Z_Job4 -- USSmith
Potential assignment
to organizational units Assignment to a concrete organizational unit
ã SAP AG 1999

n 1) Role evaluation determines the organizational units (in this case Z_Dep_DesignOffice1) that are
linked with the instance of the SAP organizational object (in this case, KB1).
n 2) All object instances linked with this organizational unit are returned as the role evaluation result
(in this case, Z_Job1 and Z_Job2).

(C) SAP AG BC610 9-6


Addressing Via SAP Organizational Objects

l In the BOR, define an object type for the SAP


organizational object with key, attribute 'Description'
and method 'ExistenceCheck'
l Create an attribute for our object type with reference
to the object type defined
l Enter SAP organizational object in table T7791
l Include SAP organizational object in organizational
plan
l Define a role and use it in the workflow step
definition

ã SAP AG 1999

n Table T7791 is maintained via SM30. The organizational units that can be linked can be specified
here.
n The organizational plan is maintained from the workflow development environment.

(C) SAP AG BC610 9-7


tRFC Packet Processing - Case 1

Event creator Event receiver

... Function f1.


Call function f1 ...
in background task
destination XXX LUW1 LUW1’
exporting ...
...
Commit work. “ end first LUW End function.

...
Call function f2 Function f2.
in background task ...
destination XXX
exporting ...
... LUW2 LUW2’
Commit work. “ end second LUW End function.

ã SAP AG 1999

n The event creator has an LUW for each event and each event has one receiver
=> Each event receiver also has its own LUW.

(C) SAP AG BC610 9-8


tRFC Packet Processing - Case 2

Event creator Event receiver

... function f1.


call function f1 ...
in background task
destination XXX
exporting ...
...
end function.
...
call function f2 function f2.
in background task ...
destination XXX LUW LUW’
exporting ... rollback work.
... raise exception.
end function.
call function f3
in background task function f3.
destination XXX ..
exporting ...
...
commit work. “ end LUW end function.

ã SAP AG 1999

n Several events originate from one LUW


=> All event creators are also in one LUW
=> Rollback work or raise within one receiver affects all other receivers.

(C) SAP AG BC610 9-9


tRFC Packet Processing - Case 3

Event creator Event receiver


...
call function f1
in background task function f1.
as separate unit ...
destination XXX
exporting ...
... LUW’
end function.
...
call function f2 function f2.
in background task ...
as separate unit
destination XXX LUW LUW’’
rollback work.
exporting ... raise exception.
...
end function.
call function f3 function f3.
in background task ..
as separate unit
destination XXX
exporting ... LUW’’’
... end function.
commit work. “ end LUW

ã SAP AG 1999

n Several events come from one LUW. The receivers, however, are started with the addition 'AS
SEPARATE UNIT'
=> Each event receiver has its own LUW
=> Rollback work or raise exception only locally in current receiver.

(C) SAP AG BC610 9-10


Event Manager and Packet Processing

l 3.0F
n All receiver FMs run independently of each other
n Error handling as in 3.0D
l 3.0D
n Workflow receiver FMs no longer trigger exceptions
n Error handling: Deactivate linkage and send a mail to the system
administrator for workflow
l 3.0C
n All workflow receiver FMs trigger exceptions
n No special error handling

ã SAP AG 1999

n The addition 'AS SEPARATE UNIT' is available as of 3.0F.

(C) SAP AG BC610 9-11


Work Queue Definition

l A work queue consists of


n A list of tuples (object instance, task)
n A list of agents for the tuples (optional)
n A default task (optional)
l Special work item type

ã SAP AG 1999

n The object instances can be of the same or of different object types. Semantically, the list is regarded
as one set (that is, duplicates are permitted).
n A task can be specified for every object instance. If a task is not specified, the default task is used.
Only dialog or synchronous background tasks are permitted.
n The agents of the tuples are derived from either the agent list or, if this list is empty, the
organizational assignment of the respective task.
n The status is handled separately for each individual tuple and for the work queue as a whole.
n Since the work queue is a work item of a specific type, it has all of the properties of a work item,
such as:
Ÿ Deadline monitoring
Ÿ Excluded agents
Ÿ Terminating events
Ÿ Visibility in the Business Workplace

(C) SAP AG BC610 9-12


Criteria for Using Work Queues

l Tasks on objects of different type


l Background task(s) on a set of objects
l Actions both on the set as a whole and on each
individual element in the set
l Status monitoring both for the set as a whole and for
each individual element in the set
l Detailed error handling

ã SAP AG 1999

n The alternatives for each possible scenario must be examined. The above criteria do not necessarily
all have to be fulfilled to use work queues.
n There are certain advantages with background tasks for a set of objects, since the methods belonging
to the tasks can be executed directly (that is, without creating a background work item).
n Background task on a set of objects to be executed together
n Actions on the work queue as a whole and on each individual object
n Error handling required
n Example: Work queues with mass processing in Asset Accounting

(C) SAP AG BC610 9-13


Work Queues Outside a Workflow

l Explicit agent assignment required


l Processing via the Business Workplace
l Restricted functionality

ã SAP AG 1999

n Since the work queue, as such, is not assigned to a task, agents must be assigned explicitly when it is
created (via the table AGENTS in the function module SWZ_AI_CREATE).
n The work queue then appears (as a dialog work item) in the Business Workplace of the recipients.
n The Business Workplace features additional menu options for processing work queues, such as
"Release" or "Display object list". The full functionality for work queues, however, is only available
as an API or as methods of the object type ARCHLISTWI.

(C) SAP AG BC610 9-14


Work Queues Within a Workflow

l Use of object type ARCHLISTWI


(or a subtype)
l Methods for all work queue actions
l Any workflow definitions
l Sophisticated error handling

ã SAP AG 1999

n The basic functionality for work queues is encapsulated in the object type ARCHLISTWI.
Application or customer-specific extensions must be implemented in a subtype (for example,
AM_AI).
n Each instance of a work queue can only be used either inside or outside a workflow.
n Processing a work queue inside a workflow allows any process definitions (for example, multi-level
release of work queue), or sophisticated error handling (for example, handling the tuples with errors
in a new work queue).
n Using work queues within a workflow is advisable.

(C) SAP AG BC610 9-15


SAP Review
Volume 1 Edition 1 July 1998

MSI BPR
Motor Sports International (MSI) has successfully implemented SAP R/3. SAP Business Workflow
helped fulfil the goals set by the company for optimizing business processes (Business Processing
Reengineering, or BPR).
The following study investigates the process used by MSI to achieve these objectives, with the help of
the SAP Business Workflow tools. The study does not only outline the precise MSI Workflow
implementation solution but also explains the business process in detail and suggests actions that you
may perform.
This case study is unlike any other Workflow process that would actually appear in your company: it
aims to motivate you to do the course and provide you with support for implementing Workflow
successfully.
The problem at MSI: the existing system at MSI could not notify the designer of relevant changes to
material master records. This communication gap led to a delay in adjusting the production line and also
resulted in large quantities of obsolete and unwanted warehouse stock.
The solution at MSI: with the help of SAP Business Workflow, BPR enabled MSI to make considerable
savings in the warehouse stock reduction procedure.

In short: the workflow process at MSI


Activation: this business process always starts when a user changes the Old Material field in a
material master record. The result of the change triggers a workflow event (for example,
OldMaterialChanged) which then triggers one of two workflow processes.
The triggering event is activated via a link to the SAP change documents. As soon as the field is
changed from a value '*' to your group number 'XX', the 'OldMaterialChanged' event is triggered.
*Note: Enquiries at MSI have shown that this field is not used. Changes to the value are
therefore used to inform the designer of a relevant change in the material master.
Distinction: As mentioned above, the event triggers one of two workflows. The definitions of the two
workflows are identical, although different role resolutions are used. The material type determines
which workflow is started. The first workflow is started for material type 'FERT' for completed goods.
All other material types start the second workflow.

(C) SAP AG BC610 10-16


Monitor: Not all changes in the Old Material field start the workflow process (MSI only wants certain
industries, for example). For this case study, you must ensure that the Changer of the material master
is your logon ID.
Core process: As soon as a material has been changed, a particular designer must be informed. The
agent responsible is based on the "laboratory" field.
After the notification, the designer adjusts the production process to suit the change. To inform the
workflow system that this work has been finished, the designer changes the Basic Material field of the
corresponding material master. This event is therefore an asynchronous task for the terminating event.
*Note: Enquiries during the project indicate that nobody else uses the Basic Material field. A
change to the value in fact represents a status change.
If the designer does not end all activities within a specified time interval (for example, five minutes),
the manager of the designer must be informed of this delay.

As soon as the workflow system has been notified that the designer has finished his or her work, it
sends a final notification that the process is finished and that the material just changed can now be sent
back to production. The workflow determines who receives this notification (Note: in practice, this
would usually be implemented via role resolution). The first workflow (for material type 'FERT')
forwards the notification to the user that changed the material at the start. The second workflow (all
other material types) forwards the notification to the designer's manager for inspection purposes.

Analyze: The management team at MSI expects a specific daily report on all newly started workflows.
As well as the total number, the list also contains the workflow initiator for each workflow instance.
The system administrator wants to maintain the database with minimal effort; a monthly archiving
procedure must therefore be planned. To support planning, the workflow administrator requires a
weekly report on the workflows that have been started but not yet completed.

Table I: Overview Material Object Types

Property Name Meaning


Keys Material Unique ID of a particular material
Attribute ChangedBy The 'owner' of the material
Plant The 'main' factory in which the material will be produced
Method ExistenceCheck Checks whether a particular material exists or not
Edit Allows the designer to change the Basic Material field
Display Displays a particular material
ChangeDocDisplay Displays all changes made to a particular material
Event BasicMaterialChanged Designer has ended processing by changing the Basic Material field
OldMaterialChanged Workflow trigger: user has changed the Old Material field

(C) SAP AG BC610 10-17

You might also like