Object Services in ABAP

Object Services in ABAP

2010
978-1-59229-339-1
217

Product Details

Object Services provide ABAP applications with various central services that are not directly covered by ABAP objects, and this practical book introduces proven solutions for the use of these standard services. It also teaches you how to easily link Object Services with user interface elements, or enhance them elsewhere with useful functions. 

Functional Scope in Detail 
Get essential details on the standard functions of Object Services (Persistence Service, Transaction Service, Query Service) as well as the technological basic principles of their implementation and their internal functioning. 

Enhancement Options 
Understand suggested enhancements for the functional scope of Object Services, such as options for reloading and releasing objects, the integration of plausibility checks, the automated processing of the SAP Lock Concept, and much more. 

Direct Benefits 
Learn to implement applications and entire systems on a completely object-oriented basis, allowing you to take full advantage of the benefits of Object Services. Your ABAP programs become more stable, re-usable, faster, and easier to maintain. 

Cross-Release Descriptions 
Increase your knowledge of further developments of Object Services, up to and including SAP NetWeaver AS ABAP Release 7.0 EhP2.

Highlights 

  • Reading persistent objects
  • Creating and changing persistent objects
  • Selecting persistent objects
  • Internal structure and functioning of Object Services
  • Enhancements for practical use
  • Plausibility checks and lazy loading
  • Integrating the SAP Lock Concept

About the Author(s)

Christian Assig, Aldo Hermann Fobbe, and Prof. Dr. Arno Niemietz work at IOT Institut für Organizations- und Technikgestaltung GmbH, which specializes in the development and implementation of complex IT solutions. They have many years of experience in object-oriented software development with ABAP, and have already used Object Services in numerous live projects.

Table of Contents 

... Preface ... 9

1 ... Introduction ... 11  

2 ... Reading Persistent Objects ... 19

2.1 ... Creating a Persistent Class ... 20

2.1.1 ... Selecting a Database Table for Persistence Representation ... 21

2.1.2 ... Assigning the Individual Fields to the Attributes of the Class ... 22

2.1.3 ... Completeness of the Persistence Representation ... 26

2.1.4 ... Instance GUIDs and Business Keys ... 26

2.1.5 ... Multiple-Table Mapping ... 28

2.1.6 ... Transient Attributes ... 29

2.1.7 ... Activating the Persistent Class ... 30

2.2 ... Instantiating Persistent Objects ... 30

2.2.1 ... IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_OID ... 31

2.2.2 ... IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_KEY ... 33

2.2.3 ... GET_PERSISTENT ... 34

2.2.4 ... Exception Handling ... 35

2.2.5 ... Behavior for Already-Loaded Objects ... 36

2.3 ... Reading Attribute Values ... 37

2.4 ... Persistent References ... 38

2.4.1 ... Definition of a Persistent Reference in the Persistence Representation ... 40

2.4.2 ... Runtime Behavior ... 41

2.4.3 ... Exception Handling ... 42

2.4.4 ... Limitations for the Use of Persistent References ... 43

2.5 ... Inheritance ... 43

2.5.1 ... Vertical Mapping ... 44

2.5.2 ... Horizontal Mapping ... 45

2.5.3 ... Comparing the Two Mapping Variants ... 47

2.5.4 ... Type Identifier ... 47

2.5.5 ... Where-Used List for Inheritance Relationships ... 48

2.6 ... Summary ... 49

 3 ... Creating and Changing Persistent Objects ... 51

3.1 ... Creating Persistent Objects ... 51

3.1.1 ... IF_OS_FACTORY~CREATE_PERSISTENT ... 52

3.1.2 ... IF_OS_FACTORY~CREATE_PERSISTENT_BY_KEY ... 53

3.1.3 ... CREATE_PERSISTENT ... 54

3.1.4 ... Exception Handling ... 55

3.1.5 ... Creating Transient Objects ... 55

3.2 ... Changing Attribute Values ... 56

3.3 ... Transaction Service ... 58

3.3.1 ... Transactions in SAP Systems ... 58

3.3.2 ... Object-Oriented Transactions ... 60

3.3.3 ... Concatenating Transactions ... 61

3.3.4 ... Subtransactions ... 63

3.3.5 ... Transaction Modes ... 64

3.3.6 ... Update Modes ... 70

