BIT611_EN_Col62_FV_Part_A4[1] - SAP Business Workflow Programming With ABAP OO
Short Description
Download BIT611_EN_Col62_FV_Part_A4[1] - SAP Business Workflow Programming With ABAP OO...
Description
BIT611 SAP Business Workflow Advanced Programming with ABAP OO SAP NetWeaver
Date Training Center Instructors Education Website
Participant Handbook Course Version: 62 Course Duration: 1 Day Material Number: 50087408
An SAP course - use it to learn, reference it for work
Copyright Copyright © 2008 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Trademarks •
Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® and SQL Server® are registered trademarks of Microsoft Corporation.
•
IBM®, DB2®, OS/2®, DB2/6000®, Parallel Sysplex®, MVS/ESA®, RS/6000®, AIX®, S/390®, AS/400®, OS/390®, and OS/400® are registered trademarks of IBM Corporation.
•
ORACLE® is a registered trademark of ORACLE Corporation.
•
INFORMIX®-OnLine for SAP and INFORMIX® Dynamic ServerTM are registered trademarks of Informix Software Incorporated.
•
UNIX®, X/Open®, OSF/1®, and Motif® are registered trademarks of the Open Group.
•
Citrix®, the Citrix logo, ICA®, Program Neighborhood®, MetaFrame®, WinFrame®, VideoFrame®, MultiWin® and other Citrix product names referenced herein are trademarks of Citrix Systems, Inc.
•
HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.
•
JAVA® is a registered trademark of Sun Microsystems, Inc.
•
JAVASCRIPT® is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.
•
SAP, SAP Logo, R/2, RIVA, R/3, SAP ArchiveLink, SAP Business Workflow, WebFlow, SAP EarlyWatch, BAPI, SAPPHIRE, Management Cockpit, mySAP.com Logo and mySAP.com are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other products mentioned are trademarks or registered trademarks of their respective companies.
Disclaimer THESE MATERIALS ARE PROVIDED BY SAP ON AN "AS IS" BASIS, AND SAP EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR APPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THESE MATERIALS AND THE SERVICE, INFORMATION, TEXT, GRAPHICS, LINKS, OR ANY OTHER MATERIALS AND PRODUCTS CONTAINED HEREIN. IN NO EVENT SHALL SAP BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES OF ANY KIND WHATSOEVER, INCLUDING WITHOUT LIMITATION LOST REVENUES OR LOST PROFITS, WHICH MAY RESULT FROM THE USE OF THESE MATERIALS OR INCLUDED SOFTWARE COMPONENTS.
g2008022104036
About This Handbook This handbook is intended to complement the instructor-led presentation of this course, and serve as a source of reference. It is not suitable for self-study.
Typographic Conventions American English is the standard used in this handbook. The following typographic conventions are also used. Type Style
Description
Example text
Words or characters that appear on the screen. These include field names, screen titles, pushbuttons as well as menu names, paths, and options. Also used for cross-references to other documentation both internal (in this documentation) and external (in other locations, such as SAPNet).
2008
Example text
Emphasized words or phrases in body text, titles of graphics, and tables
EXAMPLE TEXT
Names of elements in the system. These include report names, program names, transaction codes, table names, and individual key words of a programming language, when surrounded by body text, for example SELECT and INCLUDE.
Example text
Screen output. This includes file and directory names and their paths, messages, names of variables and parameters, and passages of the source text of a program.
Example text
Exact user entry. These are words and characters that you enter in the system exactly as they appear in the documentation.
Variable user entry. Pointed brackets indicate that you replace these words and characters with appropriate entries.
© 2008 SAP AG. All rights reserved.
iii
About This Handbook
BIT611
Icons in Body Text The following icons are used in this handbook. Icon
Meaning For more information, tips, or background Note or further explanation of previous point Exception or caution Procedures
Indicates that the item is displayed in the instructor's presentation.
iv
© 2008 SAP AG. All rights reserved.
2008
Contents Course Overview ......................................................... vii Course Goals ...........................................................vii Course Objectives .....................................................vii
Unit 1: Introduction........................................................ 1 From BOR Objects to ABAP Classes ................................2 Technical View and Business Example ..............................8
Unit 2: ABAP Classes Definition and Implementation .......... 15 Underlying Concepts of ABAP Object Classes in SAP Business Workflow............................................................ 17 Class Definition - Instance Handling and Key Fields ............. 29 Class Definition - Attributes and Methods ......................... 53
Unit 3: Use Classes in Workflow Architecture .................... 91 Exceptions, Events and API Functions ............................ 92 Using Classes in Workflow Architecture .......................... 110
2008
© 2008 SAP AG. All rights reserved.
v
Contents
vi
BIT611
© 2008 SAP AG. All rights reserved.
2008
Course Overview This course covers customer adaptations and enhancements to workflows that require programming. You will learn how to program workflow interfaces at the ABAP class level. This includes attributes, methods and events. The course also provides information on developing functional methods with the new “Container Parameter Interface” , including check function modules, and so on.
Target Audience This course is intended for the following audiences: • •
Workflow developers (with ABAP and ABAP OO knowledge) Workflow consultants (with ABAP and ABAP OO knowledge)
Course Prerequisites Required Knowledge • • • •
SAPTec BIT601 BIT610 BC400 and BC401 or equivalent knowledge
Recommended Knowledge • •
BIT600 DBITWF
Course Goals This course will prepare you to: • •
Perform workflow programming at all levels Use ABAP classes in SAP Business Workflow
Course Objectives After completing this course, you will be able to: • •
2008
Identify all points in the workflow system at which programming is possible or necessary Create your own classes and use them in the workflow architecture
© 2008 SAP AG. All rights reserved.
vii
Course Overview
BIT611
•
Use “Container Parameter Interface” as the new application programming interface (API) for workflow related functions (check, receiver type, and so on)
SAP Software Component Information The information in this course pertains to the following SAP Software Components and releases: •
viii
SAP Web Application Server 6.20
© 2008 SAP AG. All rights reserved.
2008
Unit 1 Introduction Unit Overview This unit covers a brief overview of the uses and tasks of a workflow management system. It explains the definition architecture and the places within it that can be programmed. This unit also introduces the example that will be used in the course exercises.
Unit Objectives After completing this unit, you will be able to: • • • • • •
Repeat the main points of SAP Business Workflow architecture. Recognize the components of SAP Business Workflow that enable or require programming by the user. Compare and contrast ABAP classes and business object types used in workflow development. Identify the main technical aspects of ABAP Classes and BOR Analyze the Business Process Compare the business object components (available) with the ABAP class components needed
Unit Contents Lesson: From BOR Objects to ABAP Classes.................................2 Lesson: Technical View and Business Example ...............................8
2008
© 2008 SAP AG. All rights reserved.
1
Unit 1: Introduction
BIT611
Lesson: From BOR Objects to ABAP Classes Lesson Overview This lesson repeats the underlying architecture and terminology of the workflow engine. It also compares and contrasts ABAP Classes and SAP Business Objects used in workflow development.
Lesson Objectives After completing this lesson, you will be able to: • • •
Repeat the main points of SAP Business Workflow architecture. Recognize the components of SAP Business Workflow that enable or require programming by the user. Compare and contrast ABAP classes and business object types used in workflow development.
Business Example Your company have implemented some new business functions as Add On to the SAP ERP system. These functions are developed with ABAP Objects and your developers have many experience in this part of programming technique. To gain advantage of these resources, the existing business functions should used in workflow architecture to model the important business processes in this Add On.
Workflow Management Structure There are some important declarations, you have to discuss, to describe a workflow management system: •
A system that delivers work: – – – –
In the correct sequence With all the necessary information At the correct time To the responsible people
Workflow Management is used to link work steps automatically. It enables the control of connected activities across transactions and across different applications.
2
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: From BOR Objects to ABAP Classes
To work with structured processes in a workflow management system, there has to be a variety of services to develop the necessary functions at design time: •
Processdefinition What happens, and in which order? Workflow builder, task definition
•
Organizational modeling Who does what? Organization model, rule definition
•
Application encapsulation Which objects are required? Business Object Builder, Class Builder
Through the process definition, the a workflow management system ensures that “work is delivered in the correct sequence... ”. Through organization modeling, a workflow management system ensures that “work is delivered to the people responsible...”. Through application encapsulation, a workflow management system ensures that “work is delivered with all the necessary information”. There has to be a variety of services to control the workflow runtime. Tools like the following allow to gain access of the advantages of a workflow management system: •
Support for end users What have I got to do today? Business Workplace
•
Process control What happens when? Workflow manager, work item manager
•
Evaluation of processing Who did what and when? Reporting and analysis
Through end user support, a workflow management system ensures that “work is delivered to the people responsible at the correct time”. Through process control, a workflow management system ensures that “work is delivered in the correct sequence at the correct time”.
2008
© 2008 SAP AG. All rights reserved.
3
Unit 1: Introduction
BIT611
Figure 1: SAP Business Workflow: Definition Architecture
In the graphic, A→ B means that A uses B For example: A step definition uses attributes (container operation), events (wait steps), methods (submethods). Tasks use workflow definitions (in multistep tasks) or methods (in single step tasks).
History of Business Process Management Business Process Management services were first introduced with release 2.0, but 3.0c was SAP’s first real concerted effort at providing Business Process Management with the introduction of SAP Business Workflow. At that time, object-oriented programming was more an idea than a reality in ABAP; however it was already clear that object oriented techniques were the way of the future and critical to the underpinnings of SAP Business Workflow.
4
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: From BOR Objects to ABAP Classes
Figure 2: History of Business Objects and ABAP Classes
As a result, SAP Business Workflow was delivered with an approximation of object-oriented programming called the Business Objects Repository (BOR). The aim of the BOR was clearly to provide object oriented (style) techniques and services in systems that were not yet capable of object oriented programming. Major strengths of the BOR was in how well it provided object oriented capabilities - such as inheritance, delegation, association, and polymorphism - to such an extent that it wasn’t until R/3 release 4.6C that similar depth of object oriented capabilities was available in ABAP OO and not until SAP Web Application Server 6.20 that ABAP OO was able to be integrated with SAP Business Workflow to the same degree as the BOR. Why use Classes? • • • • • • •
It’s the way forward! Standard SAP applications starting to use classes Modern editor & improved coding standards Clever bindings using functional methods Usage not limited to workflow Maintainable by developers without workflow knowledge Adding additional components to classes is really easy!
The need for workflow services outstripped the introduction of ABAP OO, and by the time ABAP OO was fully available and capable of replacing the BOR, a large body of business content had already been provided by the BOR.
2008
© 2008 SAP AG. All rights reserved.
5
Unit 1: Introduction
BIT611
Why not use Classes?! • • • •
More up front “Do It Yourself” when creating a class Knowledge of OO syntax essential (but not hard to pick up!) 1000+ BOR Object Types exist and can still be used Older versions of SAP do not support OO Classes
It is no longer a simple matter of replacing code fragments in macros - a major effort would be needed to convert existing workflow content from the BOR to ABAP OO. Currently the effort required to convert the existing body of BOR content to ABAP OO, and the disruption to customers that would be caused by such a major change in direction, exceeds the ROI of such an activity.
6
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: From BOR Objects to ABAP Classes
Lesson Summary You should now be able to: • Repeat the main points of SAP Business Workflow architecture. • Recognize the components of SAP Business Workflow that enable or require programming by the user. • Compare and contrast ABAP classes and business object types used in workflow development.
2008
© 2008 SAP AG. All rights reserved.
7
Unit 1: Introduction
BIT611
Lesson: Technical View and Business Example Lesson Overview This lesson will identify the main technical aspects of the two necessary developing areas. We will also compare the business object components (available) with the ABAP class components needed, and conduct the detailed project analysis.
Lesson Objectives After completing this lesson, you will be able to: • • •
Identify the main technical aspects of ABAP Classes and BOR Analyze the Business Process Compare the business object components (available) with the ABAP class components needed
Business Example Motor Sports International has decided to implement SAP Business Workflow as its business solution for the “Material Master Change” business process.
First Technical View There are some important changes in the workflow architecture to make the use of classes possible: •
SAP Business Workflow now supports two object repositories:
•
– SWO1 (Business Object Repository) – SE24 (Class Builder) Persistent object keys now have three components:
•
– Object category (CATID) – Object type (TYPEID) – Object key (INSTID) Both repositories are equally well supported:
•
– But: There is no delegation feature for ABAP Objects SE24 support covers the same aspects as BOR support: –
Container, Expressions, Methods and Events
The main developing area to create workflow functions still is the Business Object Repository (see explanations in the previous lesson). To create class functions, you have to use a generic (cross component) tool called the Class Builder.
8
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Technical View and Business Example
The class builder is not workflow specific, so you have to develop workflow functions in the borders of the object oriented approach it represents. One important change in handling business objects is that the broadened persistent object key now includes the category (BOR or ABAP Objects), the type (BOR object type or ABAP class name) and the key.
Figure 3: Business Object / ABAP Classes Comparison
Steps in process definitions contain, in most cases, object methods that will be invoked at runtime to execute application logic. At runtime, the workflow engine executes the processes, determines the relevant steps and invokes the methods of each step. In general, the methods invoked by the workflow engine, are based on business object types. With Web AS 6.40, it is also possible to use methods of ABAP Classes. One important aspect of workflow enabling a class is persistence management. Only persistent objects can survive the frequent context changes the workflow system encounters. For business objects, the Business Object Manager handles the variety of context changes as a “Black Box”. In workflow classes, it is the main aspect of programming to implement such a management.
Business Process Review Motor Sports International Business Process is a scenario that involves Material Master change. The problem at MSI is the delayed notification when a material changes.
2008
© 2008 SAP AG. All rights reserved.
9
Unit 1: Introduction
BIT611
Figure 4: Motor Sports International - Business Process Review
The production line is not notified about the changes in time and continues producing what is eventually obsolete inventory. They have decided that SAP Business Workflow is their solution. Main Business Scenario I •
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, which in turn resulted in large quantities of obsolete and unwanted warehouse stock.
•
Triggering: 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 initiates one of two workflow processes. The triggering event is actually initiated by a link to the change documents. As soon as you change the field from the value * to your group number ##, the OldMaterialChanged event is triggered.
•
10
*Note: Tests at MSI have shown that this field is not used. Changes to its value are used to inform the designer of a relevant change to the material master.
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Technical View and Business Example
The Main Business Scenario is based on a Material Master change. The ABAP Object class has to be implemented like the object type for Material Master: “BUS1001006” . The triggering event determined is OldMaterialChanged, and it is linked to Change Documents (transaction SWEC). It is important to differentiate between synchronous and asynchronous edit (both do not exist). An Asynchronous edit method and task is needed to allow changes and/or updates that are terminated by raising a terminating event. Main Business Scenario II •
Core process: As soon as a material is changed, a particular designer must be informed. The agent responsible is based on the Laboratory field. After notification, the designer adjusts the production process to correspond to the change. To inform the workflow system that this work has been completed, the designer changes the Basic Material field of the relevant material master. This event is therefore a terminating event of an asynchronous task.
•
*Note: Tests carried out during the project indicate that no one else uses the Basic Material field. A change to the value represents a status change. If the designer does not complete all activities within a specified time interval (for example, five minutes), the designer’s manager must be informed of this delay. As soon as the workflow system is notified that the designer has completed his or her work, it sends a notification of completion, stating that the process is completed and that the material just changed can now return to production. The workflow determines who receives this notification (in practice, this would be implemented using rule resolution).
The process involves notifying the designer when a material is changed. The responsible agent for the first step is based on the Laboratory field (MARA-LABOR). The company has also decided that Basic Material is also available to be used for a terminating event.
2008
© 2008 SAP AG. All rights reserved.
11
Unit 1: Introduction
BIT611
Necessary components of class (compare ZRGMARA) •
Attributes
•
– ChangedBy – IndustryName – PLANT – QMessages Methods
•
– Change (asynchronous) – DisplayView (parameter MaterialView) – CreateMaterialFormReference (parameter ReferenceMaterialNumber) Events – – –
BasicMaterialChanged OldMaterialChanged DeadlineTest (with parameter “LatestEndDate”)
Not all components called above are implemented in the following exercises due to time constraints. However, all necessary functions will be shown.
12
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Technical View and Business Example
Lesson Summary You should now be able to: • Identify the main technical aspects of ABAP Classes and BOR • Analyze the Business Process • Compare the business object components (available) with the ABAP class components needed
2008
© 2008 SAP AG. All rights reserved.
13
Unit Summary
BIT611
Unit Summary You should now be able to: • Repeat the main points of SAP Business Workflow architecture. • Recognize the components of SAP Business Workflow that enable or require programming by the user. • Compare and contrast ABAP classes and business object types used in workflow development. • Identify the main technical aspects of ABAP Classes and BOR • Analyze the Business Process • Compare the business object components (available) with the ABAP class components needed
14
© 2008 SAP AG. All rights reserved.
2008
Unit 2 ABAP Classes Definition and Implementation Unit Overview This unit provides a short description of the underlying concepts of ABAP Classes for SAP Business Workflow and explains the definition of a class and its components in detail. You will learn how attributes and methods are defined and implemented. You will also learn how to implement exceptions in methods, and how parameters are called and returned in method processing. The final part of the unit covers access to attributes and calling methods inside and outside the BOR, and performance recommendations for implementing an object type.
Unit Objectives After completing this unit, you will be able to: • • • • • • • • •
Explain the basic technical concepts of ABAP Object classes in SAP Business Workflow Classify some important concepts of object-oriented programming Create a class Create instance handling required for workflow engine Define key fields Define attributes with a database reference Define “virtual attributes”, like values Define multiline attributes Describe how object references are addressed in the BOR and the workflow
Unit Contents Lesson: Underlying Concepts of ABAP Object Classes in SAP Business Workflow .......................................................................... 17 Lesson: Class Definition - Instance Handling and Key Fields ............. 29 Exercise 1: Create a Class with Instance Handling..................... 41
2008
© 2008 SAP AG. All rights reserved.
15
Unit 2: ABAP Classes Definition and Implementation
BIT611
Lesson: Class Definition - Attributes and Methods .......................... 53 Exercise 2: Create Attributes for Workflow Class ....................... 65 Exercise 3: Create Methods for Workflow Class ........................ 79
16
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Underlying Concepts of ABAP Object Classes in SAP Business Workflow
Lesson: Underlying Concepts of ABAP Object Classes in SAP Business Workflow Lesson Overview In general, the methods invoked by the workflow engine are based on object types (BOR). The workflow engine is also able to invoke methods of ABAP classes. This lesson describes the underlying technical concepts of ABAP Object classes for SAP Business Workflow.
Lesson Objectives After completing this lesson, you will be able to: • •
Explain the basic technical concepts of ABAP Object classes in SAP Business Workflow Classify some important concepts of object-oriented programming
Business Example You have introduced workflow techniques in your company and now need to insert functions from your customer-based add-ons, where standard object types are not sufficient for your requirements. The developers in your company are familiar in programming ABAP Objects and most of the add-on functions are based on this language.
Classes in SAP Business Workflow Classes have to encapsulate the application data (tables) and actions that can be performed on this data (such as transactions, reports and function modules) by the workflow engine. Because the workflow engine has to handle all objects in a uniform way, this means, the class has to react in the exact way like its business object type pendant.
2008
© 2008 SAP AG. All rights reserved.
17
Unit 2: ABAP Classes Definition and Implementation
BIT611
Figure 5: Objects / Classes - Purpose
A class instance defines a stable, extendable “business” view. Users of the instance are not affected by changes to the underlying database tables, transactions, reports and so on, by using standard interface components like attributes, methods and events. The class handles the functional changes internally by implementing appropriate changes for all of its users. This encapsulation has the following advantages: • • •
18
Simple modeling of processes Stable processes with a high degree of reusability On a technical level: A standard calling interface for the workflow runtime system
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Underlying Concepts of ABAP Object Classes in SAP Business Workflow
Since the engine stores information about the process' state, steps and related objects in database tables, it must be able to convert references to instances of ABAP classes to a representation that can be saved (and vice versa: it must be possible to create an instance of an ABAP class from a previously stored persistent representation). •
Methods
•
– In tasks: Define the “core” of an activity – In steps: Before methods, after methods and secondary methods Attributes –
•
Conditions: Branches, loops, parallel processing forks, conditions before and after steps – Container operation, binding, agent assignment, deadlines Events – –
Start workflows, end steps Create event, wait for event
Use of methods in steps (methods can change object data) • •
The “main method” of an activity is encapsulated in a task so that it can be reused. Before, after and secondary methods define subordinate or parallel activities and are directly specified at a particular step.
Use of attributes (access to object attributes in the workflow is always read-only) • •
Values are used for process control or transferred as parameters on the method. You can query attributes in your own modules in programming exits (check type function modules, programmed binding, receiver type function modules).
Use of events: • •
2008
Events are created for communicating between the application and the workflow system or for communicating different workflows. The Wait for Event prompt (for example, “Wait until a specific document is released?”) is used for synchronizing processes or parts of a process. For example, “Wait until a particular document is released.”. The user is then notified of the release by an event.
© 2008 SAP AG. All rights reserved.
19
Unit 2: ABAP Classes Definition and Implementation
BIT611
Figure 6: Class - Definition in Class Builder
The Class Builder (SE24) is a client-independent directory of all defined ABAP Object classes. Each class is assigned to a development class and therefore, is also indirectly assigned to an application component. Key fields provide a unique reference between an object type and a database table (or a view). Each object instance is clearly displayed in a row in the table specified. Two types of Attribute can be can be created: • •
Database attribute (attribute value is contained in the specified database table) Virtual attribute (source text is run to determine the value)
Methods are implemented using transactions, BAPIs, reports and so on. Depending on the implementation, methods are classified according to their processing model (synchronous/asynchronous) or interaction model (dialog/background). Events are only declared in the class (both their names and parameters are declared). Events are triggered and received using other tools. Interfaces Interfaces differ from regular inheritance in their area of use. In terms of programming, there are hardly any differences, however. From a technical point of view, interfaces are simply superclasses that cannot be instantiated, do not have an implementation part, and only have public components.
20
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Underlying Concepts of ABAP Object Classes in SAP Business Workflow
In ABAP Objects, interfaces primarily serve to define uniform interfaces (protocols) for services. Various classes can thus offer (implement) these services in different ways, but keep the same semantics. Interfaces therefore contain no implementations. To recognize the semantic differences from regular inheritance, you can concentrate on the following, typical use cases:
Figure 7: Central Definition of Shared Components
For example, you want to allow for the option of having multiple classes implementing a service in different ways, but using the same method names and with a uniform signature. With regular inheritance, you would define such a method in the shared superclass. However, if you cannot model a superclass suitably for inheritance, you need to define an interface and then define this method there. Therefore, you can compare this case with a generalization relationship with a superclass.
Development Support for Creating a class To be able to use an object of an ABAP class with the workflow engine, the class has to implement the interface “IF_WORKFLOW”. This interface provides a total of six different methods which cover the requirements from workflow architecture (see below).
2008
© 2008 SAP AG. All rights reserved.
21
Unit 2: ABAP Classes Definition and Implementation
BIT611
Figure 8: Interface – IF_WORKFLOW
Be aware that classes implementing IF_WORKFLOW can be used in any workflow by any workflow modeler. This means that a class, implementing this interface, has automatically status “released” (compare with behavior of BOR objects!). As a first conclusion, such a class should only be changed in a compatible way that does not invalidate existing users (never delete attributes, change methods in an upward compatible way). There is no “where used list” that shows in which workflow a class is used: you should always assume that there are unknown users of your class in some subsequent systems or at the customer’s site. The second conclusion is that “your” (internal) classes should not implement interface IF_WORKFLOW. To protect internal classes, it is better to use wrapper classes that implement IF_WORKFLOW. These wrapper classes would be constructed especially for use within workflow and could provide a process-specific subset of methods and attributes of your internal class.
22
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Underlying Concepts of ABAP Object Classes in SAP Business Workflow
Figure 9: Interface – BI_PERSISTENT
One important aspect of workflow-enable a class is persistence management. As mentioned before, only persistent objects can survive the frequent context changes the workflow system encounters. If you want to convert a persistent saved display of an object into an instance of the corresponding ABAP class, the workflow engine calls the FIND_BY_LPOR method. The LPOR method is the counterpart to the FIND_BY_LPOR method. It provides the persistent display for an existing instance of an ABAP object. The workflow engine calls the REFRESH method when the system has to ensure that all values of an object are valid or that they correspond exactly with the persistent display of the object.
2008
© 2008 SAP AG. All rights reserved.
23
Unit 2: ABAP Classes Definition and Implementation
BIT611
Figure 10: Interface – BI_OBJECT
Different Workflow tools (inbox, workflow log, and so on) display objects that are attached to processes or process steps. In general, the object key is used to represent the object. If these tools should use a value different from the object key (for example, a descriptive text) to represent an object instance, then the object itself has to provide the value. The method DEFAULT_ATTRIBUTE_VALUE is used to get this value from an object. If this method doesn't return any value, the object key will be used as the display attribute. The tools that represent objects in a textual way (for example, workflow inbox) by displaying their default attribute also allow to navigate to an object by clicking on that default value. Since the generic tools cannot know how to navigate to a given object (which may be of some user-defined class), the system calls a generic method that implements this navigation. This method is EXECUTE_DEFAULT_METHOD. By calling the RELEASE method, an application can signal that it no longer needs the given object. The instance could therefore be removed from the instance management as soon as the last reference to this object is released. This enables the garbage collector to free the related memory.
24
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Underlying Concepts of ABAP Object Classes in SAP Business Workflow
Additional Concepts of the Object-Oriented Programming Model
Figure 11: Additional Concepts of the Object-Oriented Programming Model
•
Inheritance
•
Inheritance defines the implementation relationships between classes, so that one class (the subclass) adopts the structure and behavior of another class (superclass), possibly also adapting or extending it. Polymorphism
•
In object-orientation, polymorphism is when instances of different classes respond differently to the same messages. Event control Instead of sending messages directly to specific objects, objects can also trigger events. Events can be triggered if it is not yet known at the time of development if objects will react, and if so, how they will react.
Use customer-specific object extensions
2008
© 2008 SAP AG. All rights reserved.
25
Unit 2: ABAP Classes Definition and Implementation
BIT611
Caution: Before SAP NetWeaver 7.0, it was not possible to extend classes like business object types. The only way, to implement customer specific object extensions in SAP classes, is to use explicit enhancement possibilities (User-Exits, BAdIs, and so on) delivered in the standard programming. There is no technique like delegation in ABAP classes for SAP Business Workflow. With SAP NetWeaver 7.0, some new enhancement options have been added: Enhancement Points and Enhancement Sections. The most interesting fact is that customer enhancements with such “implicit” enhancement points (in contrast to the old fashioned way) do not need to be prepared by SAP. An enhancement point is a possibility to add (without modification) source code, variable- and parameter- declarations in SAP-programs, function modules and classes. Explicit enhancement points are SAP prepared extension possibilities in application programming, while implicit enhancement points exits standardized at definite places in SAP programming syntax, that means, without SAP preparation: • • • • •
at the beginning and end of methods of local/global classes at the end of the importing/exporting/changing declaration area of methods of local classes at interface definitions of methods of global classes at the end of public/protected/private section of local classes (to define additional attributes and methods) you can add additional attributes and methods to global classes
Hint: Classes Without Multiple Instantiation (Singleton Pattern): There are many cases (but not the workflow one) in which you need to prevent a class from being instantiated more than once for each program context. You can do this using the singleton concept. The class is defined with the additions FINAL and CREATE PRIVATE and is instantiated using its static constructor. The singleton concept is not a commencement to develop workflow related functions. You need to use classes in workflow architecture with multiple instances, so an only once instantiated class construct is not fitting.
26
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Underlying Concepts of ABAP Object Classes in SAP Business Workflow
Hint: Persistent Objects with ABAP Objects In principle, ABAP programs work with data and objects that are valid at runtime. They are transient (temporary) and disappear when the program ends. If this data is to be stored permanently and independently of the program (persistently) it must be stored in a database. For this purpose, the Persistence Services for ABAP Objects were introduced in the SAP Web AS 6.10. On request, these services write the current attribute values of objects defined as persistent to the associated transparent tables. On receiving another request, they import these values from the tables again, and write the attributes to an object previously defined as persistent.
2008
© 2008 SAP AG. All rights reserved.
27
Unit 2: ABAP Classes Definition and Implementation
BIT611
Lesson Summary You should now be able to: • Explain the basic technical concepts of ABAP Object classes in SAP Business Workflow • Classify some important concepts of object-oriented programming
28
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
Lesson: Class Definition - Instance Handling and Key Fields Lesson Overview This lesson explains how to create a class, and define its key fields and attributes. An essential function of a class, used in workflow, is its instance handling. This lesson describes the form in which the classes must be available to workflow runtime. Attributes of classes can refer to all kinds of data types, because their values are set by the methods of the class. There is no difference in attribute properties, like in object types (database fields, virtual attributes - database references, object references).
Lesson Objectives After completing this lesson, you will be able to: • • •
Create a class Create instance handling required for workflow engine Define key fields
Business Example You have introduced workflow techniques in your company and now need to insert functions from your customer-based add-ons, where standard object types are not sufficient for your requirements. First, create the class and define the key fields and the required attributes.
Instance handling in classes for SAP Business Workflow The persistent representation of an object can appear in different processes or at different places within one process. The workflow engine itself does not provide an instance manager that detects if an object has already been instantiated in the current context (for BOR objects, this is a feature of the corresponding object manager).
2008
© 2008 SAP AG. All rights reserved.
29
Unit 2: ABAP Classes Definition and Implementation
BIT611
Figure 12: Persistent vs. Runtime
Having two instances of the same object may lead to unexpected behavior, for example: • • • •
in particular if the object data is changed within that context mutual locking one instance overwrites data the other has just written inconsistent data display of the “older” instance
Furthermore, creating instances from persistent representations are often performance critical, since operations like an existence-check, initialization, and so on may require elaborate actions. Interface BI_PERSISTENT The following example demonstrates, how an instance management could be realized. This example uses a private attribute that keeps all created instances and their persistent representation:
30
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
Figure 13: Instance Handling
Instance management is automatic for business objects. The workflow engine use the Business Object Manager for these purposes. ABAP classes have also the possibility to handle its instances automatically. Hint: To be able to work with ABAP Objects persistently, the “persistence service” was introduced with SAP R/3 Basis Release 6.10. Objects and their attributes can be written to the database and re-imported. However, the concept of persistent ABAP classes is not flexible enough to handle workflow instances, so you usually handle the persistence of these objects in the class itself (as described in the following sections):
Figure 14: Object References handled in Classes
2008
© 2008 SAP AG. All rights reserved.
31
Unit 2: ABAP Classes Definition and Implementation
BIT611
The only input parameter of the following persistence handling method is a persistent object reference, a structure of type SIBFLPOR (POR = Persistent Object Reference). This structure consists of three components: •
CATID Contains an indicator (a ‘category ID’) describing what kind of object is represented. Since the Workflow Engine handles BOR Objects and ABAP Classes, the system must be able to distinguish between these two object categories. It contains “BO” for BOR object and “CL” for an ABAP class.
•
TYPEID Contains the name of the object type (for example, the ABAP class) that should be instantiated.
•
INSTID The key of the object. This field is restricted to 32 characters
Figure 15: Implementation – FIND_BY_LPOR
It could therefore be useful to manage already instantiated objects within the class, to make sure that different calls of FIND_BY_LPOR will all return a pointer to the same instance. Changes on this instance, which are done by a client are immediately visible to all other clients. METHOD bi_persistent~find_by_lpor. *- method parameter LPOR is the persistent object reference *- LPOR = Local Persistent Object Reference
32
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
* begin of local data DATA: l_standardmaterial
TYPE REF TO zbit611_... .
" reference to class instance
DATA: l_matnr
TYPE mara-matnr.
" key field
DATA: ls_instance
TYPE t_instance.
" instance handling
* end
of local data
* Check if LPOR is filled CHECK lpor-instid IS NOT INITIAL.
* instid is the key of the object l_matnr = lpor-instid.
* read mst_instances into ls_instance to test, if instance already exists READ TABLE mst_instances WITH KEY number = l_matnr INTO ls_instance. * if no result is found IF sy-subrc NE 0. * create object l_standardmaterial with key l_matnr and catch exception * if exception is raised, exit the method TRY. CREATE OBJECT l_standardmaterial EXPORTING im_matnr
= l_matnr
. CATCH cx_bo_error . EXIT. ENDTRY.
* load l_matnr and l_standardmaterial in ls_instance and append the structure * to table mst_instances ls_instance-number
= l_matnr.
ls_instance-instance = l_standardmaterial. APPEND ls_instance TO mst_instances. * endif of no result is found ENDIF. * load ls_instance-instance into result result = ls_instance-instance. ENDMETHOD.
2008
© 2008 SAP AG. All rights reserved.
33
Unit 2: ABAP Classes Definition and Implementation
BIT611
The method coding uses the class name and object key passed in the LPOR parameter to create an ABAP object instance. Depending on the persistence model chosen for this ABAP class, the instance data could be loaded right away or could be loaded later (on demand). Method LPOR is the counterpart of FIND_BY_LPOR:
Figure 16: Implementation – LPOR
FIND_BY_LPOR receives a persistent representation of an object reference and returns a “live” ABAP instance. LPOR is called on the live instance and returns the persistent object reference for that instance. There is a close relationship between these two methods: by first calling FIND_BY_LPOR for a persistent reference to get an instance, and then calling LPOR on this instance, you should get back to the persistent reference that you started out with. If an instance manager is used, as in the FIND_BY_LPOR example above, coding of the following type could be used: METHOD bi_persistent~lpor. DATA: ls_instance
TYPE t_instance.
READ TABLE mst_instances WITH KEY object = me INTO ls_instance. IF sy-subrc = 0. * return the persistent representation result = ls_instance-lpor. ELSE. * instance not found... create the persitent representation * an other way
34
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
... ENDIF. ENDMETHOD.
There are also several ways of implementing this method in this case. There is an implementation example in the CL_SWF_FORMABSENC demo class.
Figure 17: Implementation - REFRESH
Depending on how the class organizes its own delta handling, the implementation of the method may remain empty. The method is called by the workflow engine, whenever the system has to make sure that the internal values of the object are valid , that is, in sync with the persistent image. If required, reload the object instance data from database in this method: METHOD read_attributes. * get public attributes... (DDIC) * load table mara SELECT SINGLE * FROM mara INTO m_mara WHERE matnr = me->matnr. me->materialgroup
= me->m_mara-matkl.
me->materialtype
= me->m_mara-mtart.
...
* call table makt and m_makt SELECT SINGLE * FROM makt INTO m_makt WHERE matnr = me->matnr AND spras = sy-langu.
2008
© 2008 SAP AG. All rights reserved.
35
Unit 2: ABAP Classes Definition and Implementation
BIT611
* load field maktx of structure m_makt into * class attribute description me->description
= m_makt-maktx.
... ENDMETHOD.
If this method is not needed by a class, the interface-method still needs some “empty” implementation to avoid dumps if the system calls this method. In this case, just enter the METHOD ... ENDMETHOD statements (without implementation in between) as coding.
Object Functions Handling in Classes Interface BI_OBJECT
Figure 18: Implementation – DEFAULT_ATTRIBUTE_VALUE
This example demonstrates how this method could be implemented. The example assumes that the class has an instance attribute DESCRIPTION that is to be used to identify the object. The statement GET REFERENCE OF is used to return a pointer to the DATA-Object (REF TO DATA) rather than the data object itself. Even if a class does not return a specific default value (thus indicating that the object key will be used), the interface method DEFAULT_ATTRIBUTES_VALUE still needs some “empty” implementation to avoid dumps if the system calls this method. In this case, just enter the METHOD ... ENDMETHOD statements (without implementation in between) as coding.
36
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
Figure 19: Implementation – EXECUTE_DEFAULT_METHOD
The tools that represent objects in a textual way (for example, workflow inbox) by displaying their default attribute, also allow you to navigate to an object by clicking on that default value. Since the generic tools cannot know how to navigate to a given object (which may be of some user-defined class), the system calls EXECUTE_DEFAULT_METHOD, which implements this navigation. The example above demonstrates, how this method could be implemented. It expects that the class has a method DISPLAY that shows a dialog for an instance of this class. For many existing business objects, this method is implemented simply by calling the standard display transaction: METHOD DISPLAY.
*- begin of local data DATA: ls_return TYPE bapiret1. *- end of local data CALL FUNCTION 'BAPI_MATERIAL_DISPLAY' EXPORTING material
= me->matnr
IMPORTING return
= ls_return .
CASE ls_return-number. WHEN '000'.
2008
© 2008 SAP AG. All rights reserved.
37
Unit 2: ABAP Classes Definition and Implementation
BIT611
WHEN '262'.
RAISE EXCEPTION TYPE cx_bo_error. WHEN '305'. RAISE EXCEPTION TYPE cx_bo_error.
WHEN OTHERS. ENDCASE. ENDMETHOD.
If a class does not have a default method, the interface method still needs some “empty” implementation to avoid dumps if the system calls the method. In this case, just enter the METHOD ... ENDMETHOD statements (without implementation in between) as coding. By calling the method RELEASE, an application can signal that it no longer needs the given object. The instance could therefore be removed from the instance management as soon as the last reference to this object is released. This enables the garbage collector to free the related memory. Most classes will not implement this method. Nevertheless, an “empty” implementation is required to avoid dumps if the method is called by the system.
Key fields Classes implementing interface IF_WORKFLOW are recognized by transaction SE24 as “Workflow” enabled: such a class can declare attributes as key fields. If key attributes are specified, the system can provide different services, for example, generic dialogs to find an instance.
38
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
Figure 20: Implementation of Key Fields
If an object type specifies multiple key fields, the order is the same as displayed in the class builder. All specified key fields must be character fields (elementary types CHAR, NUMC, DATS or TIMS) with fixed length. Furthermore, the total length when concatenating all key attributes must not exceed 32 characters. The reason for this restriction is that the length of the field INSTID of the persistent representation for an object has a length of 32. For general ABAP classes implementing IF_WORKFLOW, it is of course also possible to use a character guid (GUID32) as the type of the key field (in this case, only one key field is possible). Applications that internally use raw-guids (GUID16) should define the key field as an (additional) character guid field an move the raw-guid to this attribute in the constructor.
2008
© 2008 SAP AG. All rights reserved.
39
Unit 2: ABAP Classes Definition and Implementation
40
© 2008 SAP AG. All rights reserved.
BIT611
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
Exercise 1: Create a Class with Instance Handling Exercise Objectives After completing this exercise, you will be able to: • Create a class for use in the workflow architecture • Implement instance handling for the workflow engine • Define key fields
Business Example Your company has developed some add-ons to the standard business scenarios of the SAP ERP system. These extensions are implemented in an ABAP Object. To gain experience with the techniques of inserting these functions in the workflow architecture, someone has to test the possibilities. You have the task of creating some ABAP class functions as examples for your colleagues. We want to create functions like these encapsulated in the BOR object type BUS1001006. Hint: Please be aware that you have to be an experienced developer to implement all following functions in the given exercise time. You could also copy some coding from the example implementation of class ZBIT611_MARA. Please use this possibility if you do not have enough time or you are not an experienced developer.
Task: Create a new class for use in the workflow architecture. Caution: If you create the following class, a warning like “Implementation missing for method "BI_OBJECT~RELEASE" . . ” could appear. If so, please go into method implementation of called function and insert a line with a space between METHOD ... . and ENDMETHOD. and save the method. 1.
Create a new class ZBIT611_##, where ## represents your group number. Complete the basic data of this class as follows:
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
41
Unit 2: ABAP Classes Definition and Implementation
Object type:
ZBIT611_## (Class)
Description:
Class Group ## (Material)
Package:
Z001
BIT611
Use the IF_WORKFLOW interface to define the standard behavior of your class. 2.
Enter the key field Material Number into class ZBIT611_##.
3.
Develop the “Instance Handling” of your class. You need to implement some types and attributes to administer the class instances, and you have to program FIND_BY_LPOR an LPOR method. To call the CONSTRUCTOR method in a object oriented way, please create an import parameter, like the key field inserted above, for this function. Also maintain an exception to handle within this method.
4.
To finish the implementation of the “Instance Handler” functions, insert the necessary code in the CONSTRUCTOR method. There are some functions, which have to be handled in this method: - the assignment of import variable to key field of class - calling of the existencecheck method - set the initial values of the class reference for handling in workflow The existencecheck method has to be implemented (part of the next exercise), so please set coding (read single entry from leading database table) at first in the constructor method itself. Also calling the functions to set initial values of workflow class is part of a later exercise.
5.
42
Test your implementation by using the “Test” button (F8).
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
Solution 1: Create a Class with Instance Handling Task: Create a new class for use in the workflow architecture. Caution: If you create the following class, a warning like “Implementation missing for method "BI_OBJECT~RELEASE" . . ” could appear. If so, please go into method implementation of called function and insert a line with a space between METHOD ... . and ENDMETHOD. and save the method. 1.
Create a new class ZBIT611_##, where ## represents your group number. Complete the basic data of this class as follows: Object type:
ZBIT611_## (Class)
Description:
Class Group ## (Material)
Package:
Z001
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
43
Unit 2: ABAP Classes Definition and Implementation
BIT611
Use the IF_WORKFLOW interface to define the standard behavior of your class. a)
To create a class, navigate to the class builder:Tools → Business Workflow → Development → Definition Tools → Application Integration → Class Builder (SE24) Insert class name ZBIT611_## and press the “Create” Button. In the next dialog, check selection “Class” and press Enter (F8). In the next dialog, enter the description Class Group ## (Material) Check the following parameters and press Enter (F8):
b)
Instantiation:
Public
Class Type:
Usual ABAP Class
Only Modeled:
-> no entry
Final:
'X'
Go to the tab “Interfaces” and insert interface IF_WORKFLOW. Press enter. The following entries should appear: BI_OBJECT BI_PERSISTENT IF_WORKFLOW Save your class (Ctrl + S).
Continued on next page
44
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
2.
Enter the key field Material Number into class ZBIT611_##. a)
Use the business object type BUS1001006 as an example implementation to compare features of your class with some existing code.
b)
Go to the tab “Attributes” and insert the following properties into first line: Attribute:
MATNR
Level:
Instance Attribute
Visibility:
Public
Key Attribute:
'X'
Read-Only:
'X'
Typing:
Type
Associated Type:
MARA-MATNR
Description:
-> set automatically
Initial Value:
-> not required
Save your class (Ctrl + S). 3.
Develop the “Instance Handling” of your class. You need to implement some types and attributes to administer the class instances, and you have to program FIND_BY_LPOR an LPOR method. To call the CONSTRUCTOR method in a object oriented way, please create an import parameter, like the key field inserted above, for this function. Also maintain an exception to handle within this method. a)
Call Edit -> Create Constructor and mark the created entry in tab “Methods”. Press the “Parameters” Button and insert the following properties into first line: Parameter:
IM_MATNR
Pass Value:
-> no entry
Optional:
-> no entry
Typing Method:
Type
Associated Type:
MARA-MATNR
Default Value:
-> not required
Description:
-> set automatically Continued on next page
2008
© 2008 SAP AG. All rights reserved.
45
Unit 2: ABAP Classes Definition and Implementation
BIT611
Save your class (Ctrl + S). b)
To handle the raised exceptions of this method, insert exception class “CX_BO_ERROR” in the exception list of the CONSTRUCTOR method (tab “Exceptions”). Exceptions are theme of chapter 3, however it is necessary to handle a failed constructor method. Please insert the information as described and wait for an explanation until chapter 3.
c)
Go to the tab “Types” and insert two entries T_INSTANCE and T_INSTANCES with Visibility “Private”. Press the “Direct Type Entry” button (after column Associated) and declare the types in next GUI as follows: TYPES: BEGIN OF t_instance, number
TYPE mara-matnr,
instance TYPE REF TO zbit611..., END
OF t_instance .
TYPES: t_instances TYPE STANDARD TABLE OF t_instance .
Save your class (Ctrl + S) and navigate back into your class. d)
Go to the tab “Attributes” and insert a new line with the following properties: Attribute:
MST_INSTANCES
Level:
Static Attribute
Visibility:
Private
Key Attribute:
-> no entry
Read-Only:
-> no entry
Typing:
Type
Associated Type:
T_INSTANCES
Description:
-> set automatically
Initial Value:
-> not required
Save your class (Ctrl + S). e)
Go to the tab “Methods” (with the 'Back to methods' button) and double click the BI_PERSISTENT~FIND_BY_LPOR method. Implement the coding as shown in the following example. Continued on next page
46
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
If you want to compare your coding, please call the implementation of class ZBIT611_MARA! METHOD bi_persistent~find_by_lpor. DATA: l_standardmaterial
TYPE REF TO zbit... .
" reference of object
DATA: l_matnr
TYPE mara-matnr.
" key field
DATA: ls_instance
TYPE t_instance.
" instance handling
* Check if LPOR is filled CHECK lpor-instid IS NOT INITIAL. * instid of import parameter LPOR is object key l_matnr = lpor-instid. * ??? instance already exists ??? READ TABLE mst_instances WITH KEY number = l_matnr INTO ls_instance.
* if no result found IF sy-subrc NE 0.
* create object l_standardmaterial TRY. CREATE OBJECT l_standardmaterial EXPORTING im_matnr
= l_matnr
. CATCH cx_bo_error . EXIT. ENDTRY. * append result to mst_instances ls_instance-number
= l_matnr.
ls_instance-instance = l_standardmaterial. APPEND ls_instance TO mst_instances.
ENDIF. * fill result result = ls_instance-instance. ENDMETHOD.
Save your class (Ctrl + S). Continued on next page
2008
© 2008 SAP AG. All rights reserved.
47
Unit 2: ABAP Classes Definition and Implementation
f)
BIT611
Go to the tab “Attributes” and insert a new line with the following properties: Attribute:
M_POR
Level:
Instance Attribute
Visibility:
Private
Key Attribute:
-> no entry
Read-Only:
-> no entry
Typing:
Type
Associated Type:
SIBFLPOR
Description:
-> set automatically
Initial Value:
-> not required
Save your class (Ctrl + S). g)
Go to the tab “Methods” (with the 'Back to methods' button) and double click the BI_PERSISTENT~LPOR method. Implement the coding as shown in the following example. If you want to compare your coding, please call the implementation of class ZBIT611_MARA! METHOD bi_persistent~lpor. * fill attribute m_por * could also be placed in the constructor m_por-catid
= 'CL'.
m_por-typeid
= 'ZBIT611...'.
m_por-instid
= me->matnr.
* load instance attribute m_por into result
result = m_por. ENDMETHOD.
Save your class (Ctrl + S). 4.
To finish the implementation of the “Instance Handler” functions, insert the necessary code in the CONSTRUCTOR method. There are some functions, which have to be handled in this method: Continued on next page
48
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
- the assignment of import variable to key field of class - calling of the existencecheck method - set the initial values of the class reference for handling in workflow The existencecheck method has to be implemented (part of the next exercise), so please set coding (read single entry from leading database table) at first in the constructor method itself.
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
49
Unit 2: ABAP Classes Definition and Implementation
BIT611
Also calling the functions to set initial values of workflow class is part of a later exercise. a)
It is possible to use the existence check to fill the main table entry of the main application table into an attribute of your class. Go to tab “Attributes” and insert a new line with the following properties: Attribute:
M_MARA
Level:
Instance Attribute
Visibility:
Private
Key Attribute:
-> no entry
Read-Only:
-> no entry
Typing:
Type
Associated Type:
MARA
Description:
-> set automatically
Initial Value:
-> not required
Save your class (Ctrl + S). b)
Go to the tab “Methods” (with the 'Back to methods' button) and double click the CONSTRUCTOR method. Implement the coding as shown in the following example. If you want to compare your coding, please call implementation of class ZBIT611_MARA! METHOD constructor. * assignment of import variable to key field of class matnr = im_matnr. * calling of the existence check method SELECT SINGLE * FROM mara INTO m_mara WHERE matnr = me->matnr. IF sy-subrc NE 0. *
DUMMY ENDIF.
ENDMETHOD.
Save your class (Ctrl + S) and activate it. Continued on next page
50
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Instance Handling and Key Fields
5.
Test your implementation by using the “Test” button (F8). a)
Press the “Test” button (F8).
b)
Enter the material “T-BBD##” into the field IM_MATNR and press the “Instance” button.
c)
A screen should be displayed, where you see the interfaces “BI_OBJECT”, “BI_PERSISTENT” and “IF_WORKFLOW”. One attribute (the key field MATNR) should also be shown.
2008
© 2008 SAP AG. All rights reserved.
51
Unit 2: ABAP Classes Definition and Implementation
BIT611
Lesson Summary You should now be able to: • Create a class • Create instance handling required for workflow engine • Define key fields
52
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Lesson: Class Definition - Attributes and Methods Lesson Overview In business object types, attributes can refer to database fields, or they can be virtual attributes whose content is determined at runtime, based on stored coding. In classes, the value of attributes always set by methods (for example, in the constructor). This lesson describes the main programming aspects in connection with the handling of class attributes in the workflow engine. It also describes the form in which attributes handle object references and multiline values and its conjunctions to the runtime environment.
Lesson Objectives After completing this lesson, you will be able to: • • • •
Define attributes with a database reference Define “virtual attributes”, like values Define multiline attributes Describe how object references are addressed in the BOR and the workflow
Business Example You have created a new customer-specific class and defined instance handling and key fields. Now you want to create the attributes to be handled in the workflow engine and also the methods that you require. You want the methods to be called using parameters, and return parameters and exceptions.
Definition of Attributes The workflow engine provides the possibility to access all public attributes of an object. There are no restrictions as to the data type of these attributes. All simple ABAP types and all DDIC types or references to other classes can be used. The following attribute natures are developed (in business object types) to be handled in workflow engine (and should reflected by the class structures): • • • •
2008
database attributes - access to database tables virtual attributes - calculation with user's own ABAP code attributes typed either with an ABAP dictionary field or an object type / class single-line and multiline attributes
© 2008 SAP AG. All rights reserved.
53
Unit 2: ABAP Classes Definition and Implementation
BIT611
A Database Attribute is defined with reference to a column of the related application table. When the database is first accessed, you have the possibility to read the complete database row and buffer it in the class. A Virtual Attribute is a special function of object types: -> in classes you always have the possibility to calculate the values of attributes with (your own) ABAP code by implementing it in the relevant methods (SET_-method) and call them, for example, in the CONSTRUCTOR -> to get a behavior like “Virtual Attributes” in business object types - the coding will be passed at runtime (when the workflow engine calls the virtual attribute) - a “Functional Method” (GET_-method) has to be implemented with special properties (see below). Some General Hints: • • • • •
Class attributes work like variables They have to be set in CONSTRUCTOR method They have to be refreshed in the BI_PERSISTENT~REFRESH method It is recommended to flag them as read-only Performance Note: Avoid complex attributes that are not always needed, as this is executed for each instance whether the attribute is used or not
Database Attributes
Figure 21: Implementing Database Field Attributes
54
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
The workflow engine provides the possibility to access all public attributes of an object. There are no restrictions as to the data type of these attributes. All simple ABAP types and all DDIC-types or references to other classes can be used. The necessary attributes should set in the CONSTRUCTOR method of class, because the workflow engine need the values when object instance is created. To refresh attribute values, especially when business content of object is changed, you have to implement the settings of the relevant attributes in the BI_PERSISTENT~REFRESH method.
Virtual Attributes
Figure 22: Functional Methods (Virtual Attributes) - Example
Hint: To simulate the behavior of Virtual Attributes you can use Functional Methods: • • • • • •
2008
Method with one returning parameter Can have importing but no exporting parameters Naming convention: GET_ - for example, GET_EMAIL_ADDRESS Returning parameter has to be named like virtual attributes - for example, EMAIL_ADDRESS Can be used in bindings and container operations - Enhanced equivalent of BOR Virtual Attributes Can NOT be used in Work Item Texts - Bind to separate task container element instead
© 2008 SAP AG. All rights reserved.
55
Unit 2: ABAP Classes Definition and Implementation
BIT611
Virtual attributes have to be calculated if the workflow engine calls them in a process context. This behavior is a speciality of attributes from business object types. Normal class attributes are set with method functions in CONSTRUCTOR (or in REFRESH) method (see explanations above). To reach the “old” BOR behavior in classes, the workflow engine interprets Functional Methods as Virtual Attributes.
References If attributes have to be object references (ABAP Objects), then these classes are not required to implement IF_WORKFLOW (it is required for the objects stored directly in the workflow context (container) but is not required for attributes of these objects). The workflow system assumes that object valued attributes of a persistent object will automatically be instantiated by the persistent class when its FIND_BY_LPOR method is called - in other words, no instantiation automatism is invoked for attributes.
Figure 23: Implementing Class References
It is also possible to define attributes that point to BOR objects. Such attributes have to be declared using the structure “SWOTOBJID” as the data type which the workflow system recognizes as a persistent BOR object handle. Such an attribute then points to “any BOR object”. To become more specific and declare your attribute as, for example a BOR object of type “BUS2012”, you need to provide an initial value in which you supply the object type.
56
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Figure 24: Implementing Object Type References METHOD set_... . DATA: lt_porder TYPE swfborptab, ls_porder TYPE swotobjid VALUE '
BUS2012'.
...
ENDMETHOD.
Caution: Structure SWOTOBJID is the BOR specific persistent representation of an object. This structure consists of the fields LOGSYS, OBJTYPE, OBJKEY and DESCRIBE. Here, “OBJTYPE” is the only field you have to fill. Since we need to leave the field LOGSYS blank, the initial value of this attribute starts with 10 spaces (for LOGSYS) followed by the object type “BUS1001006” in upper case.
2008
© 2008 SAP AG. All rights reserved.
57
Unit 2: ABAP Classes Definition and Implementation
BIT611
The above steps declare an attribute that represents a BOR object of a given type. To initialize this attribute with a specific BOR object instance, you can use the common BOR macros. This type of initialization is typically done in the CONSTRUCTOR of your class. Hint: In the “Local types” section of your class, under Goto -> Class-local types -> Local class implementations, you need the line: INCLUDE .
Figure 25: INCLUDE
Hint: In the “Macros” section of your class, under Goto -> Class-local types -> Macros, you need the line: INCLUDE .
Figure 26: INCLUDE
Using Attributes in Processes Attributes are typically accessed in workflow expressions like “&my_object.attribute&”. These expressions can occur in • • • •
data binding conditions container operations in any location, where the process or its steps can be dynamically configured (for example, selection of responsible agent, deadlines, and so on)
Starting in release 6.30, an expression can also be used to synchronously call a method. Therefore, attributes need not be exposed as public attributes, but can also be accessed via GET_-methods.
58
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Definition of Methods Individual steps that are executed by the workflow engine as part of business processes, invoke methods of objects that are accessible within the process context. Since these objects can be implemented by ABAP classes, methods of these classes can be executed within a step.
Figure 27: Synchronous and Asynchronous methods
The methods implement business logic. They can invoke dialogs, they can run synchronously or asynchronously, their execution (status) appears in the workflow log, and so on. In short, these methods have all the features that, in previous releases, were reserved for BOR methods.
2008
© 2008 SAP AG. All rights reserved.
59
Unit 2: ABAP Classes Definition and Implementation
BIT611
Figure 28: Properties of Workflow Steps
There is one difference between BOR and Class methods. To define the behavior of the workflow engine, you have to set some properties in BOR methods (as example, dialog/background, synchronous/asynchronous). Note: The BOR method properties are then pasted to the “Standard Task” properties automatically. You do not have the possibility to define these properties to a Class method. Therefore, there is another place to set these properties in connection with the workflow architecture (see figure above). Note: You have to set the Class method properties in the “Standard Task” directly! In general, only public methods can be invoked. These methods could be defined in different ways: • •
60
defined at the class or one of its super-classes included via interfaces
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Methods defined at the class itself or one of its super-classes can always be used directly within the workflow engine. For methods that are included via interfaces, a restriction applies: Hint: Since some methods included via interfaces are specified in the form “interface-name”~“method-name”, for example, IF_WORKFLOW~FIND_BY_LPOR. The total length for a method name may exceed 30 characters (currently the maximum length for a method name that can be entered in a single step task). If the method name gets too long, the class which includes the interface should simply define an alias name for this method. One can then use a public alias name (when defining tasks, as well as, when defining expressions) and avoid the length problem. Parameters of Methods In most cases, methods will have parameters (import-, export-, and so on). When calling a method in a step of a process, it is possible of pass values (for example, import parameters) or to receive values (for example, export parameters). Since the workflow engine in some cases uses RFC ( calling methods in background - using an RFC - requires that all parameters can internally be serialized / deserialized) to call a method, the types of the method parameters are restricted to one of the following: • • • •
2008
Simple types (for example, string, integer, and so on) Any DDIC type (for example, structures, tables, complex types) not containing ABAP-OO references BOR object references References to ABAP classes that support the interface IF_WORKFLOW
© 2008 SAP AG. All rights reserved.
61
Unit 2: ABAP Classes Definition and Implementation
BIT611
Method parameters representing persistent objects could be defined in any of the following ways: •
ABAP classes (implementing IF_WORKFLOW) –
TYPE SIBFLPORB The object is passed using its persistent representation
–
TYPE REF TO The object is passed as object handle
•
BOR objects –
TYPE SIBFLPORB The object is passed using its persistent representation
–
TYPE SWOTOBJID the object is passed using its persistent representation that is only valid for BOR objects Caution: Using one of the persistent object reference (POR) structures will lead to parameters with an unspecified object type. However, when one of the POR structures is used, the persistent reference can be typed using initial values. There are more options to type a persistent object reference if these methods are used in tasks. When defining a task that calls this method, the method parameters are replicated into the task container. In that case, edit the task container and change the object type of this parameter (element) to the concrete object type you need. When you integrate this task into a workflow step later, the workflow builder will “see” only the correctly typed element in your task container. This way, you can make sure that only objects of a specific type can be passed to the task (and hence to the method) through data binding in the workflow.
62
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Figure 29: Implementing the Return of Results
In defining BOR methods there is also a technique called “Return of Results”. Result parameters have an influence on the use of methods in workflow steps: If the result parameter is defined with a data reference on a fixed value domain (such as CHAR1 with the fixed values “A”, “B” and “C”), the modeler receives three outputs with the name “A”, “B” and “C” in the Workflow Builder for the new step when he or she incorporates a step based on this method. When processing the workflow, the system always specifically selects the output that returns the method as a value for the result parameter. To implement this feature please define a “Returning” parameter in method interface that contains a domain with an explicit maintained value range (see also table field SWXFORMABS-PROCSTATE with domain SWX_PROCST).
2008
© 2008 SAP AG. All rights reserved.
63
Unit 2: ABAP Classes Definition and Implementation
64
© 2008 SAP AG. All rights reserved.
BIT611
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Exercise 2: Create Attributes for Workflow Class Exercise Objectives After completing this exercise, you will be able to: • Define attributes with different references
Business Example Your company has developed some add-ons to the standard business scenarios of the SAP ERP system. These extensions are implemented in ABAP Objects. To get experience with the techniques of inserting these functions in workflow architecture, someone has to test the possibilities. Your have the task of creating some ABAP class functions as examples for your colleagues. We want to create functions like these encapsulated in the BOR object type BUS1001006. Hint: Please be aware that you have to be an experienced developer to implement all following functions in the given exercise time. You could also copy some coding from the example implementation of class ZBIT611_MARA. Please use this possibility if you do not have enough time or you are not an experienced developer.
Task: To take advantage of class functions in the workflow architecture, you have to implement some different types of attributes in your implementation. Please insert some attributes with database and object reference and an attribute that refers to a list of purchase orders (also object references). Caution: If you create the following class, you may see a warning like “Implementation missing for method "BI_OBJECT~RELEASE" . . ”. If so, please go into method implementation of called function and insert a line with a space between METHOD ... . and ENDMETHOD. and save the method. 1.
Create a read_attributes method in your class to set all necessary attributes to handle within your class:
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
65
Unit 2: ABAP Classes Definition and Implementation
BIT611
- MATERIALGROUP - MATERIALTYPE - INDUSTRY - LABOR Insert a call of this method in the BI_PERSISTENT~REFRESH method. 2.
Create a set_description method to set a default attribute like the one in business object types. It should contain the material number and the text (table MAKT). To use this attribute, insert a call of it in the BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE method.
3.
To execute the above developed methods at the right time (for workflow engine), you have to call it in the CONSTRUCTOR method.
4.
Create a (virtual, single-line) get_actual_date attribute (functional method) to get the actual date and time when the virtual attribute is called from workflow engine. Use the class CL_BSP_UTILITY for this purpose.
5.
OPTIONAL: Create a set_formabsenc method to set the result of a class attribute points to a reference of class CL_SWF_FORMABSENC.
6.
OPTIONAL: Create a set_purchaseorder method to set the result of a class attribute points to a list of object references of object type BUS2012.
7.
66
Test your implementation by using the “Test” button (F8).
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Solution 2: Create Attributes for Workflow Class Task: To take advantage of class functions in the workflow architecture, you have to implement some different types of attributes in your implementation. Please insert some attributes with database and object reference and an attribute that refers to a list of purchase orders (also object references). Caution: If you create the following class, you may see a warning like “Implementation missing for method "BI_OBJECT~RELEASE" . . ”. If so, please go into method implementation of called function and insert a line with a space between METHOD ... . and ENDMETHOD. and save the method. 1.
Create a read_attributes method in your class to set all necessary attributes to handle within your class: - MATERIALGROUP - MATERIALTYPE - INDUSTRY - LABOR Insert a call of this method in the BI_PERSISTENT~REFRESH method. a)
To change your class, navigate to the class builder:Tools → Business Workflow → Development → Definition Tools → Application Integration → Class Builder (SE24) Insert the class name ZBIT611_## and press the “Change” button.
b)
Go to the tab “Attributes” and insert a new line with the following properties: Attribute:
MATERIALGROUP
Level:
Instance Attribute
Visibility:
Public
Key Attribute:
-> no entry
Read-Only:
'X'
Typing:
Type Continued on next page
2008
© 2008 SAP AG. All rights reserved.
67
Unit 2: ABAP Classes Definition and Implementation
BIT611
Associated Type:
MARA-MATKL
Description:
-> set automatically
Initial Value:
-> not required
Attribute:
MATERIALTYPE
Level:
Instance Attribute
Visibility:
Public
Key Attribute:
-> no entry
Read-Only:
'X'
Typing:
Type
Associated Type:
MARA-MTART
Description:
-> set automatically
Initial Value:
-> not required
Attribute:
INDUSTRY
Level:
Instance Attribute
Visibility:
Public
Key Attribute:
-> no entry
Read-Only:
'X'
Typing:
Type
Associated Type:
MARA-MBRSH
Description:
-> set automatically
Initial Value:
-> not required
Attribute:
LABOR
Level:
Instance Attribute
Visibility:
Public
Key Attribute:
-> no entry
Read-Only:
'X'
Typing:
Type
Associated Type:
MARA-LABOR
Description:
-> set automatically
Initial Value:
-> not required Continued on next page
68
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Save your class (Ctrl + S). c)
Go to the tab “Methods” and insert following entries in new line: Method:
READ_ATTRIBUTES
Level:
Instance Method
Visibility:
Private
Method type:
-> no entry
Description:
Read attributes from database tables
Save your class (Ctrl + S). d)
Double-click the READ_ATTRIBUTES method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD read_attributes. SELECT SINGLE * FROM mara INTO m_mara WHERE matnr = me->matnr. me->materialgroup
= me->m_mara-matkl.
me->materialtype
= me->m_mara-mtart.
me->industry
= me->m_mara-mbrsh.
me->labor
= me->m_mara-labor.
ENDMETHOD.
Save your class (Ctrl + S). e)
Go to the tab “Methods” and double click the BI_PERSISTENT~REFRESH method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD bi_persistent~refresh. read_attributes( ). ENDMETHOD.
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
69
Unit 2: ABAP Classes Definition and Implementation
BIT611
Save your class (Ctrl + S). 2.
Create a set_description method to set a default attribute like the one in business object types. It should contain the material number and the text (table MAKT). To use this attribute, insert a call of it in the BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE method. a)
Go to the tab “Attributes” and insert a new line with the following properties: Attribute:
M_MAKT
Level:
Instance Attribute
Visibility:
Private
Key Attribute:
-> no entry
Read-Only:
-> no entry
Typing:
Type
Associated Type:
MAKT
Description:
-> set automatically
Initial Value:
-> not required
Attribute:
DESCRIPTION
Level:
Instance Attribute
Visibility:
Public
Key Attribute:
-> no entry
Read-Only:
'X'
Typing:
Type
Associated Type:
SYST-TITLE
Description:
-> set automatically
Initial Value:
-> not required
Save your class (Ctrl + S). b)
Go to the tab “Methods” and insert following entries in new line:
Continued on next page
70
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Method:
SET_DESCRIPTION
Level:
Instance Method
Visibility:
Private
Method type:
-> no entry
Description:
Set description
Save your class (Ctrl + S). c)
Double-click the SET_DESCRIPTION method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD set_description.
* call table makt and m_makt SELECT SINGLE * FROM makt INTO m_makt WHERE spras = sy-langu AND matnr = matnr. * load field maktx of structure m_makt into class attribute description CONCATENATE 'Text zu' matnr ':' m_makt-maktx INTO description SEPARATED BY space.
ENDMETHOD.
Save your class (Ctrl + S). d)
Go to the tab “Methods” and double-click the BI_OBJECT~DEFAULT_ATTRIBUTE_VALUE method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD bi_object~default_attribute_value. GET REFERENCE OF description INTO result. ENDMETHOD.
Save your class (Ctrl + S) and activate it.
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
71
Unit 2: ABAP Classes Definition and Implementation
3.
BIT611
To execute the above developed methods at the right time (for workflow engine), you have to call it in the CONSTRUCTOR method. a)
Double-click the CONSTRUCTOR method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. me->read_attributes( ).
me->set_description( ).
Save and activate your class (Ctrl + S). 4.
Create a (virtual, single-line) get_actual_date attribute (functional method) to get the actual date and time when the virtual attribute is called from workflow engine. Use the class CL_BSP_UTILITY for this purpose. a)
Go to the tab “Methods” and insert following entries in new line: Method:
GET_ACTUAL_DATE
Level:
Instance Method
Visibility:
Public
Method type:
-> no entry
Description:
Get actual date (as virtual attribute)
Save your class (Ctrl + S). b)
Press the “Parameters” button and insert a new line with the following properties: Parameter:
EX_ACTUAL_DATE
Type:
Returning
Pass Value:
-> set automatically
Optional:
-> set automatically
Typing Method:
Type
Continued on next page
72
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Associated Type:
STRING
Default Value:
-> set automatically
Description:
-> set automatically
Save your class (Ctrl + S). c)
Double-click the GET_ACTUAL_DATE method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD get_actual_date. DATA: lref_bsp_utility TYPE REF TO cl_bsp_utility, lv_timestamp
TYPE char14,
lv_result
TYPE string.
CONCATENATE sy-datum sy-uzeit INTO lv_timestamp. CALL METHOD cl_bsp_utility=>date_to_string_http EXPORTING timestamp = lv_timestamp RECEIVING result
= lv_result.
actual_date = lv_result. ENDMETHOD.
Save your class (Ctrl + S). 5.
OPTIONAL: Create a set_formabsenc method to set the result of a class attribute points to a reference of class CL_SWF_FORMABSENC. a)
Go to the tab “Methods” and insert following entries in new line:
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
73
Unit 2: ABAP Classes Definition and Implementation
BIT611
Method:
SET_FORMABSENC
Level:
Instance Method
Visibility:
Private
Method type:
-> no entry
Description:
Set object reference of class CL_SWF_FORMABSENC
Save your class (Ctrl + S). b)
Go to the tab “Attributes” and insert a new line with the following properties: Attribute:
FORMABSENC
Level:
Instance Attribute
Visibility:
Public
Key Attribute:
-> no entry
Read-Only:
'X'
Typing:
Type Ref To
Associated Type:
CL_SWF_FORMABSENC
Description:
-> set automatically
Initial Value:
-> not required
Save your class (Ctrl + S). c)
Double-click the SET_FORMABSENC method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD set_formabsenc.
* Local Data DATA l_formabsenc TYPE REF TO cl_swf_formabsenc.
* Create Object Reference TRY. CREATE OBJECT l_formabsenc EXPORTING im_number
= '0000004980'
.
Continued on next page
74
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
CATCH cx_bo_error . EXIT. ENDTRY. * Fill class attribute formabsenc = l_formabsenc. ENDMETHOD.
Save your class (Ctrl + S). d) 6.
Insert the just created method in the CONSTRUCTOR method.
OPTIONAL: Create a set_purchaseorder method to set the result of a class attribute points to a list of object references of object type BUS2012. a)
Go to the tab “Attributes” and insert a new line with the following properties: Attribute:
PURCHASEORDER
Level:
Instance Attribute
Visibility:
Public
Key Attribute:
-> no entry
Read-Only:
'X'
Typing:
Type
Associated Type:
SWFBORPTAB
Description:
-> set automatically
Initial Value:
-> not required
Save your class (Ctrl + S). b)
Go to the tab “Methods” and insert following entries in new line:
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
75
Unit 2: ABAP Classes Definition and Implementation
BIT611
Method:
SET_PURCHASEORDER
Level:
Instance Method
Visibility:
Private
Method type:
-> no entry
Description:
Set object references of object type BUS2012
Save your class (Ctrl + S). c)
To get all functions referring to the macro language used to handle business object types, you have to insert the following lines: Hint: In the “Local types” section of your class, under Goto -> Class-local types -> Local class implementations, you need the line: INCLUDE . In the “Macros” section of your class, under Goto -> Class-local types -> Macros, you need the line: INCLUDE .
d)
Double-click the SET_PURCHASEORDER method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD set_purchaseorder. DATA: lref_porder TYPE swc_object, lt_tekdoc
TYPE STANDARD TABLE OF ekdoc,
ls_tekdoc
TYPE ekdoc,
lv_werks
TYPE ekpo-werks.
DATA: lt_porder ls_porder
TYPE swfborptab, TYPE swotobjid VALUE '
BUS2012'.
CLEAR lv_werks.
CALL FUNCTION 'ME_CHECK_DOCUMENT_FOR_MATERIAL' EXPORTING *
EXISTENCE_CHECK
= ' '
matnr *
PLANT_INITIAL
= matnr = ' '
Continued on next page
76
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
werks
= lv_werks
*
PLANT_INFO
= ' '
*
BWART
=
*
BWKEY
=
*
NO_ACCOUNT_ASSIGNED
= ' '
*
BMATN
=
*
MPROF
=
*
IF_SOBKZ
=
*
IF_VBELN
=
*
IF_VBELP
=
*
IF_PSPNR
=
* IMPORTING *
CONTRACT_FLAG
=
*
DELPLAN_FLAG
=
*
INFO_FLAG
=
*
PO_FLAG
=
*
REQ_FLAG
=
*
RFQ_FLAG
=
TABLES xekdoc
= lt_tekdoc
EXCEPTIONS OTHERS. . LOOP AT lt_tekdoc INTO ls_tekdoc WHERE bstyp = 'F'.
swc_create_object lref_porder 'BUS2012' ls_tekdoc-ebeln. swc_object_to_persistent lref_porder ls_porder. APPEND ls_porder TO lt_porder.
ENDLOOP. purchaseorder = lt_porder. ENDMETHOD.
Save your class (Ctrl + S). Caution: The Default Value of “LS_PORDER” should have 10 spaces before the object type name (see also description in the previous lesson). Continued on next page
2008
© 2008 SAP AG. All rights reserved.
77
Unit 2: ABAP Classes Definition and Implementation
e) 7.
BIT611
Insert the just created method in the CONSTRUCTOR method.
Test your implementation by using the “Test” button (F8). a)
Press “Test” Button (F8).
b)
Enter the material “R-1003” in the field IM_MATNR and press the “Instance” button.
c)
A screen should be displayed where you see the interfaces “BI_OBJECT”, “BI_PERSISTENT” and “IF_WORKFLOW”. It should also show the above developed attributes.
78
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Exercise 3: Create Methods for Workflow Class Exercise Objectives After completing this exercise, you will be able to: • Define methods with import and export parameters
Business Example Your company has developed some add-ons to the standard business scenarios of the SAP ERP system. These extensions are implemented in ABAP Objects. To gain experience with the techniques of inserting these functions in workflow architecture, someone has to test the possibilities. You have the task of creating some ABAP class functions as examples for your colleagues. We want to create functions like those encapsulated in the BOR object type BUS1001006. Hint: Please be aware that you have to be an experienced developer to implement all following functions in the given exercise time. You could also copy some coding from the example implementation of class ZBIT611_MARA. Please use this possibility if you do not have enough time or you are not an experienced developer.
Task: To handle the basic functions of an object used in the workflow architecture, create in the some “ExistenceCheck” and “Display” methods. The last part of this exercise should be the implementation of some methods with import and export parameters. Caution: If you create the following class, you may see a warning like “Implementation missing for method "BI_OBJECT~RELEASE" . . ”. If so, please go into method implementation of called function and insert a line with a space between METHOD ... . and ENDMETHOD. and save the method. 1.
Create an “ExistenceCheck” method to validate the key structure, given from the workflow engine. It is only the call of main application table for business scenario and should not have other code. Continued on next page
2008
© 2008 SAP AG. All rights reserved.
79
Unit 2: ABAP Classes Definition and Implementation
2.
BIT611
Create a “Display” method to display application data with the functionality of BAPI_MATERIAL_DISPLAY. To implement the behavior of the default method, insert a call of this method in BI_OBJECT~EXECUTE_DEFAULT_METHOD method.
3.
Create a “DisplayView” method with the Import Parameter “MaterialView” to display special application data. Use transaction MM03 and the necessary SET/GET parameter.
4.
Create a “Change” method to change application data. Use transaction MM02 and necessary SET/GET parameter.
5.
Test your implementation by using the “Test” button (F8).
6.
OPTIONAL Create a “Create” method with interface BAPI_STANDARDMATERIAL_CREATE. This is a static function, that means, it works without instance.
7.
OPTIONAL You could also test some of your developed functions in standard task. Yet, this is part of last exercise of this course.
80
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Solution 3: Create Methods for Workflow Class Task: To handle the basic functions of an object used in the workflow architecture, create in the some “ExistenceCheck” and “Display” methods. The last part of this exercise should be the implementation of some methods with import and export parameters. Caution: If you create the following class, you may see a warning like “Implementation missing for method "BI_OBJECT~RELEASE" . . ”. If so, please go into method implementation of called function and insert a line with a space between METHOD ... . and ENDMETHOD. and save the method. 1.
Create an “ExistenceCheck” method to validate the key structure, given from the workflow engine. It is only the call of main application table for business scenario and should not have other code. a)
Go to the tab “Methods” and insert following entries in new line: Method:
EXISTENCECHECK
Level:
Instance Method
Visibility:
Public
Method type:
-> no entry
Description:
Existence Check to verify data from workflow engine
To handle the raised exceptions, insert exception “CX_BO_ERROR” in the exception list of the EXISTENCECHECK method (tab “Exceptions”). Exceptions are theme of chapter 3, however it is necessary to handle a failed constructor method. Please insert the information as described and wait for an explanation until chapter 3. Save your class (Ctrl + S). b)
Double-click the EXISTENCECHECK method. Implement the coding as shown in the following example. Continued on next page
2008
© 2008 SAP AG. All rights reserved.
81
Unit 2: ABAP Classes Definition and Implementation
BIT611
If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD existencecheck. SELECT SINGLE * FROM mara INTO m_mara WHERE matnr = me->matnr. IF sy-subrc NE 0. RAISE EXCEPTION TYPE cx_bo_error. ENDIF. ENDMETHOD.
Save your class (Ctrl + S). c)
Call EXISTENCECHECK method in the CONSTRUCTOR method:
METHOD constructor. * assignment of import variable to key field of class matnr = im_matnr. TRY. CALL METHOD me->existencecheck. CATCH cx_bo_error. EXIT. ENDTRY. ... ENDMETHOD.
Save your class (Ctrl + S). 2.
Create a “Display” method to display application data with the functionality of BAPI_MATERIAL_DISPLAY. To implement the behavior of the default method, insert a call of this method in BI_OBJECT~EXECUTE_DEFAULT_METHOD method. a)
Go to the tab “Methods” and insert following entries in new line: Continued on next page
82
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Method:
DISPLAY
Level:
Instance Method
Visibility:
Public
Method type:
-> no entry
Description:
Display application data
Save your class (Ctrl + S). b)
c)
Press the “Parameters” Button and insert the following properties into the first line: Parameter:
EX_RETURN
Type:
Exporting
Pass Value:
-> no entry
Optional:
'X'
Typing Method:
Type
Associated Type:
BAPIRET1
Default Value:
-> not required
Description:
-> set automatically
Double-click the DISPLAY method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD display.
CALL FUNCTION 'BAPI_MATERIAL_DISPLAY' EXPORTING material = matnr IMPORTING return
= ex_return.
CASE ex_return-number. * DUMMY ENDCASE. ENDMETHOD.
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
83
Unit 2: ABAP Classes Definition and Implementation
BIT611
Save your class (Ctrl + S). d)
Go to the tab “Methods” and double-click the BI_OBJECT~EXECUTE_DEFAULT_METHOD method. Implement the coding as shown in the following example. The exception class cx_root handles all exceptions from method display and communicates them to the workflow engine. It has not to be inserted into interface of BI_OBJECT~EXECUTE_DEFAULT_METHOD. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD bi_object~execute_default_method. TRY. display( ). CATCH cx_root. ENDTRY. ENDMETHOD.
Save your class (Ctrl + S) and activate it. 3.
Create a “DisplayView” method with the Import Parameter “MaterialView” to display special application data. Use transaction MM03 and the necessary SET/GET parameter. a)
Go to the tab “Methods” and insert following entries in a new line: Method:
DISPLAYVIEW
Level:
Instance Method
Visibility:
Public
Method type:
-> no entry
Description:
Display application data with Import Parameter MaterialView
Save your class (Ctrl + S). b)
84
Press the “Parameters” Button and insert the following properties into the first line: Continued on next page
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
c)
Parameter:
IM_MATERIALVIEW
Type:
Importing
Pass Value:
-> no entry
Optional:
'X'
Typing Method:
Type
Associated Type:
T132T-STATM
Default Value:
'K'
Description:
-> set automatically
If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD displayview.
SET PARAMETER ID 'MAT' FIELD matnr. SET PARAMETER ID 'MXX' FIELD im_materialview.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN. ENDMETHOD.
Save your class (Ctrl + S).
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
85
Unit 2: ABAP Classes Definition and Implementation
4.
BIT611
Create a “Change” method to change application data. Use transaction MM02 and necessary SET/GET parameter. a)
Go to the tab “Methods” and insert following entries in a new line: Method:
CHANGE
Level:
Instance Method
Visibility:
Public
Method type:
-> no entry
Description:
Change application data
Save your class (Ctrl + S). b)
Double-click the CHANGE method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD change. SET PARAMETER ID 'MAT' FIELD matnr. CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN. ENDMETHOD.
Save your class (Ctrl + S). 5.
Test your implementation by using the “Test” button (F8). a)
Press the “Test” button (F8).
b)
A screen should be displayed where you see only the “CREATE” method.
c)
Click the “Instance” button and enter the material “R-1003” in the field IM_MATNR and press the “Instance” button.
d)
A screen should be displayed where you see the interfaces “BI_OBJECT”, “BI_PERSISTENT” and “IF_WORKFLOW”. Also, it should display the above developed attributes. Lastly, it should display the variety of methods, that you can test: “EXISTENCECHECK”, “DISPLAY”, “DISPLAYVIEW”, and so on. Continued on next page
86
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
6.
OPTIONAL Create a “Create” method with interface BAPI_STANDARDMATERIAL_CREATE. This is a static function, that means, it works without instance. a)
Go to the tab “Methods” and insert following entries in a new line: Method:
CREATE
Level:
Static Method
Visibility:
Public
Method type:
-> no entry
Description:
Create Material
Save your class (Ctrl + S). b)
c)
Press the “Parameters” button and insert the following properties into the first line: Parameter:
EX_RETURN
Type:
Exporting
Pass Value:
-> no entry
Optional:
'X'
Typing Method:
Type
Associated Type:
BAPIRET1
Default Value:
-> not required
Description:
-> set automatically
Double-click the CREATE method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD create.
CALL FUNCTION 'BAPI_STANDARDMATERIAL_CREATE' IMPORTING material = ex_newmaterial return
= ex_return.
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
87
Unit 2: ABAP Classes Definition and Implementation
BIT611
CASE ex_return-number.
* DUMMY ENDCASE. ENDMETHOD.
Save your class (Ctrl + S). 7.
OPTIONAL You could also test some of your developed functions in standard task. Yet, this is part of last exercise of this course.
88
a)
Create some standard tasks with transaction “PFTC”.
b)
Test the created standard tasks with transaction “SWUS”.
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Class Definition - Attributes and Methods
Lesson Summary You should now be able to: • Define attributes with a database reference • Define “virtual attributes”, like values • Define multiline attributes • Describe how object references are addressed in the BOR and the workflow
2008
© 2008 SAP AG. All rights reserved.
89
Unit Summary
BIT611
Unit Summary You should now be able to: • Explain the basic technical concepts of ABAP Object classes in SAP Business Workflow • Classify some important concepts of object-oriented programming • Create a class • Create instance handling required for workflow engine • Define key fields • Define attributes with a database reference • Define “virtual attributes”, like values • Define multiline attributes • Describe how object references are addressed in the BOR and the workflow
90
© 2008 SAP AG. All rights reserved.
2008
Unit 3 Use Classes in Workflow Architecture Unit Overview This unit shows additional concepts for controlling processes in Business Process Management like Exception Handling in class methods and Event Handling in relation to the object oriented paradigm of ABAP classes. It shows the consequences of these techniques for the process flow and gives you hints about the most important aspects you have to know in building workflow with ABAP classes.
Unit Objectives After completing this unit, you will be able to: • • • • • •
Understand the exception techniques in workflow classes and their handling in the workflow engine Define events and trigger them to start processes Use API functions to affect workflow functions based on classes Define and start single-step tasks and multistep tasks Explain and define bindings within a multistep task Use class components in workflow architecture
Unit Contents Lesson: Exceptions, Events and API Functions ............................. 92 Exercise 4: Create Exception and Event Handling for Classes ......101 Lesson: Using Classes in Workflow Architecture........................... 110 Exercise 5: Create and Test Workflow Functions with ABAP Classes ...................................................................... 119
2008
© 2008 SAP AG. All rights reserved.
91
Unit 3: Use Classes in Workflow Architecture
BIT611
Lesson: Exceptions, Events and API Functions Lesson Overview There are some additional techniques to control processes in the workflow engine. In this lesson, we discuss the class “Exception Handling”, the “Events” in classes and the necessary areas to use class API functions.
Lesson Objectives After completing this lesson, you will be able to: • • •
Understand the exception techniques in workflow classes and their handling in the workflow engine Define events and trigger them to start processes Use API functions to affect workflow functions based on classes
Business Example You have to implement some additional techniques in your material master process to control its flow. To do this, you have to understand the “Exception Handling”, “Event Handling” with ABAP classes and the technique to set container values with new programming API.
Exceptions in Methods Methods might also have exceptions that report errors to the caller. The workflow engine is able to handle these exceptions. In general, the engine can distinguish between temporary exceptions (for example, object is locked) and application exceptions that report “permanent” errors. Depending on the kind of exception, the system behaves differently: • •
For BOR-Object types, the type of exception (temporary or application exception) can be defined using the Business Object Builder For ABAP classes, the different types of exception are based on either the exception class hierarchy or on naming conventions.
An exception is triggered directly for all error types (temporary, application or system errors), using the method exceptions in the class builder and entering the “RAISE EXCEPTION TYPE” statement. To define customer based exceptions, it is also possible to create own exception classes by subclassing the class-based workflow exceptions (for example CX_BO_TEMPORARY).
92
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Exceptions, Events and API Functions
Figure 30: Reaction to Exception - Dialog Steps
In the object method, exceptions are defined as temporary exceptions, as application errors, or as system errors. If a subsequent step is modeled in the workflow definition for this exception, this step is executed. If no subsequent step is modeled, the workflow assumes an error status for application errors and system errors, and for temporary errors, the workflow remains in the status “in process”.
Figure 31: Reaction to Exception - Background Steps
Background steps also allow you to model a repeat counter for a temporary error.
2008
© 2008 SAP AG. All rights reserved.
93
Unit 3: Use Classes in Workflow Architecture
BIT611
If this repeat counter is modeled, the step is automatically repeated, for the number of times specified in the definition, whenever a temporary error occurs. The step switches permanently to either “error” or “completed” status (followed by the modeled subsequent step) only when this number of repetitions is complete. The repetition is implemented by a background job (SWWERRE). The background job must be scheduled to allow the repetition to be carried out if temporary errors occur.
Figure 32: Handle Exceptions from ABAP Classes
Class-Based Exceptions Class-based exceptions can be used for methods. At runtime, the workflow engine will catch the thrown exceptions and treat them as application exceptions. To raise temporary exceptions, you can use the exception class CX_BO_TEMPORARY and its subclasses. All exceptions of this class and the subclasses are handled as temporary exceptions. Therefore, it is also possible to create your own exception classes for temporary exceptions by subclassing CX_BO_TEMPORARY. For dialog methods, it might be useful to raise an exception if the user cancels the dialog (as a temporary exception). In this case, you can use CX_BO_ACTION_CANCELLED (subclass of CX_BO_TEMPORARY) to raise this specific exception. Non Class-Based Exceptions
94
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Exceptions, Events and API Functions
Non class-based exceptions could also be used for methods. These exceptions will also be caught by the engine. Like above, these exceptions will be handled as application exceptions. To raise temporary exceptions, the name of an exception has to start with TMP or TEMP. For dialog methods it might be useful to raise an exception if the user cancels the dialog (as a temporary exception). In this case, you can use TMP_EXIT_CANCELLED or TEMP_EXIT_CANCELLED to raise this specific exception.
Handling Events The workflow engine makes use of an event manager that handles events and calls the corresponding receivers (for example, processes, that should be started or steps within a process that should be completed). These events are triggered by calling the Event Manager API. The events are handled asynchronously and the receivers are started in their own LUW (Logical Unit of Work). The sender and receiver of the event do not need to reside on the same logical system.
Figure 33: Basic logic to trigger Events
ABAP classes can also define events that are used to communicate between ABAP objects residing in the same context (roll area). These events, which are triggered using built-in ABAP statements, and the previously mentioned events handled by the event manager, are completely different. If an event is triggered by the following ABAP objects command, this has no significance for the event manager: RAISE EVENT EXPORTING... = ...
2008
© 2008 SAP AG. All rights reserved.
95
Unit 3: Use Classes in Workflow Architecture
BIT611
Figure 34: Event Handling in Classes
Nevertheless, public events that are defined at a class could also be used to trigger events for the workflow engine. To achieve this, an event handler in an ABAP program code would have to make explicit calls to the workflow system’s event manger through its API, thus dispatching a local ABAP event to a workflow event. It is also possible to use event parameters to pass values to possible event handlers. However, because the workflow event manager uses RFC to dispatch its events, restrictions concerning data types apply: • • •
event parameters are restricted to simple types (for example, string, integer, and so on) any possible ABAP dictionary types (for example, structures, tables, complex types) BOR object references or references to ABAP classes that implement the interface IF_WORKFLOW
The following sections describe how events can be triggered via the workflow event manager API. Since the handlers will be started in their own LUW using a tRFC, a COMMIT WORK is always required to actually start the receivers. This section describes how static methods could be used to trigger an event. Before the event is triggered, the corresponding value for the event parameter is set. The handling of event parameters is optional. Triggering Events Via Static Methods *- begin of local data DATA: l_event_parameters TYPE REF TO if_swf_ifs_parameter_container. *- begin of local data
96
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Exceptions, Events and API Functions
TRY.
*--- get the event container that is used to transport the event parameters CALL METHOD cl_swf_evt_event=>get_event_container EXPORTING im_objcateg
= ‘CL‘
“category for classes
im_objtype
= ‘CL_DEMO_CLASS‘
“the classname
im_event
= ‘CHANGED‘
“event that will be triggerd
RECEIVING re_reference
= l_event_parameters.
*--- set the values of the parameters CALL METHOD l_event_parameters->set EXPORTING name
= ‘USER‘
“the name of the event parameter
value
= sy-uname.
“the value
*--- raise the event CALL METHOD cl_swf_evt_event=>raise EXPORTING im_objcateg
= ‘CL‘
“category for classes
im_objtype
= ‘CL_DEMO_CLASS‘
“the classname
im_event
= ‘CHANGED‘
“the event name
im_objkey
= ‘…‘
“the obj.-key (instid)
im_event_container
= l_event_parameters. “the event params
*--- start the receivers (tRFC) COMMIT WORK.
CATCH cx_swf_evt_exception. “except. while raising the event CATCH cx_swf_cnt_container. “except. while setting event params
ENDTRY.
Raising an event without COMMIT WORK will not start any receiver. If the event is triggered within a transaction, the COMMIT WORK of the running transaction can (and should) be used. The following event definition is used to show the mechanism of dispatching an ABAP event to a workflow event manger event. The example also shows the mechanism for passing event parameters. This section gives an example of how to raise the same event using instance methods. It is up to the user weather to use static or instance methods. There is no difference between these possibilities. Trigger Events Using Instance Methods
2008
© 2008 SAP AG. All rights reserved.
97
Unit 3: Use Classes in Workflow Architecture
BIT611
*- begin of local data DATA: l_event_parameters TYPE REF TO if_swf_ifs_parameter_container. DATA: l_event
TYPE REF TO if_swf_evt_event.
*- end of local data
TRY. *--- get an event object CALL METHOD cl_swf_evt_event=>get_instance EXPORTING im_objcateg
= ‘CL‘
“category for classes
im_objtype
= ‘CL_DEMO_CLASS‘
“the classname
im_event
= ‘CHANGED‘
“event that will be triggerd
im_objkey
= ‘…‘
“the object-key (instid)
RECEIVING re_event
= l_event.
*--- get the event container to set the parameters l_event_parameters
= l_event->get_event_container( ).
*--- set the values of the parameters CALL METHOD l_event_parameters->set EXPORTING name
= ‘USER‘
“the name of the event parameter
value
= sy-uname.
“the value
*--- raise the event CALL METHOD l_event->raise. *--- start the receivers (tRFC) COMMIT WORK. CATCH cx_swf_evt_exception. “exception while raising the event CATCH cx_swf_cnt_container. “exception while setting event params ENDTRY.
98
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Exceptions, Events and API Functions
Note that events say something about object status changes that have actually occurred. Therefore, ensure that the event is not created until the relevant status change has taken place. To do this, call the method for creating an event in the same logical unit of work (LUW) that the status change is made in. •
Interface IF_SWF_IFS_PARAMETER_CONTAINER To set the event parameters, use the IF_SWF_IFS_PARAMETER_CONTAINER interface. Use the SET method of this interface to set the relevant parameters. Use the TRY ... ENDTRY instruction to catch the exceptions cx_swf_evt_execption (error in event creation) and cx_swf_cnt_container (error in setting a parameter).
•
Class CL_SWF_EVT_EVENT The ABAP class CL_SWF_EVT_EVENT has two methods, RAISE and RAISE_IN_UPDATE_TASK, which behave in the same way as the function modules SWE_EVENT_CREATE and SWE_EVENT_CREATE_FOR_UPD_TASK.
Parameter Container Interface Programming with containers always meant manipulating internal tables of structure SWCONT using container macros. To overcome the limitations of the old container implementation, a new, ABAP Objects based programming model has been developed. In this new programming model, the container is represented as an ABAP Object reference of type IF_SWF_IFS_PARAMETER_CONTAINER. SWCONT has not disappeared everywhere (for example, it is still used when programming BOR methods) but some APIs already use the above interface and more of them will follow. IF_SWF_IFS_PARAMETER_CONTAINER contains the following methods:
2008
© 2008 SAP AG. All rights reserved.
99
Unit 3: Use Classes in Workflow Architecture
BIT611
Figure 35: Parameter Container Interface
The new container interface could used in, as example, check function modules, to develop BOR methods, triggering events in customer specific programming, and so on. See the new interface implementation in some programming examples: • • •
FB sww_wi_create_via_event_ibf (receiver function module for standard wf) FB swb_2_check_fb_start_cond_eval (check function module) FB swe_event_create (function module to generate an event)
Figure 36: Examples for Using New Interface
100
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Exceptions, Events and API Functions
Exercise 4: Create Exception and Event Handling for Classes Exercise Objectives After completing this exercise, you will be able to: • Define exception and event handling for classes
Business Example Your company has developed some add-ons to the standard business scenarios of the SAP ERP system. These extensions are implemented in ABAP Objects. To gain experience with the techniques of inserting these functions in workflow architecture, someone has to test the possibilities. You have the task of creating some ABAP class functions as examples for your colleagues. We want to create functions like those encapsulated in the BOR object type BUS1001006. Hint: Please be aware that you have to be an experienced developer to implement all following functions in the given exercise time. You could also copy some coding from the example implementation of class ZBIT611_MARA. Please use this possibility if you do not have enough time or you are not an experienced developer.
Task: To handle the basic functions of an object used in workflow architecture, you have created some methods in the last exercise. To check some important function results, it has to be implemented an exception handling in the previously developed methods. There should also be some workflow events triggered, when business content is created or changed. 1.
Please realize the exception handling of ExistenceCheck and Constructor method implemented in the previous exercises.
2.
The return codes of BAPI_MATERIAL_DISPLAY in the method Display should be handled from workflow engine.
3.
OPTIONAL The return codes of BAPI_STANDARDMATERIAL_CREATE in the method Create should be handled from the workflow engine. Continued on next page
2008
© 2008 SAP AG. All rights reserved.
101
Unit 3: Use Classes in Workflow Architecture
BIT611
4.
To define customer specific time points for the process, create two additional events; one for the change of field Basic Material and one for the change of field Old Material.
5.
OPTIONAL To make the creation of a new material public, you have to implement a triggering event “CREATED” in the Create method. It should be include a parameter “User”.
6.
102
Test your implementation by using the “Test” button (F8).
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Exceptions, Events and API Functions
Solution 4: Create Exception and Event Handling for Classes Task: To handle the basic functions of an object used in workflow architecture, you have created some methods in the last exercise. To check some important function results, it has to be implemented an exception handling in the previously developed methods. There should also be some workflow events triggered, when business content is created or changed. 1.
Please realize the exception handling of ExistenceCheck and Constructor method implemented in the previous exercises. a)
These implemented exceptions handle the general behavior of class in workflow context, if no business object is available to the given key. If you want to compare your coding, call the implementation of class ZBIT611_MARA.
2.
The return codes of BAPI_MATERIAL_DISPLAY in the method Display should be handled from workflow engine. a)
To handle the raised exceptions, insert exceptions “CX_BO_ERROR” and “CX_BO_ACTION_CANCELLED” in the exceptions list of the method (tab “Exceptions”). Save your class (Ctrl + S).
b)
Double-click the DISPLAY method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD display. ...
CASE ex_return-number. WHEN '000'. * material is displayed
WHEN '262'.
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
103
Unit 3: Use Classes in Workflow Architecture
BIT611
RAISE EXCEPTION TYPE cx_bo_error EXPORTING textid = 'No materialnumber transfered.'. WHEN '305'.
RAISE EXCEPTION TYPE cx_bo_error EXPORTING textid = 'Material not existing.'.
WHEN OTHERS. RAISE EXCEPTION TYPE cx_bo_error EXPORTING textid = 'Other Error'. ENDCASE.
ENDMETHOD.
Save your class (Ctrl + S). c) 3.
Save your class (Ctrl + S) and activate it.
OPTIONAL
Continued on next page
104
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Exceptions, Events and API Functions
The return codes of BAPI_STANDARDMATERIAL_CREATE in the method Create should be handled from the workflow engine. a)
To handle the raised exceptions, insert exceptions “CX_BO_ERROR” and “CX_BO_ACTION_CANCELLED” in the exceptions list of the method (tab “Exceptions”). Save your class (Ctrl + S).
b)
Double-click the CREATE method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD create. ... CASE ex_return-number.
WHEN '000'. WHEN '355'. RAISE EXCEPTION TYPE cx_bo_action_cancelled EXPORTING textid = 'No material has been created.'. when '356'.
* material is created WHEN OTHERS. RAISE EXCEPTION TYPE cx_bo_error EXPORTING textid = 'other'. ENDCASE. ENDMETHOD.
Save your class (Ctrl + S).
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
105
Unit 3: Use Classes in Workflow Architecture
4.
BIT611
To define customer specific time points for the process, create two additional events; one for the change of field Basic Material and one for the change of field Old Material. a)
Go to the tab “Events” and insert the following entries:
Event
BASICMATERIALCHANGED
Type
Instance
Visibility
Public
Description
Field basic material changed
Event
OLDMATERIALCHANGED
Type
Instance
Visibility
Public
Description
Field old material changed
Save your class (Ctrl + S). 5.
OPTIONAL To make the creation of a new material public, you have to implement a triggering event “CREATED” in the Create method. It should be include a parameter “User”. a)
Go to tab “Events” and insert the following entry:
Event
CREATED
Type
Instance
Visibility
Public
Description
Material Master created
Define a parameter “User” for the CREATED event. Mark the created entry and use the “Parameters” button to insert the following properties: Continued on next page
106
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Exceptions, Events and API Functions
Parameter
USER
Optional
-> no entry
Typing
Type
Associated Type
SY-UNAME
Default Value
-> no entry
Description
-> set automatically
Save your class (Ctrl + S). b)
Double-click the CREATE method. Implement the coding as shown in the following example. If you want to compare your coding, call the implementation of class ZBIT611_MARA. METHOD create. *- begin of local data DATA: l_event_parameters TYPE REF TO if_swf_ifs_parameter_container. *- end of local data
... CASE ex_return-number. ...
WHEN '365'. TRY. *--- get the event container that is used to transport the event parameters CALL METHOD cl_swf_evt_event=>get_event_container EXPORTING im_objcateg
= 'CL'
im_objtype
= 'ZBIT611_...'
im_event
= 'CREATED'
RECEIVING re_reference = l_event_parameters.
Continued on next page
2008
© 2008 SAP AG. All rights reserved.
107
Unit 3: Use Classes in Workflow Architecture
BIT611
*--- set the values of the parameters
CALL METHOD l_event_parameters->set EXPORTING name
= 'USER'
value = sy-uname. *--- raise the event CALL METHOD cl_swf_evt_event=>raise EXPORTING im_objcateg
= 'CL'
im_objtype
= 'ZBIT611_...'
im_event
= 'CREATED'
im_objkey
= ex_newmaterial
im_event_container = l_event_parameters. *--- start the receivers (tRFC) COMMIT WORK. CATCH cx_swf_evt_exception. CATCH cx_swf_cnt_container. ENDTRY. ...
ENDCASE. ENDMETHOD.
Save your class (Ctrl + S). 6.
108
Test your implementation by using the “Test” button (F8). a)
Press the “Test” Button (F8).
b)
A screen should be displayed where you see only the “CREATE” method.
c)
Create a new material and check the event triggering in transaction SWEL.
d)
To check exception handling, call the CREATE method of your class and check the reaction of system. If you abort the creation of material with the yellow “Exit” button (or press Schift + F3), the CX_BO_ACTION_CANCELLED exception should be raised.
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Exceptions, Events and API Functions
Lesson Summary You should now be able to: • Understand the exception techniques in workflow classes and their handling in the workflow engine • Define events and trigger them to start processes • Use API functions to affect workflow functions based on classes
2008
© 2008 SAP AG. All rights reserved.
109
Unit 3: Use Classes in Workflow Architecture
BIT611
Lesson: Using Classes in Workflow Architecture Lesson Overview This lesson explains the concept behind calling synchronous and asynchronous methods in tasks. It also describes how tasks can be started and integrated into workflows. This includes saving binding specifications, so that you can work correctly with the required objects in the individual business process steps at runtime.
Lesson Objectives After completing this lesson, you will be able to: • • •
Define and start single-step tasks and multistep tasks Explain and define bindings within a multistep task Use class components in workflow architecture
Business Example You want to use the methods and attributes of your new class definition in a workflow. To do this, you need to define tasks.
Definition of Standard Tasks
Figure 37: Single-Step Tasks
110
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Using Classes in Workflow Architecture
The default rule is evaluated if the task is used either outside a workflow, or in a step definition without an agent assignment. The following texts can be defined: • • • • • •
Work item text (workflow inbox in Business Workplace) Task description (work item preview in Business Workplace) Completion text Latest end text Latest start text Requested end text
Calling Synchronous and Asynchronous Methods •
Single-step task referring to a synchronous method
•
– Single-step task is terminated when the method reports back to caller – Binding between task container and method container in both directions Single-step task referring to asynchronous method – – –
Method started by workflow system Report back by terminating event Single-step task is terminated when terminating event occurs
Communication between single-step task and object method: •
Synchronous: The method is called, it takes over the process control and, after it has been processed, reports back to the caller.
•
Asynchronous: The method is called, the synchronous part of the method is processed and ends without returning any export parameters. The asynchronous part (update) runs without any connection to the caller and must report back to the caller with an event.
2008
© 2008 SAP AG. All rights reserved.
111
Unit 3: Use Classes in Workflow Architecture
BIT611
Please repeat the following notes about synchronous/asynchronous calling of workflow steps: • • • •
The task method is always called synchronously (that is, in the same session as the calling program) Previous methods and subsequent methods are always called synchronously Secondary methods are always called asynchronously (that is, in a new external session) Reports back to the workflow are made only from the task method. Secondary methods are for display only.
An explicit confirmation can be modeled in the step definition for both synchronous and asynchronous tasks. Synchronous tasks can also have terminating events. The task is then terminated, either when it has been successfully executed or when the terminating event has been received. In this case, the terminating event cannot be triggered within the associated object method.
Options for Starting Tasks • • • • •
Automatically through the workflow system when you reach a step within a multistep task Directly using the workflow development environment Program-driven through the API of the work item manager Using a triggering event Directly, using the system menu
Usually, tasks are started automatically through the step definition when a workflow is processed.
112
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Using Classes in Workflow Architecture
Workflow Definition Steps
Figure 38: Workflow Definition Steps
All block-oriented modeling constructs such as branches and loops are available. The steps can be arranged in sequence or parallel. The modeling interface (“Workflow Builder”) contains the relevant graphical operators for handling blocks. Each step is a determining component of its own block. Operations such as, copying or deleting on individual steps (for example, the “loop” step type) always affect the entire block (the entire loop contents, for example) that depends on this step.
2008
© 2008 SAP AG. All rights reserved.
113
Unit 3: Use Classes in Workflow Architecture
BIT611
Container and Binding Definition
Figure 39: Using the Workflow Container
The workflow container stores the data available throughout the process. It is used to perform the following tasks: •
Specify the import and export parameters for the entire workflow (elements with the property “Import” or “Export”) Exchange data between individual steps
• (1)
When the workflow is started, data from a triggering event is transferred to the workflow container as input parameters.
(2)
In a container operation, data in the workflow container can be changed by an allocation or a calculation.
(3)
The expressions in a condition refer to data belonging to the workflow container.
(4)
In a wait step, data is read from the workflow container (for example, to create the instance linkage for the event being received), whereas the event parameters are written to the workflow container with a binding.
(5)+(6) Data from the workflow container is read in an activity (binding for the task) and written (the output parameters of the task are transferred to the workflow container with binding). In addition, data is read from the workflow container to resolve the rule used in the step for agent determination and determine any dates (6) defined on the step (such as the deadline) with an expression.
114
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Using Classes in Workflow Architecture
Figure 40: Binding in Workflow Execution
(1)(11) The event container is filled when the event is created using the container macro (that is, before the event is triggered). (2)
Binding from the triggering event to the workflow. This binding is absolutely essential; usually, the reference of the triggering object and the user name (or “event initiator”) are transferred to the workflow container.
(3) (8) Binding from the workflow container to the rule: This sets the input parameters for the rule if one is defined for agent determination in the step. If there is a default rule in the task definition, the parameters are supplied from the work item container. (4) Binding between the workflow container and task container (work (7) (9) item container) for setting the input parameters (during the call) and (13) reading the output parameters of the task (once the task is completed). The Workflow Builder generates a proposal for this binding in the step definition. (5) (6) Binding between the task and the method container. There is a (10) binding for synchronous tasks in import (5) and export (6) direction. (12) In asynchronous tasks, the import binding is directly defined (10), whereas the return binding is defined during the terminating event (12). The runtime system copies the entire container if no binding is defined between the task and method.
2008
© 2008 SAP AG. All rights reserved.
115
Unit 3: Use Classes in Workflow Architecture
BIT611
Components of Class in Workflow Architecture
Figure 41: Using ABAP Objects in Workflow I
Figure 42: Using ABAP Objects in Workflow II
116
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Using Classes in Workflow Architecture
Figure 43: Using ABAP Objects in Workflow III
2008
© 2008 SAP AG. All rights reserved.
117
Unit 3: Use Classes in Workflow Architecture
118
© 2008 SAP AG. All rights reserved.
BIT611
2008
BIT611
Lesson: Using Classes in Workflow Architecture
Exercise 5: Create and Test Workflow Functions with ABAP Classes Exercise Objectives After completing this exercise, you will be able to: • Create standard tasks with ABAP classes • Create process flows with ABAP classes
Business Example You have either found or created all the classes that you want to use in your business process with the associated attributes and methods in the Class Builder. Now, you want to create single-step tasks based on the object methods, which you can use later in your workflow definition. Hint: It is a prerequisite for the course that participants know how to create and maintain tasks. The solution therefore only refers to created sample tasks. The following pages give a brief description of how to avoid problems when creating and maintaining tasks. All tasks are based on the class ZBIT611_##. Create a Standard Task. 1. Call transaction PFTS and choose Create. 2. Input data on the basic screen: ID: As specified in the exercise Name: As appropriate for the required task Work item text: As specified in the exercise Enter the material number in the text using the “Insert variables” button underneath the text. Section object methods: Object category: CL ABAP class Enter the class ZBIT611_## and the method required in the exercise. Press Enter to confirm. When prompted, transfer elements that are not available from the object method. 3. Enter the task description: Description tab page
2008
© 2008 SAP AG. All rights reserved.
119
Unit 3: Use Classes in Workflow Architecture
BIT611
Task description text type Choose the Change button Text: As specified in the exercise Enter the material number by choosing the menu option Include - Expression 4. Enter the possible agents: Possible agents are the users who are authorized to carry out the task in a business context. Maintenance: On the Task maintenance basic screen, choose the menu path: Additional Data -> Maintain Agent Assignment. Select the task ID and choose the Properties button. Then select General Task. 5. Enter texts for missed deadlines/completion: Description tab page Text type: Required texts (latest end text/completion text) Text: As specified in the exercise 6. Enter a terminating event: Terminating Events tab page Entry in the ELEMENT field: Using the F4 help, select the element _WI_OBJECT_ID. Again, using the F4 help, select the terminating event. 7. Enter a default value for the input parameter MaterialView/Maintenancestatus On the basic screen for the task: Container tab page Double click on the line containing MaterialView/Maintenancestatus Initial Value tab page Enter the value K for the Basic Data 1 view. 8. Test a task Call transaction SWUS. Under Task, enter the following: TSxxxxxxxx Transfer test data: Click on the line containing the expression _WI_OBJECT_ID An input line opens on the bottom edge of the screen. Use the F4 help to select the material that you want to test. 9. Display the instance data
120
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Using Classes in Workflow Architecture
Call the Workplace (transaction SBWP or Office - Workplace) Open the Inbox folder Click on the Workflow folder. Select the required work item and choose the Display icon. Choose Goto -> Technical Work Item Display Choose Extras -> Instance Linkage 10. Display the event trace Call transaction SWEL Enter your object type ZBIT611_## Choose Execute The triggered terminating event is displayed. In the detailed data (double-click on Event), you can view the number of the work item that was terminated by the event.
Task 1: Create a new standard task for displaying a material master from a predetermined view. 1.
Create the task ZCL##MatDisV with the method DisplayView. Define the task as a general task. Enter a work item text. Text:Display Material < Material number from object>. Display the material number with view. Display the material number in the work item text. Define the view K (corresponds to the Basic data 1 view) as default value for parameter “IM_MATERIALVIEW” to control the view initially called for the material.
2.
Test the task by starting it in the workflow development environment (transaction SWUS).
Task 2: Create a new standard task for changing a material master. 1.
Create the ZCL##Change task with the Change method. Define the task as a general task. Specify a work item text, a text for latest end and a text for completion. In addition to the material number, also issue the number and name of a plant for this material in all texts. Use the following texts: Continued on next page
2008
© 2008 SAP AG. All rights reserved.
121
Unit 3: Use Classes in Workflow Architecture
BIT611
Text: Change material 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.
3.
Test the task by starting it in the workflow development environment using transaction SWUS.
Task 3: Create a new standard task for creating a material master. 1.
Create the ZCL##Create task with the Create method. Define the task as a general task. Enter the following text as the work item text and description: Create a material master record.
2.
Test the task by starting it in the workflow development environment using transaction SWUS.
Task 4: Define a workflow with a triggering event. Hint: It is a prerequisite for the course that participants know how to create and maintain a task. The solution therefore only refers to created sample tasks. The following pages give a brief description of how to avoid problems when creating and maintaining tasks. The description follows the tasks. Workflow definition. 1. Creating a Workflow: Call transaction SWDD Choose the Save button. Enter the required workflow ID. Create the workflow as a local object. 2. Integrate the standard tasks as specified in the exercise. Select the undetermined step in the Workflow Builder. Choose the Create step icon. Continued on next page
122
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Using Classes in Workflow Architecture
Click on the step type Activity. Enter your task. 3. Select the responsible agents from the possible agents: Section Agents. Choose Users followed by the required users. 4. Define recipients for notification of completion: Notification tab page. Select the Workflow initiator expression. 5. Define a missed deadline Latest End tab page. Reference time: Generate work item Action: Send text Recipient: Select the Workflow initiator expression. 6. Link a triggering event On the Workflow Builder basic screen: Click on the Workflow Container tab page (on the left of the screen). Double-click reference variables for your material on the Properties tab page. Select the Import indicator. On the basic screen of the Workflow Builder, choose: Goto → Basic Data, tab page Start Events Enter your object type and select the event. Activate the event linkage by clicking on the button under A... (Event linkage active/inactive) 7. Testing the workflow On the Workflow Builder basic screen - click the Test icon. The workflow automatically switches to the test transaction SWUS. Remember to maintain the test data. 1.
Create a workflow template called ZCL##MSIPROC1 for creating and displaying a material master.
2.
Incorporate the single-step task ZCL##Change into your workflow definition. Continued on next page
2008
© 2008 SAP AG. All rights reserved.
123
Unit 3: Use Classes in Workflow Architecture
124
BIT611
3.
Define OldMaterialChanged as the triggering event for your workflow. Implement the binding between the triggering event and the workflow and activate the event linkage.
4.
Check, save, and activate your workflow definition. Test your workflow with your material by starting it from the workflow development environment.
5.
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.
6.
Add the single-step task ZCL##MatDisV to your workflow definition after the ZCL##Change step. Assign the value of the MaterialView parameter from the workflow container to the step parameter for controlling the display view.
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Using Classes in Workflow Architecture
Solution 5: Create and Test Workflow Functions with ABAP Classes Task 1: Create a new standard task for displaying a material master from a predetermined view. 1.
Create the task ZCL##MatDisV with the method DisplayView. Define the task as a general task. Enter a work item text. Text:Display Material < Material number from object>. Display the material number with view. Display the material number in the work item text. Define the view K (corresponds to the Basic data 1 view) as default value for parameter “IM_MATERIALVIEW” to control the view initially called for the material. a)
Refer to the following task definition as a solution: TS99700174 - ZCL00MatDisV Use the following path to display the task (starting from SAP Easy Access): Tools→ Business Workflow→ Development→ Definition Tools→ Tasks/Task Groups→ Create. For further details see general description.
2.
Test the task by starting it in the workflow development environment (transaction SWUS). a)
For further details, see general description.
Task 2: Create a new standard task for changing a material master. 1.
Create the ZCL##Change task with the Change method. Define the task as a general task. Specify a work item text, a text for latest end and a text for completion. In addition to the material number, also issue the number and name of a plant for this material in all texts. Use the following texts: Text: Change material a)
Refer to the following task definition as a solution: TS99700175 - ZCL00Change For further details, see general description. Continued on next page
2008
© 2008 SAP AG. All rights reserved.
125
Unit 3: Use Classes in Workflow Architecture
2.
BIT611
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. a)
3.
Enter the terminating event in the task definition.
Test the task by starting it in the workflow development environment using transaction SWUS. a)
For further details see general description.
Task 3: Create a new standard task for creating a material master. 1.
Create the ZCL##Create task with the Create method. Define the task as a general task. Enter the following text as the work item text and description: Create a material master record. a)
Refer to the following task definition as a solution: TS99700176 - ZCL00Create For further details, see general description.
2.
Test the task by starting it in the workflow development environment using transaction SWUS. a)
For further details, see general description.
Task 4: Define a workflow with a triggering event. Hint: It is a prerequisite for the course that participants know how to create and maintain a task. The solution therefore only refers to created sample tasks. The following pages give a brief description of how to avoid problems when creating and maintaining tasks. The description follows the tasks. Workflow definition. 1. Creating a Workflow: Call transaction SWDD Choose the Save button. Continued on next page
126
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Using Classes in Workflow Architecture
Enter the required workflow ID. Create the workflow as a local object. 2. Integrate the standard tasks as specified in the exercise. Select the undetermined step in the Workflow Builder. Choose the Create step icon. Click on the step type Activity. Enter your task. 3. Select the responsible agents from the possible agents: Section Agents. Choose Users followed by the required users. 4. Define recipients for notification of completion: Notification tab page. Select the Workflow initiator expression. 5. Define a missed deadline Latest End tab page. Reference time: Generate work item Action: Send text Recipient: Select the Workflow initiator expression. 6. Link a triggering event On the Workflow Builder basic screen: Click on the Workflow Container tab page (on the left of the screen). Double-click reference variables for your material on the Properties tab page. Select the Import indicator. On the basic screen of the Workflow Builder, choose: Goto → Basic Data, tab page Start Events Enter your object type and select the event. Activate the event linkage by clicking on the button under A... (Event linkage active/inactive) 7. Testing the workflow On the Workflow Builder basic screen - click the Test icon. The workflow automatically switches to the test transaction SWUS. Continued on next page
2008
© 2008 SAP AG. All rights reserved.
127
Unit 3: Use Classes in Workflow Architecture
BIT611
Remember to maintain the test data. 1.
Create a workflow template called ZCL##MSIPROC1 for creating and displaying a material master. a)
Define a workflow with a triggering event. WS99700306 - ZCL00MSIPROC Path (starting from SAP Easy Access):Tools→ Business Workflow→ Development→ Definition Tools→ Workflow Builder→ Create
2.
Incorporate the single-step task ZCL##Change into your workflow definition. a)
3.
Define OldMaterialChanged as the triggering event for your workflow. Implement the binding between the triggering event and the workflow and activate the event linkage. a)
4.
see task 4-1a)
Add the single-step task ZCL##MatDisV to your workflow definition after the ZCL##Change step. Assign the value of the MaterialView parameter from the workflow container to the step parameter for controlling the display view. a)
128
see task 4-1a)
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. a)
6.
see task 4-1a)
Check, save, and activate your workflow definition. Test your workflow with your material by starting it from the workflow development environment. a)
5.
see task 4-1a)
see task 4-1a)
© 2008 SAP AG. All rights reserved.
2008
BIT611
Lesson: Using Classes in Workflow Architecture
Lesson Summary You should now be able to: • Define and start single-step tasks and multistep tasks • Explain and define bindings within a multistep task • Use class components in workflow architecture
2008
© 2008 SAP AG. All rights reserved.
129
Unit Summary
BIT611
Unit Summary You should now be able to: • Understand the exception techniques in workflow classes and their handling in the workflow engine • Define events and trigger them to start processes • Use API functions to affect workflow functions based on classes • Define and start single-step tasks and multistep tasks • Explain and define bindings within a multistep task • Use class components in workflow architecture
130
© 2008 SAP AG. All rights reserved.
2008
BIT611
Course Summary
Course Summary You should now be able to: • • •
Identify all points in the workflow system at which programming is possible or necessary Create your own classes and use them in the workflow architecture Use “Container Parameter Interface” as the new application programming interface (API) for workflow related functions (check, receiver type, and so on)
Related Information • • •
2008
Use information in SAP Help Portal Use information in release notes Use information in Service Marketplace and Notes
© 2008 SAP AG. All rights reserved.
131
Course Summary
132
BIT611
© 2008 SAP AG. All rights reserved.
2008
Feedback SAP AG has made every effort in the preparation of this course to ensure the accuracy and completeness of the materials. If you have any corrections or suggestions for improvement, please record them in the appropriate place in the course evaluation.
2008
© 2008 SAP AG. All rights reserved.
133
View more...
Comments