3.3.7 ... Check Agents ... 74

3.3.8 ... Undo Mechanism for Persistent Objects ... 77

3.3.9 ... Transaction Statuses ... 78

3.4 ... Management States of Persistent Objects ... 80

3.4.1 ... State Transitions for Persistent Objects That Don't Exist in the Database Yet ... 81

3.4.2 ... State Transitions for Persistent Objects That Already Exist in the Database ... 82

3.4.3 ... State Transitions When Finishing Transactions and SAP Logical Units of Work ... 86

3.5 ... Summary ... 88  

4 ... Selecting Persistent Objects ... 89

4.1 ... Determining Keys of Persistent Objects with Open SQL ... 89

4.2 ... Mass Instantiation ... 91

4.3 ... Simple Selections Using the Query Service ... 93

4.4 ... More Complex Selections Using the Query Service ... 96

4.4.1 ... Defining Query Parameters ... 97

4.4.2 ... Defining the Filter Condition ... 99

4.4.3 ... Defining the Sort Condition ... 106

4.4.4 ... Passing Concrete Values for Query Parameters ... 109

4.5 ... Comparing the Query Service and Open SQL ... 112

4.6 ... Handling Newly Created and Changed Objects ... 113

4.7 ... Summary ... 116  

5 ... Internal Structure and Functioning of Object Services ... 117

5.1 ... Persistence Service ... 117

5.1.1 ... Class Agent and Base Agent ... 117

5.1.2 ... Instance Manager and Persistency Manager ... 121

5.1.3 ... Database Tables with Information on the Persistence Representation ... 124

5.1.4 ... Automatic Source Code Generation ... 124

5.1.5 ... Garbage Collection in ABAP Objects ... 127

5.2 ... Transaction Service ... 129

5.2.1 ... Implementation of the Transaction Manager and the Transactions ... 129

5.2.2 ... Undo Management ... 131

5.3 ... CL_OS_SYSTEM ... 134

5.4 ... Summary ... 136  

6 ... Useful Enhancements for Practical Use ... 137

6.1 ... Reloading Objects from the Database ... 137

6.2 ... Release of Objects No Longer Required ... 140

6.3 ... Conversion Between Object and Structure ... 141

6.3.1 ... Reading Attribute Values from a Persistent Object ... 142

6.3.2 ... Writing Attribute Values to a Persistent Object ... 144

6.3.3 ... Structures in Connection with Persistent Classes ... 146

6.4 ... Use of Persistent Objects in User Interfaces ... 150

6.4.1 ... SAP Control Framework ... 150

6.4.2 ... Using Persistent Objects in Web Dynpro Contexts ... 154

6.4.3 ... Setting the Transaction Mode in a Web Dynpro Application ... 158

6.5 ... Summary ... 159  

7 ... Intelligent Persistent Objects ... 161

7.1 ... Plausibility Checks ... 161

7.1.1 ... Variant 1: Custom Access Methods with Different Names in the Persistent Class ... 163

7.1.2 ... Variant 2: Delegation with Access Methods in a Usual Class ... 165

7.1.3 ... Variant 3: Persistent Subclass ... 167

7.1.4 ... Variant 4: Enhancement Framework ... 169

7.1.5 ... Comparing the Various Variants ... 174

7.2 ... Lazy Loading ... 176

7.3 ... Summary ... 180  

8 ... Integration of the SAP Lock Concept and Object Services ... 181

8.1 ... The SAP Lock Concept ... 182

8.2 ... Pessimistic and Optimistic Locking ... 186

8.2.1 ... Lock Mode ... 186

8.2.2 ... Pessimistic Locking ... 187

8.2.3 ... Optimistic Locking ... 189

8.2.4 ... Using the Two Locking Strategies in an SAP System ... 191

8.3 ... Integration of Optimistic Locking ... 192

8.3.1 ... Setting Optimistic Locks ... 193

8.3.2 ... Registering the Check Agent ... 197

8.3.3 ... Converting Optimistic Locks Into Exclusive Locks ... 199

8.4 ... Integration of Pessimistic Locking ... 204

8.5 ... Integration of Both Locking Strategies ... 205

8.6 ... Summary ... 207  

9 ... Conclusion ... 209

... The Authors ... 211

... Index ... 213