BC414_EN_Col92_FV_Inst_A4.pdf
August 19, 2017 | Author: Rashmi Karan | Category: N/A
Short Description
bc 414.. abap...
Description
BC414 Programming Database Updates SAP NetWeaver
Date Training Center Instructors
Education Website
Instructor Handbook Course Version: 92 Course Duration: 2 Day(s) Material Number: 50099921 Owner: Mo Sai Hsu (D002460)
An SAP Compass course - use it to learn, reference it for work
Copyright Copyright © 2011 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.
g2011231111421
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 and external.
2011
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.
© 2011 SAP AG. All rights reserved.
iii
About This Handbook
BC414
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
© 2011 SAP AG. All rights reserved.
2011
Contents Course Overview ......................................................... vii Course Goals ...........................................................vii Course Objectives .................................................... viii
Unit 1: Database Updates with Open SQL ........................... 1 Database Updates with Open SQL ...................................2
Unit 2: LUWs and Client/Server Architecture ..................... 31 LUWs and SAP Client/Server Architecture ........................ 32
Unit 3: SAP Locking Concept ......................................... 49 Reasons for Using Locks ............................................ 50 Lock Objects and Lock Modules .................................... 57 Setting and Releasing Locks ........................................ 66
Unit 4: Organizing Database Updates............................... 95 Database Changes from Within the Application Program ....... 96 Database Changes Using Update Techniques...................104
Unit 5: Complex LUW Processing .................................. 141 LUW Logic in Program-Controlled Calls ..........................142
Unit 6: Number Assignment .......................................... 155 Number Assignment .................................................156
Unit 7: Logging Database Changes ................................ 189 Creating Change Documents ......................................190
Unit 8: Object Services ................................................ 221 Updates Using ABAP Object Services ...........................222
Unit 9: Appendix ........................................................ 237 Runtime Architecture and Storage Access for Programs Called Within Programs..................................................239 Passing Data Between Programs .................................249 Authorization Checks ................................................258 SAP Table Buffers ...................................................265 Cluster Tables ........................................................270
2011
© 2011 SAP AG. All rights reserved.
v
Contents
BC414
SAP Locks – Update and Lock Duration..........................279 COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises .........................283
Index ....................................................................... 321
vi
© 2011 SAP AG. All rights reserved.
2011
Course Overview This course provides information about executing change transactions.
Target Audience This course is intended for the following audiences: • • •
Experienced ABAP developers Consultant Project team members
Course Prerequisites Required Knowledge • •
Practical experience of the ABAP development environment (ABAP Workbench) Programming User Dialogs (BC410)
Recommended Knowledge • •
ABAP Dictionary (BC430) Fundamentals of Web Dynpro for ABAP (NET310)
Course Duration Details
2011
Unit 1: Database Updates with Open SQL Database Updates with Open SQL Exercise 1: Changing a Single Record Exercise 2: Changing Several Data Records
45 Minutes 15 Minutes 20 Minutes
Unit 2: LUWs and Client/Server Architecture LUWs and SAP Client/Server Architecture Exercise 3: LUW Concepts
30 Minutes 30 Minutes
Unit 3: SAP Locking Concept Reasons for Using Locks Lock Objects and Lock Modules Exercise 4: Lock Objects and Lock Modules Setting and Releasing Locks Exercise 5: SAP Locking Concept
10 Minutes 15 Minutes 20 Minutes 60 Minutes 45 Minutes
Unit 4: Organizing Database Updates Database Changes from Within the Application Program
15 Minutes
© 2011 SAP AG. All rights reserved.
vii
Course Overview
BC414
Database Changes Using Update Techniques Exercise 6: Organizing Database Updates
160 Minutes 40 Minutes
Unit 5: Complex LUW Processing LUW Logic in Program-Controlled Calls
30 Minutes
Unit 6: Number Assignment Number Assignment Exercise 7: Number Assignment
60 Minutes 45 Minutes
Unit 7: Logging Database Changes Creating Change Documents Exercise 8: Creating Change Documents
60 Minutes 30 Minutes
Unit 8: Object Services Updates Using ABAP Object Services
60 Minutes
Unit 9: Appendix Runtime Architecture and Storage Access for Programs Called Within Programs Passing Data Between Programs Authorization Checks SAP Table Buffers Cluster Tables SAP Locks – Update and Lock Duration COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises Exercise 9: Complete Solution for “Generating Customer Data Records” (Complete Transaction) Exercise 10: Complete Solution for “Creating/Canceling a Booking” (Complete Transaction)
30 Minutes 30 Minutes 45 Minutes 15 Minutes 45 Minutes 5 Minutes 30 Minutes 0 Minutes
0 Minutes
Course Goals This course will prepare you to: •
Develop transactions that make changes to the database.
Course Objectives After completing this course, you will be able to: • • • • •
viii
Use ABAP Open SQL statements for database updates Implement the SAP locking concept for database updates Implement different update techniques for database changes Create change documents to log database changes Use numbers derived from number range objects
© 2011 SAP AG. All rights reserved.
2011
BC414
Course Overview
SAP Software Component Information The information in this course pertains to the following SAP Software Components and releases: •
SAP NetWeaver 7.0EhP 2
Hints on Preparing this Course Remember to check for additional information published after the final release of the course material. For the latest information and course updates, see the additional Instructor Guide, System Setup Guide, and Troubleshooting Guide on SAP Service Marketplace. You can find them under the alias /curr-abap: http://service.sap.com/curr-abap. Training System Availability Please refer to the info found at http://service.sap.com/curr-info link “essential training system information” Testing and Preparation System Please refer to the info found at http://service.sap.com/curr-info link “essential training system information” Required System Landscape This course needs an SAP Netweaver Application Server ABAP 7.0 EhP 2 or higher. Using the Training WTS Farm Please refer to the info found at http://service.sap.com/curr-info link “essential training system information” User ID and Passwords for the Course To create the participant user IDs and your trainer user ID, log on to the system with the user "Training". The password for this user is changed monthly. The current password should be included in the training information e-mail or documentation delivered to you by the education department. The standard format for the user ID is the course ID followed by the group number (here: BC414-xx). The initial password is INITIAL. Use transaction ZUSR to copy these user IDs from the reference user ID. You may use any existing user having the authorization SAP_ALL as a reference user (e.g. the template user NETALL). After having created your own user, please log off (as TRAINING). Log on with a generated user (e.g. BC414-00). Only use the new user throughout the course from now on.
2011
© 2011 SAP AG. All rights reserved.
ix
Course Overview
BC414
Additional Preparation in the System CATTs/eCATTs: 1.
2.
Automatic CATTs/eCATTs are started before training and a dialog box is generated afterwards to show that CATT was executed. No CATTs/eCATTs are needed for this course. Training CATTs/eCATTs are used, for example, to generate data before a specific exercise in a course. No CATTs/eCATTs are needed for this course.
Switching ON/OFF table locking in SAP systems: This course does not require switching ON/OFF of table locking. Example ABAPs: All example ABAPs needed for this course can be found in package BC414 in the training system
x
© 2011 SAP AG. All rights reserved.
2011
Unit 1 Database Updates with Open SQL
1
Instructor notes can be found in each of the lessons contained in this unit.
Unit Overview The basic knowledge of Open SQL statements is required to implement database changes. In this unit, inserting, changing, and deleting one or multiple datasets on the database server is discussed thoroughly.
Unit Objectives After completing this unit, you will be able to: •
Use Open SQL commands to execute database changes
Unit Contents Lesson: Database Updates with Open SQL ...................................2 Exercise 1: Changing a Single Record .................................. 17 Exercise 2: Changing Several Data Records ............................ 23
2011
© 2011 SAP AG. All rights reserved.
1
Unit 1: Database Updates with Open SQL
Lesson: 2
BC414
Database Updates with Open SQL Lesson Duration: 45 Minutes
Lesson Overview In this lesson, the Open SQL statements for inserting, changing, or deleting datasets on the database are discussed. This includes different variants of single record operations and multiple record operations.
Lesson Objectives After completing this lesson, you will be able to: •
Use Open SQL commands to execute database changes
Business Example All the aspects described in this lesson can be demonstrated by means of the program SAPBC414_SQL_D. Copy this program, so you can manipulate the source code. Debug the program. A break point assures that a debugger session is opened automatically. Caution: Debug the program only if the debugger session runs in an exclusive mode (displayed in the title). Otherwise changes are commited at the end of each dialog step related to the debugger mode. This will destroy the data consistency. If you debug this program in an exclusive mode, database changes are only commited if explicitly triggered from the debugger (Edit → Database → Commit). All database changes can be rolled back explicitly from the debugger (Edit → Database → Rollback). To monitor the temporary changes, you can display the database content of the changed table in transaction SE11 in a second mode. You want to use Open SQL commands to execute database changes.
2
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Updates with Open SQL
Open SQL: Introduction
Figure 1: Overview – SQL terms
In ABAP, you have both the Open SQL commands and the respective database-specific Native SQL commands at your disposal for making database changes. Accessing the database with Native SQL enables you to use database-specific commands. This requires detailed knowledge of the syntax in question. Programs that use Native SQL commands need additional programming after they have been transported to different system environments (different database systems), since the syntax of the SQL commands generally needs to be adjusted on a database-specific basis. Open SQL commands are not database-specific. They are automatically converted into the respective SQL statements by the database interface and passed to the database. An ABAP program that operates with Open SQL is therefore not database-specific and you can use it in any SAP system without having to adjust it. A further advantage of using Open SQL is that you can buffer the content of database tables locally on the application server for quicker read access. This also means that the database load is reduced. The data is read from the buffer automatically after the respective table settings have been made. The Open SQL set of commands only comprises operations for Data Manipulation Language (DML), not for Data Definition Language (DDL) since these are integrated in the ABAP Dictionary.
2011
© 2011 SAP AG. All rights reserved.
3
Unit 1: Database Updates with Open SQL
BC414
You should implement database accesses using Native SQL only if a particular Native SQL function that is not available in Open SQL must be used. For more information about Native and Open SQL, refer to the ABAP Editor keyword documentation for the term SQL.
Figure 2: Target Quantity and Return Values
You can limit the target quantity on the database using all the Open SQL commands discussed here. One or more rows can be processed using an SQL command. Commands that process several lines usually give better performance than corresponding single-set accesses (exception: mass data change using MODIFY). In addition, there is a syntax variant available for the change operation that you can use to change individual fields in a line. If you have masked field selections (WHERE LIKE ''), note that ’_’ masks an individual character and ’%’ masks a character string of any length (in line with the SQL standard). All the Open SQL commands provide you with a return message about the success or failure of the database operation performed. The message is issued in the form of a return code in the system field sy-subrc. If sy-subrc equals 0, the SQL operation has been completed successfully. All other values mean that errors have occurred. For further details, refer to the keyword documentation for the command in question. In addition, the sy-dbcnt system field displays the number of records for which the desired database operation was actually carried out.
4
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Updates with Open SQL
Note that Open SQL commands do not perform any automatic authorization checks. You need to execute these explicitly in your program (statement AUTHORITY-CHECK).
Figure 3: Accessing Client-Specific Tables
If the addition CLIENT SPECIFIED is not specified in an Open SQL command, no client specification is allowed in the respective WHERE clause. If the database table contains client dependent data, the records of the current execution client are accessed. The corresponding WHERE clause is automatically added by the database interface. If you wish to process data from other clients, you must specify the addition CLIENT SPECIFIED in the Open SQL command and the respective client(s) in the appropriate WHERE clause. Caution: If an Open SQL command contains the addition CLIENT SPECIFIED without a client specification, the datasets of all clients are accessed.
Open SQL: Syntax The statements INSERT, DELETE, UPDATE, and MODIFY may be used to change the content of database tables.
2011
© 2011 SAP AG. All rights reserved.
5
Unit 1: Database Updates with Open SQL
BC414
Creating Database Records Program SAPBC414_SQL_D. Debug corresponding section.
Figure 4: Creating a Single Record
To insert a new row in a database table, enter the command INSERT INTO VALUES . For this purpose, you must place the line to be inserted in the structure before the command is called. This structure must be the same as for the lines in the database table concerned. The client field that may possibly exist in the structure will only be taken into consideration if the CLIENT SPECIFIED addition is specified. If there is no CLIENT SPECIFIED addition, the current execution client applies. Rows can also be inserted using views. However, the view must already be created in the ABAP Dictionary with the maintenance status “read and change” and must only contain fields from a table. This INSERT variant has the following return codes: • •
0: Line inserted successfully. 4: Line could not be inserted because a line with the same key already exists.
Alternative syntax : INSERT INTO VALUES .
6
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Updates with Open SQL
Figure 5: Creating multiple records
You can use the command INSERT FROM TABLE to create several rows in a database table. The internal table that you should specify here must have the same line structure as the corresponding database table and the new data records. The client field that may possibly exist in the internal table will only be taken into consideration if the CLIENT SPECIFIED addition is specified. If there is no CLIENT SPECIFIED addition, the current execution client applies. If it is possible to create all the lines, sy-subrc is automatically set to zero. If, however, even one data record cannot be created, the system triggers a runtime error. This means that the entire insertion operation is discarded (database rollback). If you wish to have all records inserted that may be inserted, use the command addition ACCEPTING DUPLICATE KEYS. This addition has the effect that, if there is an error, the runtime error (and thus also the database rollback) is suppressed, sy-subrc is set to 4, and all the records without errors are inserted. The sy-dbcnt system field contains the number of rows that were successfully inserted in the database.
2011
© 2011 SAP AG. All rights reserved.
7
Unit 1: Database Updates with Open SQL
BC414
Changing Database Records Program SAPBC414_SQL_D. Debug corresponding section.
Figure 6: Changing a single record
Using the two variants of the UPDATE command discussed above, you can change a specific line within a database table. In the case of variant 1, the database record that contains the key in is overwritten by the content of . However, the key field mandt that may possibly exist in is only taken into consideration if the CLIENT SPECIFIED addition is specified as well (otherwise the current execution client applies). Logically, must have the same structure as the database record to be changed. In the case of variant 2, the record specified in the WHERE clause is changed. However, only the fields specified in the SET addition are overwritten on the database side with the values specified. In this syntax version, you must define the record to be changed in the WHERE clause by exactly specifying all the key field evaluations. For details on the specification of a possibly existing mandt field, refer to the figure “Accessing client-specific tables”.
8
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Updates with Open SQL
You can specify simple calculation operations as evaluation for numeric database fields in the SET addition: f = g , f = f + g , f = f - g . Rows can also be changed using views. However, the view must already be created in the ABAP Dictionary with the maintenance status “read and change” and must only contain fields from a table. These two UPDATE variants have the following return codes: • •
0: Line was changed. 4: Line could not be changed because, for example, the specified key does not exist.
Figure 7: Changing Several Records
If identical changes are to be made to the same fields in several rows of a database table, use the syntax specified on the slide. Using the WHERE clause you define which lines are to be changed. For details on specification of a possibly existing mandt field, refer to the figure “Accessing Client-Specific Tables”. In the SET addition, you specify which fields in these records are to be changed. The following calculations are also possible here for the numeric fields to be changed: f=g,f=f+g,f=f-g.
2011
© 2011 SAP AG. All rights reserved.
9
Unit 1: Database Updates with Open SQL
BC414
This UPDATE variant has the following return codes: • •
0: At least one line has been changed. 4: No line was changed.
The sy-dbcnt field contains the number of updated rows. You can also perform a mass data change by specifying an internal table that has the same structure as the corresponding database table and the records to be changed. The mandt field that possibly exists in the specified internal table is only taken into consideration if the CLIENT SPECIFIED addition is specified (otherwise the current execution client applies). This UPDATE variant has the following return codes: • •
0: All the specified lines were changed successfully. 4: At least one of the specified lines could not be changed (because, for example, it does not exist). The other lines were changed.
The sy-dbcnt system field contains the number of updated rows.
Modifying Database Records
Figure 8: Modifying Single Record / Several Records
The MODIFY command is SAP-specific. It covers the two commands UPDATE and INSERT: • •
10
If the data record specified in the MODIFY statement exists, this record is updated (→ UPDATE). If the data record specified in the MODIFY statement does not exist, this record is inserted (→ INSERT).
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Updates with Open SQL
Using the various syntax variants, you can process single records and several records (same as the syntax of UPDATE and INSERT). The operation can also be carried out on views. However, the view must already be created in the ABAP Dictionary with the maintenance status “read and change” and must only contain fields from a table. This command has the following return codes: • •
0: Specified record or all specified records were processed (updated/inserted). 4: The specified record or at least one of the specified records could not be processed – for example, because the record does not exist in the database and inserting it would destroy a unique secondary index. If you have chosen mass data change, the other records were processed.
The sy-dbcnt field contains the number of processed rows.
Deleting Database Records Program SAPBC414_SQL_D. Debug corresponding section.
Figure 9: Deleting a Single Record
2011
© 2011 SAP AG. All rights reserved.
11
Unit 1: Database Updates with Open SQL
BC414
The syntax specified above for the DELETE command enables you to delete a single row in a database table. In this syntax version, you must define the record to be changed in the WHERE clause by exactly specifying all the key field evaluations. For details on the specification of a possibly existing mandt field, refer to the figure “Accessing Client-Specific Tables”. A row can also be deleted from views. However, the view must already be created in the ABAP Dictionary with the maintenance status “read and change” and must only contain fields from a table. This DELETE variant has the following return codes: • •
0: Line was deleted. 4: Line could not be deleted because, for example, it does not exist in the database.
Alternative syntax : DELETE [CLIENT SPECIFIED] FROM . With this syntax version, the structure must have the same structure as the records in the respective database table and must be filled with the key fields of the records to be deleted before the command is called. However, the key field mandt, which possibly exists in , is only taken into consideration if the CLIENT SPECIFIED addition is specified (otherwise the execution client applies).
Figure 10: Deleting Several Records
12
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Updates with Open SQL
This syntax variant of the DELETE command enables you to delete several lines in a database table. Here, you can specify the lines that are to be deleted in the WHERE clause. For details on the specification of a possibly existing mandt field, refer to the figure “Accessing Client-Specific Tables”. If you wish to delete several records from a database table, you can specify them first in an internal table that has the same structure as the respective database table and then use the above syntax of the DELETE command. To do so, all you need to do is specify the key part of the records to be deleted in the internal table. If the key field mandt exists, then it will only be taken into consideration if the CLIENT SPECIFIED addition is specified (otherwise the current execution client applies). This DELETE variant has the following return codes: • •
0: All the lines specified in the internal table were deleted. 4: At least one line could not be deleted (for example, because it does not exist). The other records were deleted.
The number of lines deleted from the database is shown in the system field sy-dbcnt. You can delete all the lines in a cross-client database table using the following syntax: DELETE FROM WHERE LIKE '%'. Here is an arbitrary table field. If you wish to delete all the lines of the execution client from a client-specific database table, you can use the same syntax: DELETE FROM WHERE LIKE '%'. If you wish to delete all the existing lines from a client-specific database table, you must also specify the CLIENT SPECIFIED addition in the command: DELETE FROM CLIENT SPECIFIED WHERE LIKE '%'. Deleting data records using conditions produces the following return codes: • •
0: At least one line was deleted. 4: No line was deleted because, for example, the specified lines do not even exist.
The system field sy-dbcnt contains the number of lines that have been deleted from the database.
Restoring Previous Database Status Program SAPBC414_SQL_D. Debug corresponding section.
2011
© 2011 SAP AG. All rights reserved.
13
Unit 1: Database Updates with Open SQL
BC414
Figure 11: Restoring Previous Database Status
If an Open SQL statement that executes a change to the database returns a return code different than zero, you should make sure that the database is reset to the same status as before you attempted to make the respective change. You achieve this by performing a database rollback, which reverses all changes to the current database LUW (see next unit). There are two ways of causing a database rollback: • •
Sending a termination dialog message (A-Message) Using the ROLLBACK WORK ABAP statement
The transmission of an A Message causes a database rollback and terminates the program. All other message types (E,W, I) also involve a dialog but do not trigger a database rollback. The ABAP statement ROLLBACK WORK, on the other hand, causes a database rollback without terminating the program. In this case, you should be careful since the context has not been reset in the current program.
14
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Updates with Open SQL
Navigating in the Exercises
Figure 12: Navigating in the Exercises
2011
© 2011 SAP AG. All rights reserved.
15
Unit 1: Database Updates with Open SQL
16
© 2011 SAP AG. All rights reserved.
BC414
2011
BC414
15
Lesson: Database Updates with Open SQL
Exercise 1: Changing a Single Record Exercise Duration: 15 Minutes
Exercise Objectives After completing this exercise, you will be able to: • Insert single records in database tables
Business Example You want to execute direct database changes from your program. Program: SAPMZCUSTOMER_## Transaction: ZCUSTOMER_## Copy template: SAPMBC414_CUST_T Model solution: SAPMBC414_CUST_SQL_S
Task 1: Prepare and test program Create a package, copy the template program, and create a transaction to start your copy. 1.
Create a package. Name the package ZBC414_##, where ## is your group number.
2.
Copy the template program SAPMBC414_CUST_T with all constituents. Name the copy SAPMZCUSTOMER_##. Create a transaction (name: ZCUSTOMER_##) to start your program. Save program and transaction in your package ZBC414_## and assign the objects to the transport request used before. Activate your program and test your transaction.
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
17
Unit 1: Database Updates with Open SQL
3.
BC414
The program you copied allows you to enter new customer data using screen 100. Analyze the program flow if all obligatory screen fields are filled, and the SAVE icon is clicked. Which function code is related to the SAVE icon? Which subroutine should encapsulate the code related to the database dialog? Use the debugger to analyze the program flow. Start the debugger by entering /h in the command field before you save the data.
Task 2: Implement database changes Extend the program to include the database dialog. 1.
Implement the code to create a new customer data set on the database: Insert the new customer data record in the database table SCUSTOM. If the operation is successful, message S015 should be issued; if the operation is not successful, termination message A048 should be issued. Hint: • •
•
18
In the subroutine SAVE, the newly entered customer data is retained in the structure CS_SCUSTOM. The already implemented call of the subroutine NUMBER_GET_NEXT places a new customer number into the field CS_SCUSTOM-ID (internal number assignment). The BC414 message class is declared as a program default in the PROGRAM statement and therefore valid throughout the programs.
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Updates with Open SQL
Solution 1: Changing a Single Record Task 1: Prepare and test program Create a package, copy the template program, and create a transaction to start your copy. 1.
Create a package. Name the package ZBC414_##, where ## is your group number. a)
Start transaction SE80. Select Package in the first input field above the object tree. Enter the package name in the second fields above the object list. Press Enter.
b)
On the following dialog screen, enter a short description and (optionally) an application component. Press Enter.
c)
Use the value help to assign your package to the transport request your trainer created for you. Finish the dialog.
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
19
Unit 1: Database Updates with Open SQL
2.
BC414
Copy the template program SAPMBC414_CUST_T with all constituents. Name the copy SAPMZCUSTOMER_##. Create a transaction (name: ZCUSTOMER_##) to start your program. Save program and transaction in your package ZBC414_## and assign the objects to the transport request used before. Activate your program and test your transaction. a)
In transaction SE80, open the object list for package BC414. Expand the tree, so all programs related to the package are displayed. Right mouse click on program SAPMBC414_CUST_T. Choose Copy... from the context menu.
b)
On the following screen, enter the name of the program you want to create (SAPMZCUSTOMER_##). Press Enter.
c)
The next dialog asks for the program parts you would like to copy. Mark all checkboxes so all parts will be copied. Press Copy.
d)
The following dialog displays the names of the includes that will be created during the copy process. Accepts the proposals by clicking Copy.
e)
When being asked for the package, enter ZBC414_##. Press Enter.
f)
Finally, assign all new objects to the transport request used before. Finish the copy procedure by clicking Enter.
g)
Change the package displayed in the object tree of transaction SE80. Display your package ZBC414_##. Open the object list. Expand the tree, so your program is displayed. Activate your program (choose Activate from the program’s context menu and press Enter on the next screen).
h)
Now select Create → Transaction from the context menu of your program. Enter ZCUSTOMER_## in the input field for the transaction name and enter any description. Press Enter.
i)
On the detail screen for the transaction, enter the name of your program (SAPMZCUSTOMER_##), the screen number of the start screen (100), and mark the checkbox labeled SAP GUI for Windows. Click the icon to save the transaction (CTRL+S). Assign the transaction to your package and your transport request.
j)
To test the transaction, select the Test icon in the application toolbar (F8).
Continued on next page
20
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Updates with Open SQL
3.
The program you copied allows you to enter new customer data using screen 100. Analyze the program flow if all obligatory screen fields are filled, and the SAVE icon is clicked. Which function code is related to the SAVE icon? Which subroutine should encapsulate the code related to the database dialog? Use the debugger to analyze the program flow. Start the debugger by entering /h in the command field before you save the data. Answer: The function code SAVE is related to the SAVE icon. The subroutine SAVE should contain the code for the database changes.
Task 2: Implement database changes Extend the program to include the database dialog. 1.
Implement the code to create a new customer data set on the database: Insert the new customer data record in the database table SCUSTOM. If the operation is successful, message S015 should be issued; if the operation is not successful, termination message A048 should be issued. Hint: • •
•
a)
In the subroutine SAVE, the newly entered customer data is retained in the structure CS_SCUSTOM. The already implemented call of the subroutine NUMBER_GET_NEXT places a new customer number into the field CS_SCUSTOM-ID (internal number assignment). The BC414 message class is declared as a program default in the PROGRAM statement and therefore valid throughout the programs.
See the model solution below.
Result Hint: Tips on Model Solutions for this Course The model solutions reproduce the statements for screen flow logic and ABAP program parts that you need to include. The exercises for course BC414 are designed to expand on two larger programs accompanying the
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
21
Unit 1: Database Updates with Open SQL
BC414
contents of the unit in question. To make the examples clearer, we do not reproduce all the code necessary for every model solution. The following procedure is used instead: • •
All model solutions contain only changed and new program parts. A complete version of both programs is provided in the appendix in the training folder.
Forms - Include MBC414_CUST_SQL_SF01 *----------------------------------------------------------------------* ***INCLUDE MBC414_CUST_SQL_SF01 *----------------------------------------------------------------------* ... *&---------------------------------------------------------------------* *&
Form
SAVE
*&---------------------------------------------------------------------* *
PS_SDYN_BOOK
text
*----------------------------------------------------------------------* FORM save_new_booking USING ps_sdyn_book TYPE sdyn_book. DATA ls_sbook
TYPE sbook.
MOVE-CORRESPONDING ps_sdyn_book TO ls_sbook. * get customer name SELECT SINGLE name FROM scustom INTO ls_sbook-passname WHERE id = ls_sbook-customid. IF ls_sbook-class IS INITIAL. ls_sbook-class = 'Y'.
Continued on next page
136
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Database Changes Using Update Techniques
ENDIF. CALL FUNCTION 'INSERT_SBOOK' IN UPDATE TASK EXPORTING is_sbook = ls_sbook. CALL FUNCTION 'UPDATE_SFLIGHT' IN UPDATE TASK EXPORTING iv_carrid = ls_sbook-carrid iv_connid = ls_sbook-connid iv_fldate = ls_sbook-fldate. ENDFORM.
2011
" SAVE_NEW_BOOKING
© 2011 SAP AG. All rights reserved.
137
Unit 4: Organizing Database Updates
BC414
Lesson Summary You should now be able to: • Perform database changes using the update concept • Implement different update techniques (synchronous, asynchronous, local) • Create and use update modules • Implement updates of type V1 and V2 • Implement the SAP locking concept in accordance with the selected change type
138
© 2011 SAP AG. All rights reserved.
2011
BC414
Unit Summary
Unit Summary You should now be able to: • Execute database updates directly from application programs • Use subroutines that are called in a way that the processing is deferred • Perform database changes using the update concept • Implement different update techniques (synchronous, asynchronous, local) • Create and use update modules • Implement updates of type V1 and V2 • Implement the SAP locking concept in accordance with the selected change type
2011
© 2011 SAP AG. All rights reserved.
139
Unit Summary
140
BC414
© 2011 SAP AG. All rights reserved.
2011
Unit 5 Complex LUW Processing
131
No instructor notes for this unit.
Unit Overview In complex applications, different programming units are combined to form the final program. The programming units may be function modules, methods of global classes, executable programs or transactions. In respect to the update concept, it is of great significance if a SAP LUW can be extended across multiple programming units. This unit explains which program types may be used to modularize an application without modularizing the SAP LUW and which program types cannot be used for this purpose.
Unit Objectives After completing this unit, you will be able to: • • •
Explain the LUW logic for program-controlled program calls Perform complex LUW processing Use the SAP lock mechanism for complex LUW processing
Unit Contents Lesson: LUW Logic in Program-Controlled Calls...........................142
2011
© 2011 SAP AG. All rights reserved.
141
Unit 5: Complex LUW Processing
Lesson: 132
BC414
LUW Logic in Program-Controlled Calls Lesson Duration: 30 Minutes
Lesson Overview This lesson explains LUW logic for program-controlled calls.
Lesson Objectives After completing this lesson, you will be able to: • • •
Explain the LUW logic for program-controlled program calls Perform complex LUW processing Use the SAP lock mechanism for complex LUW processing
No instructor notes are available in this lesson. You may develop little demo programs to clarify the concepts.
Business Example You want to implement complex LUW processing with LUW logic for program-controlled calls.
142
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: LUW Logic in Program-Controlled Calls
Programs Called Within Programs
Figure 66: Synchronous Calls
There are two ways of calling other ABAP programs on a synchronous basis from within a program. •
For the following calls, the processing of the called program is inserted, that is, the processing of the calling program is interrupted and then continued again after the called program has been completed: CALL FUNCTION '' CALL METHOD => CALL METHOD -> CALL TRANSACTION ''
•
SUBMIT AND RETURN For the following calls the calling program is terminated and the called program is started: LEAVE TO TRANSACTION '' SUBMIT
SUBMIT and SUBMIT AND RETURN are used to call programs that can be executed (program type “1” = “executable program”). CALL TRANSACTION '' and LEAVE TO TRANSACTION '' are used to call transactions.
2011
© 2011 SAP AG. All rights reserved.
143
Unit 5: Complex LUW Processing
BC414
For more details on SUBMIT, CALL TRANSACTION, and LEAVE TO TRANSACTION, refer to the keyword documentation integrated in the ABAP Editor.
Figure 67: Asynchronous Call of a Function Module
Function modules can also be called asynchronously for executing processes in parallel. For this, the call must be supplied with the addition STARTING NEW TASK . “” stands for a user-individual name for the new independent task in which the function module will be processed. Asynchronously called function modules are processed in parallel to and independent of the calling program. You can receive the output of the function module (addition RECEIVE RESULTS FROM FUNCTION) in a later processing phase of the calling program. Function modules that are to be called using the addition STARTING NEW TASK must be marked as capable of being called remotely in their properties (processing type: “remote-capable module”). For further information, see the keyword documentation in the ABAP Editor for CALL FUNCTION.
144
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: LUW Logic in Program-Controlled Calls
LUW Logic in Program-Controlled Calls
Figure 68: SAP LUWs in Synchronous Program Calls
Function modules and methods run in the same SAP LUW as the program that calls them. Executable programs called by SUBMIT AND RETURN, or SUBMIT and transactions called by CALL TRANSACTION '', or LEAVE TO TRANSACTION '' each run in a separate SAP LUW, that is, their update requests have separate update keys. If you use SUBMIT AND RETURN or CALL TRANSACTION '', the SAP-LUW of the calling program is continued as soon as the calling program is completed. The LUWs of calling and called programs are run independently of one another. Update requests and subroutine calls using the addition ON COMMIT each require an independent COMMIT WORK in the corresponding SAP LUW (see next figure). If you use SUBMIT or LEAVE TO TRANSACTION '', the SAP LUW of the calling program ends. If you do not conclude your update requests with the statement COMMIT WORK before the program call,
2011
© 2011 SAP AG. All rights reserved.
145
Unit 5: Complex LUW Processing
BC414
no header for the related update key is created in the log. This means that the update process for these requests will not be executed by the update work process. The same applies to subroutines called with the addition ON COMMIT. Hint: Calling a program via SUBMIT ..., CALL TRANSACTION '', or LEAVE TO TRANSACTION '' involves an implicit DB commit. Thus, all inline changes performed by a program are automatically committed, if another executable program or transaction is called.
Figure 69: SAP LUWs for CALL TRANSACTION
If you call up transactions with nested calls, each transaction needs its own COMMIT WORK, since each transaction maps its own SAP LUW. The same is true for executable programs that are called with SUBMIT AND RETURN.
146
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: LUW Logic in Program-Controlled Calls
Figure 70: Call mode in CALL TRANSACTION
If a transaction is called from within a program using CALL TRANSACTION '', you can also have the transaction executed without user dialog (that is, in the background). For this purpose, you need to supply an internal table in batch-input format (see the online documentation for the CALL TRANSACTION) using the USING addition. This table contains the values for the dynpros and the function code to navigate between the dynpros. Also, you should specify the MODE parameter for the call with “N” (“do not display”). Further values for the MODE parameter are “A” (“display” = default), “E” (“only display if error”), and “P” (“display debugger at break point”). Using the call parameter UPDATE, you can overwrite the default update mode for the transaction to be called, which is usually asynchronous. Possible values for the UPDATE parameter are “A” (“asynchronous”, = default), “S” (“synchronous”) and “L” (“local”). If you have UPDATE = 'S', the processing of the calling program will only be continued when the update process triggered by the called transaction is completed. The update success is then returned by the system field sy-subrc. You use UPDATE = 'S' if further processing after the transaction that is to be called depends on the success of the transaction. For further information, refer to the keyword documentation in the ABAP Editor for the term CALL TRANSACTION.
2011
© 2011 SAP AG. All rights reserved.
147
Unit 5: Complex LUW Processing
BC414
Figure 71: SAP LUWs in Asynchronous Function Calls
A function module that is called asynchronously runs in a separate session and therefore creates its own SAP LUW. The processing of the calling program is interrupted briefly, and, after the function module has been triggered, processing is continued. This means that registered update flags and subroutines called with the addition ON COMMIT are retained. Hint: Note that the asynchronous call of a function module triggers an implicit database commit. This means that inline changes processed in the calling program up to that point will be committed on the database.
148
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: LUW Logic in Program-Controlled Calls
Figure 72: Ability to Accumulate Locks for Program Call
If a lock of type “E” was set in the program for a data record, you can have further locks of type “E” set in the same program, in a function module that was called synchronously or in a called method. The cumulation counter of the original lock is increased by 1. However, you cannot set further locks to existing ones from within a program called using SUBMIT AND RETURN or CALL TRANSACTION ''. Any lock attempts from such programs will be rejected with the exception FOREIGN_LOCK . If you have a program called using SUBMIT or LEAVE TO TRANSACTION '', the calling program will be terminated immediately. All the locks set up to that point will be automatically deleted. Therefore, no lock conflicts between the calling and the called program can arise. Lock requests of the same user from different main sessions or terminal sessions will be treated as lock requests from different users.
2011
© 2011 SAP AG. All rights reserved.
149
Unit 5: Complex LUW Processing
BC414
Figure 73: Implementation of Different Program Calls
Programs called by SUBMIT AND RETURN or CALL TRANSACTION '' have their own independent SAP LUW. You can use these to perform nested (complex) LUW processing. Asynchronously called function modules are suitable for tasks that can be processed in parallel. Note that an asynchronously called function module runs in a new main session and therefore has its own independent SAP memory. You should therefore use the function module interface for data transfer. Sample application of the asynchronous function call: In your program, you want to call up a display transaction that is displayed in a separate window (amodal). Call a function module asynchronously that itself calls the transaction through CALL TRANSACTION ''. Using the function module interface, you can transfer data. The function module could pass the information to the transaction via the SAP memory.
150
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: LUW Logic in Program-Controlled Calls
Facilitated Discussion Discuss open questions.
Discussion Questions Use the following questions to engage the participants in the discussion. Feel free to use your own additional questions.
2011
© 2011 SAP AG. All rights reserved.
151
Unit 5: Complex LUW Processing
BC414
Lesson Summary You should now be able to: • Explain the LUW logic for program-controlled program calls • Perform complex LUW processing • Use the SAP lock mechanism for complex LUW processing
152
© 2011 SAP AG. All rights reserved.
2011
BC414
Unit Summary
Unit Summary You should now be able to: • Explain the LUW logic for program-controlled program calls • Perform complex LUW processing • Use the SAP lock mechanism for complex LUW processing
2011
© 2011 SAP AG. All rights reserved.
153
Unit Summary
154
BC414
© 2011 SAP AG. All rights reserved.
2011
Unit 6 Number Assignment
143
Instructor notes can be found in each of the lessons contained in this unit.
Unit Overview Database records are typically identified via a unique key. Number ranges assign numbers to complete the keys of the individual database records of a business object. Such numbers are, for example, order or material master record numbers. In this unit, the definition of number range objects, the maintenance of number ranges, and the assignment and check of numbers are discussed.
Unit Objectives After completing this unit, you will be able to: • • • • •
Create number range objects and maintain number range intervals Use function modules to determine the next free number of an interval with internal number assignment Use function modules to check the validity of numbers assigned externally Locate information on function modules for managing number ranges Explain the meaning of buffered number assignment
Unit Contents Lesson: Number Assignment .................................................156 Exercise 7: Number Assignment .........................................175
2011
© 2011 SAP AG. All rights reserved.
155
Unit 6: Number Assignment
Lesson: 144
BC414
Number Assignment Lesson Duration: 60 Minutes
Lesson Overview This lesson explains how to assign unique IDs to newly created data records.
Lesson Objectives After completing this lesson, you will be able to: • • • • •
Create number range objects and maintain number range intervals Use function modules to determine the next free number of an interval with internal number assignment Use function modules to check the validity of numbers assigned externally Locate information on function modules for managing number ranges Explain the meaning of buffered number assignment
Instructor notes can be found below.
Business Example You want to assign a unique ID for data records that are to be created.
Number Range Management – Overview Business objects are identified by unique keys. Typically, the complete key or at least a part of it is defined by a number. The number range management is a mechanism to assign business objects to specific number range intervals. In addition, number range management ensure that numbers are only assigned once.
156
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
Figure 74: Requirements
The technical details of number ranges are defined as number range objects. For each number range object, one or multiple number ranges can be maintained. Each number range is identified by an alphanumeric identifier, the number range number. In general, one number range contains one number range interval. However, a number range may also by organized by the fiscal year. In this case, for each fiscal year an own number range interval may be defined for one and the same number range. Number assignment takes place either externally or internally. With external number assignment, the user inputs a number that is then checked by the system to see if it has been reserved for external assignment. With internal number assignment, the system automatically assigns a number to a business object. Thus, there are different number ranges for external and internal number assignment. Number range intervals are composed of either numbers or – for external number ranges only – alphanumeric characters. Number ranges may not overlap.
Figure 75: Number Ranges
2011
© 2011 SAP AG. All rights reserved.
157
Unit 6: Number Assignment
BC414
Figure 76: Number Range Intervals
Sometimes it is meaningful to govern the number assignment by the value of a subobject (e.g. for each plant the material number should be assigned separately, for each company code the same document number should be assignable once). This is also supported by the number assignment management. If subobjects are used, number ranges maintained for a certain value of the subobject may not overlap.
158
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
Figure 77: Distinguish Number Assignment by Subobject
Another requirement may be the assignment of number ranges according to the value of a classification criterion contained by the business object (e.g. the number assignment to a material should depend on the material category – row material, semi-finished material, or finished material). This can be implemented if all possible values of the classification criterion are stored in a database table together with the information about the related number range(s) (e.g. all material kinds together with the number range numbers of the related internal and external number ranges). This database table – specific to the number range object – is called group table. Either one number range (internal or external) or two number ranges (one internal and one external) may be stored with the value of the classification criterion. Each entry in the group table is called element.
2011
© 2011 SAP AG. All rights reserved.
159
Unit 6: Number Assignment
BC414
Figure 78: Distinguish Number Assignment by Classification Criterion
The two concepts (distinguish number assignment by subobject/classification criterion) may be combined (e.g. material numbers should be assigned for each plant and each material kind separately). In this case, the group table has to contain another column containing the value of the subobject (e.g. the plant identifier).
160
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
Figure 79: Distinguish Number Assignment by Classification Criterion and Subobject
Number range documentation can be found in the Online Documentation under “Number Ranges”.
Creating Number Range Objects and Maintaining Number Ranges In order to implement the number assignment, you first need to create a corresponding number range object, maintain the number range interval(s), and then access both of these from within your application program (with the help of special function modules – see next section). Both the creation of number range objects and the maintenance of number range intervals is facilitated by the transaction SNRO. Here you should create a number range object (analogous SBOOKID). While creating it, you should explain the properties of the first list below.
2011
© 2011 SAP AG. All rights reserved.
161
Unit 6: Number Assignment
BC414
Figure 80: Number Range Objects
162
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
The following information can to be entered by you: • •
• •
• •
•
•
•
Object: First, the name of the number range object has to be entered. Customer objects begin with Y or Z. Subobject data element: If you want to guide the number assignment by a subobject, you have to enter a corresponding data element name. This data element must, by way of its domain, refer to a value table and can have a field length of up to six characters. To-year flag: Select if you want your number ranges to be organized according to fiscal year. Number length domain: This obligatory information defines the length (maximum number of characters) of the numbers. You must enter a domain. This domain can be either type NUMC or type CHAR and can have a field length of up to 20 characters. No interval rolling: Select if you want to prevents the number range intervals from automatically starting from the beginning at the upper limit. Number range transaction: You may enter the name of a transaction code here. This will automatically create a parameter transaction for the transaction SNRO. This parameter transaction may then be used to maintain the number ranges for the current number range object. Warning %: This obligatory parameter (between 0.1 and 99.9) defines a warning limit in respect to the total amount of numbers in a number range interval. If this limit is reached, the functions that are used to get/check the next number will return a warning information. Main memory buffering: The system automatically suggests a main memory buffering. You can, however, define a different buffering mechanism by yourself (discussed below). Buffering can even be switched off. Note that buffering should only be turned off in exceptional cases (for example, when unbroken number sequences are necessary). No. of numbers in buffer: If the count of currently buffered numbers for a number range interval reaches zero the buffer is refilled. This parameter defines how many numbers are transferred to the buffer.
Explain the properties related to group properties. Display the number range object MATERIALNR. Explore the group table and the related text table with SE11 or SE16. Locate the columns containing the number range numbers.
2011
© 2011 SAP AG. All rights reserved.
163
Unit 6: Number Assignment
BC414
Figure 81: Group Specification
164
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
If you want to guide the number assignment by a classification criterion, the fields in the group labeled “Group specification” need to be filled: • •
• •
•
Group table: Enter the name of the table containing the elements with the related numbers of the number range(s). Subobject field in group table: Only to be filled if the number assignment is guided by a subobject. Then the name of the table column containing the subobject value has to be entered here. Fld NoRangeElement: Enter the name of the table column containing the classification criterion value. Fields int./ext. no.range no.: Use if two number ranges (internal and external) are to be assigned to each table element. Then, the name of the column containing the internal number range number has to be entered in the left field, while the name of the column containing the external number range number has to be entered in the right field. Fld NoRangeNo: Use if only one number range (internal or external) is to be assigned to each table element. Then, the name of the column containing this number range number has to be entered in the field. Hint: Either the fields labeled “Fields int./ext. no.range no.”, or the field labeled “Fld NoRangeNo” may be filled.
•
Display element text: Select if the element text should be displayed in the maintenance dialog for the data ranges.
The element texts displayed during the maintenance dialog have to be maintained in a second database table, which is defined typically as a text table for the group table. Details can be entered in a dialog popping up if you click the button labeled “Maintain text”. Create an internal and an external number range. Create number range intervals for two carriers (by copying the number range interval of the first carrier to the interval of the second one. To maintain number range intervals, you have to click the corresponding toolbar button in the transaction SNRO labeled “Number ranges”. The following screen displays three buttons to create new number range intervals, to change the status (current number) of existing number range intervals, and to display existing intervals. If the number range object uses a subobject, an additional field to enter an allowed value for the subobject is displayed. This is since the number ranges are specific to the subobject value. For details about maintaining groups, refer to the online documentation under “Number ranges”.
2011
© 2011 SAP AG. All rights reserved.
165
Unit 6: Number Assignment
BC414
Function Modules for Number Management When assigning numbers, you should always pay attention to any regulations and application-specific criteria that apply (for example, mandatory unbroken or chronological number sequences). The function modules used to get or check numbers belong to the function group SNR3. Check the function module in transaction SE37.
Figure 82: Getting Number Range Information
Use the function module NUMBER_GET_INFO to get information about the individual number range intervals of number range objects (interval limits, current status, and so on). This information is transferred as a structure using the INTERVAL parameter. This parameter is typed with the transparent table NRIV. For more information, refer to the function module documentation.
Internal Number Assignment Check the function module in transaction SE37. Access an internal number range. To get all return codes, you should switch off the buffering in your number range object, or you should ignore the buffer when getting the next number. In addition, the number of buffered numbers should be small (e.g. 10) and the warning level should be set appropriately (e.g. 30% ).
166
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
Figure 83: Get Numbers (from Internal Number Range)
When assigning numbers internally, call the function module NUMBER_GET_NEXT to determine the next number(s) available. If you have requested more than one number using the import parameter QUANTITY, the export parameter QUANTITY contains the number of assigned numbers, while the export parameter NUMBER contains the last number assigned. The assigned numbers are then in the interval (NUMBER - Export-QUANTITY + 1 to NUMBER). If the last number of the interval has been assigned, the number assignment begins again at the first number of the interval, provided the property “No interval rolling” was left empty in the definition of the number range object. The return code allows you to see if the number can be assigned without any problems, or if it lies within a critical range. • • • •
SPACE: Number assignment successful 1: Number assignment successful but the number of unassigned numbers dropped below the warning level (property “Warning %”). 2: Number assignment successful; however, the last available number was just assigned to you. 3: You requested more numbers than were available. All available numbers were assigned to you.
For more information, refer to the function module documentation.
2011
© 2011 SAP AG. All rights reserved.
167
Unit 6: Number Assignment
BC414
External Number Assignment Check the function module in transaction SE37. Access an external number range.
Figure 84: Check Number (External Number Range)
Use the function module NUMBER_CHECK for checking external numbers. This function checks, if a given number lies within a number range interval that has been designated for external use. The checked number is not marked by the function module as assigned. The check results are returned through the export parameter RETURNCODE. • •
SPACE: Number inside the specified interval ’X’: Number outside of the specified interval
For more information, refer to the function module documentation.
168
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
Buffering Numbers The data for number ranges is stored in database table NRIV. In this table, an entry exists for each individual number range interval. The way to access this information can be adjusted by setting the buffering mode in the related number range object. This is done via the menu path Edit → Set up Buffering. The following modes are available: • • • •
No buffering Main Memory Local File and Process ID Parallel
In the following, the impact of this setting on performance and number assignment is discussed.
Accessing Table NRIV Without a Buffer
Figure 85: Accessing Table NRIV Without a Buffer (1)
Note: This mode is selected via the menu item No buffering. If buffering is switched off, the system must read directly from the database each time a new number is assigned. This leads to the locking of the corresponding number range until completion of the current LUW. The advantages of non-buffered access are: • •
2011
Numbers are assigned without gaps Chronological sequence of number assignment is assured
© 2011 SAP AG. All rights reserved.
169
Unit 6: Number Assignment
BC414
Disadvantages are: • •
Database locks lead to a serialization Multiplication effects may result (see next figure)
Figure 86: Accessing Table NRIV Without a Buffer (2)
In the function module NUMBER_GET_NEXT, the statement SELECT SINGLE ... FOR UPDATE is used to access the table NRIV. This locks the relevant table entry in the database until completion of the current LUW. This can lead to considerable waiting time when multiple programs request numbers from the same number range.
170
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
Buffer Numbers on Application Server
Figure 87: Access Through Number Range Buffer (Default)
Note: This mode is selected via the menu item Main Memory. You can enhance performance considerably by buffering number ranges in the main memory of each application server (default buffering mode). Here the number assignment is conducted by number range servers. Number range servers are logical units on the application servers and run their own LUWs. Gaps in respect to number assignments can occur due to rollback or network errors. Your buffers are refilled automatically with a new number package (= quantity of numbers) as soon as all its numbers have been assigned. You determine how many numbers are stored in the buffer during the number range object maintenance (parameter “No. of numbers in buffer”). With this kind of buffering, the application server only has to read directly from the database after it has assigned all of the numbers in its current packet. This leads to better performance and makes clear why number range objects should be buffered as long as application logic and regulations allow. The function module NUMBER_GET_NEXT offers you the option of ignoring the buffer if you wish to do so (interface parameter IGNORE_BUFFER).
2011
© 2011 SAP AG. All rights reserved.
171
Unit 6: Number Assignment
BC414
Buffer Numbers on Database
Figure 88: Parallel Access to Number Ranges
Note: This mode is selected via the menu items Parallel and Local File and Process ID. Another means of assigning buffered numbers is to buffer the numbers block by block on the database (database table NRIV_LOKAL). Mode “Parallel”: Here, the blocks are assigned to application servers. This enables parallel accesses from various servers. Serialization only takes place for each individual server. This buffering mechanism can be implemented on all customer installations. Mode “Local File and Process ID”: Here, the blocks are assigned to individual work processed on the application servers. This enables parallel accesses from various work processes located on the same server. Thus, serialization is minimized. This buffering mechanism cannot be implemented on all customer installations, since the generated identifier of the number packages may exceed the length allowed in table NRIV_LOKAL. In both modes, the numbers are assigned without gaps (for rare exceptions see note 175047 - to document gaps, the report RSSNR0A1 can be used). Numbers are not assigned in chronological order.
172
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
Using Function Groups to Manage Number Ranges
Figure 89: Using Function Groups to Manage Number Ranges
For processing number range objects, number ranges, and groups, there are additional function modules available that allow you to edit dialogs, database accesses, and other tasks. These function modules are assigned to five different function groups. If you are only interested in using standard number range functions, then you only need the function modules found in function group SNR3.
2011
© 2011 SAP AG. All rights reserved.
173
Unit 6: Number Assignment
174
BC414
© 2011 SAP AG. All rights reserved.
2011
BC414
163
Lesson: Number Assignment
Exercise 7: Number Assignment Exercise Duration: 45 Minutes
Exercise Objectives After completing this exercise, you will be able to: • Create a number range object • Define number ranges and number range intervals • Implement the technique for internal number assignment in transactions
Business Example You need to implement the assignment of numbers in your transaction because a need to assign a unique ID to newly created data records. Program: SAPMZBOOKINGS_## Transaction code: ZBOOKINGS_## Copy template: SAPMBC414_BOOK_UPDATE_S Model solution: SAPMBC414_BOOK_NRANGE_S Model solution (number range object): SBOOKID
Task 1: Prepare and Test Program If you have not finished the previous exercise dealing with database updates, you can copy the template program and create a transaction to start your copy. 1.
If necessary, copy the template program SAPMBC414_BOOK_UPDATE_S with all constituents. Name the copy SAPMZBOOKINGS_NRANGE_##. Create a transaction (name: ZBOOKINGS_NRANGE_## ) to start your program. Save program and transaction in your package ZBC414_## and assign the objects to the transport request created by your trainer. Activate your program and test your transaction.
Task 2: Create Number Range Object Create a number range object to assign numbers to the bookings created in your program. The booking numbers should be assigned depending on the carrier. The numbers should be buffered in the main memory. Set the block size for the buffered numbers to 20. The warning level should be adjusted to 4 numbers. 1.
Create a number range object (name: ZBOOK_##).
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
175
Unit 6: Number Assignment
2.
BC414
Set the properties. The booking numbers should be assigned for each flight carrier independently. The numbers should be buffered in the main memory. Set the block size for the buffered numbers to 20. The warning level should be adjusted to 4 numbers. Hint: Use transaction SE11 to display the transparent table SBOOK. Here, you can explore the name of the domain related to the flight booking number and the name of the data element describing the carrier ID. Set the warning level to a percentage value corresponding to 4 left numbers.
Task 3: Create Number Range Intervals Create an internal number range interval for the flight carriers “AA” and “LH, respectively”. The number intervals with number range number “01” have to start at “1##00000” and have to end at “1##99999”. Here, “##” is the group number also used for the naming of you package. 1.
Create an internal number range interval for the flight carrier “AA”. The number interval with number range number “01” has to start at “1##00000” and has to end at “1##99999”.
2.
Create an internal number range interval for the flight carrier “LH”. The number range interval should have the same settings as the number range you created for the carrier “AA”.
Task 4: Implement Internal Number Assignment Adjust your program so that the booking number of a new booking is assigned by internal number assignment. Get a number from the internal number range interval of the number range object you created in this exercise. 1.
Create a new subroutine (name: GET_NUMBER) in the include ending with F01. The subroutine should have one parameter to interchange the flight carrier and a second parameter to interchange the booking number. The flight carrier is not changed by the subroutine. Call the subroutine from the PAI module USER_COMMAND_0300 (directly before the lock request for the new booking). Pass the carrier ID (SDYN_BOOK-CARRID) to the subroutine. Assign the booking number set in the subroutine to the field SDYN_BOOK-BOOKID.
2.
Implement the source code of the subroutine: - Call the function module NUMBER_GET_NEXT. - Assign the carrier ID to the interface parameter SUBOBJECT. Continued on next page
176
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
- Assign the name of your number range object (ZBOOK_##) to the interface parameter OBJECT. - Assign the identifier of your number range interval (01) to the interface parameter NR_RANGE_NR. - Assign the booking number returned by the function module to the corresponding interface parameter of the subroutine. - Handle the parameter RETURNCODE and the exceptions of the function module. Possible messages: - Supply of numbers exceeded critical level → Message 070 - Caution: Last number was taken Þ Message 071 - No more free numbers Þ Message 072 - Internal error supplying numbers (sy-subrc = &1) Þ Message 073 3.
Since the numbers are now assigned by the system, you do not need to display an input field for the booking number on subscreen 301. Hide the field for the booking number dynamically. To do so, remove the comment asterisk in front of the module HIDE_BOOKID in the flow logic of subscreen 301. The module is already created.
2011
© 2011 SAP AG. All rights reserved.
177
Unit 6: Number Assignment
BC414
Solution 7: Number Assignment Task 1: Prepare and Test Program If you have not finished the previous exercise dealing with database updates, you can copy the template program and create a transaction to start your copy. 1.
If necessary, copy the template program SAPMBC414_BOOK_UPDATE_S with all constituents. Name the copy SAPMZBOOKINGS_NRANGE_##. Create a transaction (name: ZBOOKINGS_NRANGE_## ) to start your
Continued on next page
178
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
program. Save program and transaction in your package ZBC414_## and assign the objects to the transport request created by your trainer. Activate your program and test your transaction. a)
In transaction SE80, open the object list for package BC414. Expand the tree, so all programs related to the package are displayed. Right mouse click program SAPMBC414_BOOK_UPDATE_S. Choose Copy... from the context menu.
b)
On the following screen, enter the name of the program you want to create (SAPMZBOOKINGS_NRANGE_##). Press Enter.
c)
The next dialog asks for the program parts you would like to copy. Mark all checkboxes so all parts are copied. Press Copy.
d)
The following dialog displays the names of the includes that will be created during the copy process. Accepts the proposals by clicking Copy.
e)
When being asked for the package, enter ZBC414_##. Press Enter.
f)
Finally, assign all new objects to the transport request used before. Finish the copy procedure by clicking Enter.
g)
Change the package displayed in the object tree of transaction SE80. Display your package ZBC414_##. Open the object list. Expand the tree, so your program is displayed. Activate your program (choose Activate from the program’s context menu and press Enter on the next screen).
h)
Now select Create → Transaction from the context menu of your program. Enter ZBOOKINGS_NRANGE_## in the input field for the transaction name and enter any description. Press Enter.
i)
On the detail screen for the transaction, enter the name of your program (SAPMZBOOKINGS_NRANGE_##), the screen number of the start screen (100), and mark the checkbox labeled SAP GUI for Windows. Click the icon to save the transaction (CTRL+S). Assign the transaction to your package and your transport request.
j)
To test the transaction, select the Test icon in the application toolbar (F8).
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
179
Unit 6: Number Assignment
BC414
Task 2: Create Number Range Object Create a number range object to assign numbers to the bookings created in your program. The booking numbers should be assigned depending on the carrier. The numbers should be buffered in the main memory. Set the block size for the buffered numbers to 20. The warning level should be adjusted to 4 numbers. 1.
2.
Create a number range object (name: ZBOOK_##). a)
Start transaction SNRO. You can enter the transaction code in the command field or you can start by choosing Tools → ABAP Workbench → Development → Other Tools → Number Ranges.
b)
In the first screen, enter ZBOOK_## in the input field and click the button labeled “Create”.
Set the properties. The booking numbers should be assigned for each flight carrier independently. The numbers should be buffered in the main memory. Set the block size for the buffered numbers to 20. The warning level should be adjusted to 4 numbers. Hint: Use transaction SE11 to display the transparent table SBOOK. Here, you can explore the name of the domain related to the flight booking number and the name of the data element describing the carrier ID. Set the warning level to a percentage value corresponding to 4 left numbers. a)
Enter a meaningful short text and long text.
b)
Enter the domain related to flight booking numbers (S_BOOK_ID) in field “Number range domain”.
c)
Enter the data element related to a carrier (S_CARR_ID) in the field labeled “Subobject data element”.
d)
Enter 20 in the field labeled “No. of numbers in buffer”.
e)
Enter 20 (= 100 * 4 / 20) in the field labeled “Warning %”.
f)
Save the number range object by clicking the Save button in the toolbar. In the following dialog screen, click the Yes button to accept the buffering method. Assign the number range object to your package and your change request.
Continued on next page
180
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
Task 3: Create Number Range Intervals Create an internal number range interval for the flight carriers “AA” and “LH, respectively”. The number intervals with number range number “01” have to start at “1##00000” and have to end at “1##99999”. Here, “##” is the group number also used for the naming of you package. 1.
2.
Create an internal number range interval for the flight carrier “AA”. The number interval with number range number “01” has to start at “1##00000” and has to end at “1##99999”. a)
On the screen for maintaining number range objects, click the Number Ranges toolbar button. This will bring you to the initial screen for maintaining number ranges.
b)
Enter AA in the input field labeled “Airline” and click the button to change intervals.
c)
On the following screen, click the toolbar button to insert intervals.
d)
Enter 01 in the column labeled “No”. Enter 1##00000 in the column labeled “From number” and 1##99999 in the column labeled “To number”. Note: ## is your group number
e)
Enter 1##00000 in the field “Current number”.
f)
Do not check the checkbox in column “Ext”.
g)
Finish the dialog (Enter).
h)
Click the Save button. Accept the information displayed on the next screen. Click the Back button to navigate to the initial screen for maintaining number ranges.
Create an internal number range interval for the flight carrier “LH”. The number range interval should have the same settings as the number range you created for the carrier “AA”. a)
On the initial screen for maintaining number ranges, click the Copy button in the toolbar.
b)
Enter AA in the input field labeled “From” and LH in the input field labeled “To”.
c)
Finish the dialog (Enter). Accept the information displayed on the next screen.
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
181
Unit 6: Number Assignment
BC414
Task 4: Implement Internal Number Assignment Adjust your program so that the booking number of a new booking is assigned by internal number assignment. Get a number from the internal number range interval of the number range object you created in this exercise. 1.
Create a new subroutine (name: GET_NUMBER) in the include ending with F01. The subroutine should have one parameter to interchange the flight carrier and a second parameter to interchange the booking number. The flight carrier is not changed by the subroutine. Call the subroutine from the PAI module USER_COMMAND_0300 (directly before the lock request for the new booking). Pass the carrier ID (SDYN_BOOK-CARRID) to the subroutine. Assign the booking number set in the subroutine to the field SDYN_BOOK-BOOKID. a)
2.
See model solution. The subroutine is most easily created via forward navigation (write the call of the subroutine, then double-click the subroutine’s name).
Implement the source code of the subroutine: - Call the function module NUMBER_GET_NEXT. - Assign the carrier ID to the interface parameter SUBOBJECT. - Assign the name of your number range object (ZBOOK_##) to the interface parameter OBJECT. - Assign the identifier of your number range interval (01) to the interface parameter NR_RANGE_NR. - Assign the booking number returned by the function module to the corresponding interface parameter of the subroutine. - Handle the parameter RETURNCODE and the exceptions of the function module. Possible messages: - Supply of numbers exceeded critical level → Message 070 - Caution: Last number was taken Þ Message 071 - No more free numbers Þ Message 072 - Internal error supplying numbers (sy-subrc = &1) Þ Message 073 a)
3.
See model solution.
Since the numbers are now assigned by the system, you do not need to display an input field for the booking number on subscreen 301. Hide the field for the booking number dynamically. To do so, remove the comment asterisk in front of the module HIDE_BOOKID in the flow logic of subscreen 301. The module is already created. Continued on next page
182
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Number Assignment
a)
See model solution.
Result
PAI Modules - Include MBC414_BOOK_NRANGE_SI01 *----------------------------------------------------------------------* ***INCLUDE MBC414_BOOK_NRANGE_SI01 *----------------------------------------------------------------------* ... *&---------------------------------------------------------------------* *&
Module
USER_COMMAND_0300
INPUT
*&---------------------------------------------------------------------* MODULE user_command_0300 INPUT. CASE ok_code. WHEN 'BOOK' OR 'DETCON' OR 'DETFLT'. tab-activetab = ok_code. WHEN 'NEW_CUSTOM'. *
Optional: Create new customer PERFORM create_new_customer CHANGING sdyn_book-customid. SET SCREEN '0300'. WHEN 'SAVE'. PERFORM convert_to_loc_currency USING
sdyn_book-forcuram sdyn_book-forcurkey sdyn_book-carrid
CHANGING sdyn_book-loccuram sdyn_book-loccurkey. *
Get next free number in the number range '01'
*
of number object 'SBOOKID' PERFORM get_number USING
sdyn_book-carrid
CHANGING sdyn_book-bookid. *
Lock booking CALL FUNCTION 'ENQUEUE_ESBOOK' EXPORTING carrid
= sdyn_book-carrid
connid
= sdyn_book-connid
fldate
= sdyn_book-fldate
bookid
= sdyn_book-bookid
EXCEPTIONS
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
183
Unit 6: Number Assignment
BC414
foreign_lock
= 1
system_failure = 2 OTHERS
= 3.
CASE sy-subrc. WHEN 0. WHEN 1. MESSAGE e061. WHEN OTHERS. MESSAGE e063 WITH sy-subrc. ENDCASE. *
Save booking and update flight
*
End LUW and start update process
PERFORM save_new_booking USING sdyn_book. COMMIT WORK. SET SCREEN '0100'. WHEN 'BACK'. CALL FUNCTION 'DEQUEUE_ALL'. SET SCREEN '0100'. WHEN OTHERS. SET SCREEN '0300'. ENDCASE. ENDMODULE.
" USER_COMMAND_0300
INPUT
Forms - Include MBC414_BOOK_UPDATE_SF01 *----------------------------------------------------------------------* ***INCLUDE MBC414_BOOK_NRANGE_SF01 *----------------------------------------------------------------------* ... *&---------------------------------------------------------------------* *&
Form
GET_NUMBER
*&---------------------------------------------------------------------* *
-->
PV_CARRID
text
*
PT_BOOKINGS_MOD
text
*
-->PT_CD
text
*----------------------------------------------------------------------* FORM create_change_document USING pt_bookings_mod TYPE gty_t_sbook pt_cd
TYPE gty_t_cd.
DATA ls_sbook_n TYPE sbook. DATA ls_sbook_o TYPE sbook. DATA ls_sbook
TYPE vsbook.
LOOP AT pt_bookings_mod INTO ls_sbook_n. *
read unchanged data from buffer table into work area READ TABLE pt_cd FROM ls_sbook_n INTO ls_sbook_o.
*
build up table of bookings before changes MOVE-CORRESPONDING ls_sbook_o TO ls_sbook. APPEND ls_sbook TO ysbook.
*
build up table of bookings after changes MOVE-CORRESPONDING ls_sbook_n TO ls_sbook. APPEND ls_sbook TO xsbook. ENDLOOP.
Continued on next page
216
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Creating Change Documents
* define objectid from key fields of sbook CONCATENATE ls_sbook-mandt ls_sbook-carrid ls_sbook-connid ls_sbook-fldate INTO objectid SEPARATED BY space. * fill interface parameters for function call (which itself is * encapsulated in form CD_CALL_BC414_SBOOK_TAB tcode
= sy-tcode.
utime
= sy-uzeit.
udate
= sy-datum.
username
= sy-uname.
upd_sbook = 'U'. * perform calls the neccessary function to create change document * 'in update task' PERFORM cd_call_bc414_sbook_tab. ENDFORM.
2011
" CREATE_CHANGE_DOCUMENT
© 2011 SAP AG. All rights reserved.
217
Unit 7: Logging Database Changes
BC414
Lesson Summary You should now be able to: • Create change document objects • Create change documents • Analyze change documents
218
© 2011 SAP AG. All rights reserved.
2011
BC414
Unit Summary
Unit Summary You should now be able to: • Create change document objects • Create change documents • Analyze change documents
2011
© 2011 SAP AG. All rights reserved.
219
Unit Summary
220
BC414
© 2011 SAP AG. All rights reserved.
2011
Unit 8 Object Services
209
Instructor notes can be found in each of the lessons contained in this unit.
Unit Overview The Object Service supports the consistent change of persistent objects within the SAP transaction concept. This unit gives a brief overview of the Persistent Service and Transaction Service, which are part of the Object Services.
Unit Objectives After completing this unit, you will be able to: • •
Explain how the Persistence Service lets the ABAP programmer work with relational database data in an object-oriented way Describe how the Transaction Service supports the consistent change of persistent objects within the SAP transaction concept
Unit Contents Lesson: Updates Using ABAP Object Services ............................222
2011
© 2011 SAP AG. All rights reserved.
221
Unit 8: Object Services
Lesson: 210
BC414
Updates Using ABAP Object Services Lesson Duration: 60 Minutes
Lesson Overview This lesson describes the role of the Persistence Service and of the Transaction Service in respect to database updates.
Lesson Objectives After completing this lesson, you will be able to: • •
Explain how the Persistence Service lets the ABAP programmer work with relational database data in an object-oriented way Describe how the Transaction Service supports the consistent change of persistent objects within the SAP transaction concept
Trainer hints can be found in this lesson.
Business Example You want to work with persistent objects in your application. Thus, you have to know what needs to be considered if the data of these persistent objects is altered.
Persistence Service The Persistence Service can be thought of as a software layer between the ABAP program and the database. This service allows application developers to access database records via the attributes of related objects (persistent objects). The Persistence Service ensures that an object is initialized in a specified state, and saves the state of that object when required. The state of the object when it is instantiated reflects the state of the data in the database at that time. Changes to the object state in the ABAP program are not written to the database before the COMMIT WORK statement has been executed. Thus, a persistent object exists as an original in the database (database record) and as a copy in one or more ABAP programs (objects). Hint: It is necessary to implement the classical SAP locking concept when working with persistent objects.
222
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Updates Using ABAP Object Services
To use the Persistence Service for objects, the classes of these objects must be created as persistent classes in the Class Builder. Note: The term “persistent class” does not imply that a class is persistent. Rather, it means that the objects of that class and their state are managed by the Persistence Service. For example, the objects of these classes are instantiated in the ABAP program with a method of the Persistence Service (not with the usual CREATE OBJECT statement), which ensures that the initialization is correct. When the Class Builder creates a persistent class, it automatically generates an associated class, known as the class actor or class agent, whose methods manage the objects of persistent classes at runtime. As well as their identity, persistent classes can contain key attributes, which allow the Persistence Service to ensure that the content of each persistent object is unique.
Figure 101: Persistent Objects – Design Time
Check the classes CL_BC414_BOOKING, CL_BC414_FLIGHT, and the related CA_ and CB_ classes. You can also create your own persistent class in the customer name space, activate it, and check then the generated agent class ZCA.
2011
© 2011 SAP AG. All rights reserved.
223
Unit 8: Object Services
BC414
Figure 102: Persistent Objects – Instantiation
Persistent Objects and COMMIT WORK To apply the changes made to the runtime objects of persistent classes to the actual database records in the database, you only have to execute the COMMIT WORK statement. Note: All update modes are supported. Unless you are executing an object-oriented transaction from within the Transaction Service (see next sections), you must include the COMMIT WORK statement explicitly in the program. The function of the COMMIT WORK statement is extended when you use it in conjunction with Object Services: •
• •
224
Internal methods of the Persistence Service are called. These methods bundle the changes made to persistence objects and pass them to a special update function module called with the addition IN UPDATE TASK. The SAP LUW is closed and the update process is triggered. The attributes of all persistent objects are initialized.
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Updates Using ABAP Object Services
Figure 103: Persistent Objects – Persisting Data
Figure 104: Persistent Objects – Code Sample
2011
© 2011 SAP AG. All rights reserved.
225
Unit 8: Object Services
BC414
In the code sample displayed above, a persistent object is created for an existing flight. The price of this flight is increased by 10%. This information is stored in the object until the COMMIT WORK statement is processed. Then, a change request for this data set is added to the log table. This change request gets the same key as all other change requests of the current SAP LUW. Finally, the update is started. After the COMMIT WORK statement, the object referenced by LO_FLIGHT is not deleted (event if the local reference variable is deleted), because it is managed by the persistent service. However, the attributes are initialized. The current state of the persistent object is refreshed by calling the class agent method GET_PERSISTENT(...) again. Compare the source code of the programs SAPMBC414_BOOK_MODEL_D1 and SAPMBC414_BOOK_MODEL_D2, PAI modules for screen 200 and 300. Instead of subroutines, methods defined in a model layer are called. In these model methods you find the code to use update modules directly (_D1) or the code using the class agents of persistent classes (_D2).
Transaction Service The Transaction Service supports the consistent change of persistent objects within the SAP transaction concept. It is used implicitly when working with persistent objects in classical transactions. However, this “compatibility mode” is only one option of using the Transaction Service. It is also possible to write new fully object-oriented applications (example: Web Dynpro applications). Here, the Transaction Service offers a second transaction mode (“object-oriented transaction mode”). In this mode, you do not have to use the COMMIT WORK statement to trigger the update process. Instead, you work with a so called transaction manager which allows you to define the begin and the end of a transaction. The transaction manager allows you to define multiple transactions in one program. The first transaction defined in your application automatically gets the top-level transaction. If this top-level transaction is ended, the update process is started automatically. To manage a transaction, a proxy object for this transaction can be obtained from the transaction manager. The transaction proxy allows you to end corresponding transaction via the method END( ). Note: In OO transactions, the COMMIT WORK statement must not be used.
226
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Updates Using ABAP Object Services
Figure 105: Transaction Service – Begin/End Transaction
The possibility to define multiple transactions in one application allows you to develop components changing data on the database – each component defining its own transaction – and combine them in a new program. If the COMMIT WORK statement is not explicitly used in any of the components (object-oriented transaction mode), all component-related transactions are combined via the top-level transaction. All related changes are combined in one LUW.
2011
© 2011 SAP AG. All rights reserved.
227
Unit 8: Object Services
BC414
Figure 106: Transaction Service – Nesting Transactions
228
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Updates Using ABAP Object Services
Transaction Manager and Transaction Proxy To work with the Transaction Service, you need to know the following important classes and related methods: •
Set transaction mode and update mode (for details see next section): CL_OS_SYSTEM=>INIT_AND_SET_MODE( )
•
Get transaction manager (returns transaction manager object LO_TM): CL_OS_SYSTEM=>GET_TRANSACTION_MANAGER( )
•
Create new transaction (returns transaction proxy object LO_TP): LO_TM->CREATE_TRANSACTION( )
•
Get current transaction (returns transaction proxy object object LO_TP): LO_TM->GET_CURRENT_TRANSACTION( )
•
Get top-level transaction (returns transaction proxy object object LO_TP): LO_TM->GET_TOP_TRANSACTION( )
•
Start transaction: LO_TP->START( )
•
End transaction: LO_TP->END( ) Note: If transaction is top-level transaction, COMMIT WORK is implicitly triggered.
•
Create new transaction and concatenate it with current top-level transaction: LO_TP->END_AND_CHAIN( ) Note: Top-level transaction is extended by new transaction.
•
End transaction and rollback work: LO_TP->UNDO( ) Note: If transaction is top-level transaction and transaction mode is “object-oriented”, ROLLBACK is triggered implicitly. All changes made to persistent objects in the current transaction are rolled back.
2011
© 2011 SAP AG. All rights reserved.
229
Unit 8: Object Services
BC414
Transaction Mode and Update Mode The transaction mode is set as follows: •
•
If you do not set the transaction mode explicitly before using the Object Services the first time, the respective default mode (“compatibility mode”) is used. In this case, a top-level transaction is created and started automatically. You can create additional transactions. These will be defined as sub transactions of the top-level transaction. To end the top-level transaction, you can use the statement COMMIT WORK or you can call the method END( ) of the transaction proxy. To set the transaction mode in your program explicitly, you have to call the static method CL_OS_SYSTEM=>INIT_AND_SET_MODE( ) before you access the Object Services in a program for the first time. The transaction mode is set to “object-oriented mode” by passing the values OSCON_FALSE to the parameter I_EXTERNAL_COMMIT. The top-level transaction has to be created explicitly by calling the method CREATE_TRANSACTION( ) of the transaction manager. The top-level transaction has to be started explicitly by calling the method START( ) of the related transaction proxy.
•
For an OO transaction, you can set the transaction mode to “object-oriented mode” by selecting the check box labeled OO-Transaction model in the transaction definition. The top-level transaction has to be created explicitly by calling the method CREATE_TRANSACTION( ) of the transaction manager. The top-level transaction has to be started explicitly by calling the method START( ) of the related transaction proxy.
230
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Updates Using ABAP Object Services
In addition to the transaction mode, the update mode can be set by the Transaction Service. Setting the update mode may happen before the top-level transaction is started. However, the update mode can also be changed in every transaction as long as the top-level transaction is not ended: •
•
•
•
If you do not set the update mode explicitly before using the Object Services the first time, the respective default mode (“asynchronous update mode”) is used. You can set the update mode together with the transaction mode using method CL_OS_SYSTEM=>INIT_AND_SET_MODE( ). Pass the corresponding value to the parameter I_UPDATE_MODE. You can set the update mode at any time before ending the top-level transaction by calling the method SET_MODE_UPDATE( ) of the transaction proxy. Pass the corresponding value to the parameter I_UPDATE_MODE. Allowed update modes can be set via constants of the global type pool OSCON: Asynchronous updates: OSCON_DMODE_DEFAULT or OSCON_DMODE_UPDATE_TASK. Synchronous updates: OSCON_DMODE_UPDATE_TASK_SYNC. Local updates: OSCON_DMODE_LOCAL. Direct updates: OSCON_DMODE_DIRECT. Note: You do not have to declare the usage of the type tool OSCON.
2011
© 2011 SAP AG. All rights reserved.
231
Unit 8: Object Services
BC414
Figure 107: Transaction Service – Code Sample
In the code sample displayed above, the Transaction Service is explicitly used for an executable program. Before accessing the Object Services the first time, the transaction mode and update mode is set by calling the method CL_OS_SYSTEM=>INIT_AND_SET_MODE( ). This method may only be called once, thus the code is assigned to the ABAP event LOAD-OF-PROGRAM. The transaction mode is set to “object-oriented”. In the ABAP event START-OF-SELECTION, the reference to the transaction manager is determined. Then, a transaction proxy object is created. This will be related to the top-level transaction, since no other transaction has been created before. Finally, the top-level transaction is started. If program units (e.g. methods) are called that define their own transactions, these transactions will be subtransactions in respect to the top-level transaction. Before the program is ended, the top-level transaction is ended. The Object Services will then create all update requests and assign them to the same LUW. Then, the Object Services will trigger the database update (COMMIT WORK). Compare the source code of the programs SAPMBC414_BOOK_MODEL_D2 and SAPMBC414_BOOK_MODEL_D3, PAI modules for screen 200 and 300. Now, the transaction mode and the update mode is defined explicitly. The transaction is ended using the END( ) method of the transaction proxy, not by COMMIT WORK.
232
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Updates Using ABAP Object Services
Facilitated Discussion Discuss open questions.
Discussion Questions Use the following questions to engage the participants in the discussion. Feel free to use your own additional questions. -
2011
© 2011 SAP AG. All rights reserved.
233
Unit 8: Object Services
BC414
Lesson Summary You should now be able to: • Explain how the Persistence Service lets the ABAP programmer work with relational database data in an object-oriented way • Describe how the Transaction Service supports the consistent change of persistent objects within the SAP transaction concept
234
© 2011 SAP AG. All rights reserved.
2011
BC414
Unit Summary
Unit Summary You should now be able to: • Explain how the Persistence Service lets the ABAP programmer work with relational database data in an object-oriented way • Describe how the Transaction Service supports the consistent change of persistent objects within the SAP transaction concept
2011
© 2011 SAP AG. All rights reserved.
235
Unit Summary
236
BC414
© 2011 SAP AG. All rights reserved.
2011
Unit 9 Appendix
223
Instructor notes can be found in each of the lessons contained in this unit.
Unit Overview This lesson contains additional material related to the topic “database updates”. In addition, the complete source code of the applications developed in this course is listed.
Unit Objectives After completing this unit, you will be able to: • • • • • • • • • • • •
2011
Call existing programs from your program using different techniques Explain the runtime architecture and the storage access options of these programs (ABAP memory and SAP memory) Appropriately implement the different methods for data transfer between your program and the programs called from within your program Find information on authorization objects Create authorization objects Find information on authorizations and profiles Perform authorization checks in your program Link the execution of transaction codes to authorization objects Explain the SAP table buffer Explain cluster tables Explain how the parameter _SCOPE influences the lifetime of SAP locks Use the ABAP statements COMMIT WORK and ROLLBACK WORK appropriately
© 2011 SAP AG. All rights reserved.
237
Unit 9: Appendix
BC414
Unit Contents Lesson: Runtime Architecture and Storage Access for Programs Called Within Programs ................................................................239 Lesson: Passing Data Between Programs ..................................249 Lesson: Authorization Checks ................................................258 Lesson: SAP Table Buffers ....................................................265 Lesson: Cluster Tables .........................................................270 Lesson: SAP Locks – Update and Lock Duration ..........................279 Lesson: COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises ........................................283 Exercise 9: Complete Solution for “Generating Customer Data Records” (Complete Transaction) ........................................287 Exercise 10: Complete Solution for “Creating/Canceling a Booking” (Complete Transaction) ....................................................295
238
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: 225
Lesson: Runtime Architecture and Storage Access for Programs Called Within Programs
Runtime Architecture and Storage Access for Programs Called Within Programs Lesson Duration: 30 Minutes
Lesson Overview This lesson explains runtime architecture and storage access for programs called within programs.
Lesson Objectives After completing this lesson, you will be able to: • •
Call existing programs from your program using different techniques Explain the runtime architecture and the storage access options of these programs (ABAP memory and SAP memory)
See Instructor Note in the course introduction.
Business Example You want to call further programs (function modules, reports, transactions) from your program and use the various storage access options.
2011
© 2011 SAP AG. All rights reserved.
239
Unit 9: Appendix
BC414
Programs Called Within Programs
Figure 108: Synchronous Calls
There are two ways of calling other ABAP programs on a synchronous basis from within a program. •
CALL FUNCTION, CALL TRANSACTION, SUBMIT AND RETURN: The processing of the called program is inserted, that is, the processing of the calling program is interrupted and then continued again after the called program has been completed.
•
SUBMIT , LEAVE TO TRANSACTION : The calling program is terminated and the called program is started.
SUBMIT and SUBMIT AND RETURN are used to execute programs that can be executed (program type “1” or “executable program”). CALL TRANSACTION and LEAVE TO TRANSACTION call transactions. For more details on SUBMIT, CALL TRANSACTION, and LEAVE TO TRANSACTION, refer to the keyword documentation integrated in the ABAP Editor.
240
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Runtime Architecture and Storage Access for Programs Called Within Programs
Figure 109: Asynchronous Call of a Function Module
Function modules can also be called asynchronously for executing processes in parallel. For this, the call must be supplied with the addition “STARTING NEW TASK ” stands for a user-individual name for the new independent task in which the function module will be processed. Asynchronously called function modules are processed in parallel to and independent of the calling program. You can receive the output of the function module (RECEIVE RESULTS FROM FUNCTION) in a later processing phase of the calling program. Function modules that are to be called using the addition STARTING NEW TASK must be marked as capable of being “called remotely” in their properties (process type: remote-capable module). For further information, see the keyword documentation in the ABAP Editor for CALL FUNCTION.
2011
© 2011 SAP AG. All rights reserved.
241
Unit 9: Appendix
BC414
Accessing ABAP and SAP Memory
Figure 110: Logical Memory Level Model
Several main sessions or modes can be active within a user session. A main session is usually linked to a window. Several internal sessions (up to 20) can run within one main session. One program is always processed within an internal session. Program data is only visible within the program. You can use SAP memory and ABAP memory to pass data between programs. Each SAP session has one SAP memory that can be accessed from all other modes of this session. The SAP memory serves as a storage area for field values and is retained for the duration of the session. You can use the contents of the SAP memory as default values for the respective screen input fields. Since all sessions can access the SAP memory, it is only conditionally suitable for transferring data between internal sessions of a main session. Instead, the ABAP memory should be used. Each main session has its own ABAP memory. Access to the ABAP memory is only possible from the respective internal sessions. It is provided as a storage area for internal program variables (fields, structures, internal tables, complex objects) so that they can be passed between internal sessions of a main session. When you end a main session, the corresponding ABAP memory is released automatically. Accessing the ABAP or SAP memory will be discussed in a later section of this unit.
242
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Runtime Architecture and Storage Access for Programs Called Within Programs
Figure 111: Storage Access for a Synchronous Function Module Call
When a function module is called, the corresponding function group is loaded into the current internal session and the called function module is processed. The processing of the calling program is interrupted and continued after the function module has been executed. Note that the loaded function group, together with the global data objects there, are kept in the internal session up to the end of the calling program. This means in particular that when a further function module of this group is called by the current main program, the new function group does not have to be reloaded and the global data objects of the function group have the same contents as they had after the first function module was called.
2011
© 2011 SAP AG. All rights reserved.
243
Unit 9: Appendix
BC414
Figure 112: Storage Access for “SUBMIT AND RETURN” and “CALL TRANSACTION”
The program called using CALL TRANSACTION or SUBMIT AND RETURN runs in a separately opened internal session that contains a new program context. After the called program has been completed, the new internal session is deleted and processing is continued for the calling program. The called program can end itself prematurely with the statement LEAVE PROGRAM.
244
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Runtime Architecture and Storage Access for Programs Called Within Programs
Figure 113: Storage Access for “SUBMIT”
If a program is called through the SUBMIT statement, the context of the calling program is removed from the current internal session and the called program is loaded for processing.
Figure 114: Storage Access for “LEAVE TO TRANSACTION”
2011
© 2011 SAP AG. All rights reserved.
245
Unit 9: Appendix
BC414
The statement LEAVE TO TRANSACTION removes all the internal sessions of the current main session and opens a new internal session for processing the called transaction. When this happens, the ABAP memory is initialized! This means, in particular, that you cannot pass any data to the called transaction through the ABAP memory.
Figure 115: Storage Access for an Asynchronous Function Module Call
Function modules that have been called asynchronously are processed on the same application server within a newly opened session. The processing takes place in parallel and independently of the calling program. You can receive the output of the function module (RECEIVE RESULTS FROM FUNCTION) in a later processing phase of the calling program. For further information, see the keyword documentation in the ABAP Editor for CALL FUNCTION and RECEIVE RESULTS FROM FUNCTION.
246
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Runtime Architecture and Storage Access for Programs Called Within Programs
Facilitated Discussion –
Discussion Questions Use the following questions to engage the participants in the discussion. Feel free to use your own additional questions. –
2011
© 2011 SAP AG. All rights reserved.
247
Unit 9: Appendix
BC414
Lesson Summary You should now be able to: • Call existing programs from your program using different techniques • Explain the runtime architecture and the storage access options of these programs (ABAP memory and SAP memory)
248
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: 233
Lesson: Passing Data Between Programs
Passing Data Between Programs Lesson Duration: 30 Minutes
Lesson Overview This lesson explains methods for passing data between calling programs and called programs.
Lesson Objectives After completing this lesson, you will be able to: •
Appropriately implement the different methods for data transfer between your program and the programs called from within your program
See Instructor Note in the course introduction.
Business Example You want to appropriately implement the different methods for data transfer between your program and the programs called from within your program.
2011
© 2011 SAP AG. All rights reserved.
249
Unit 9: Appendix
BC414
Passing Data Between Programs
Figure 116: Overview – Passing Data Between Programs
There are different ways of passing on data to a program when it is called: 1. 2. 3. 4. 5.
Through the interface of the called program (interface of a method, function module, subroutine, or dialog module, standard selection screen of a report) Through the ABAP memory Through the SAP memory Through database tables Through files on your presentation server or application server
For further information about transferring data using database tables and the shared buffer, refer to the keyword documentation in the ABAP Editor for the terms EXPORT and IMPORT. For further information about transferring data between an ABAP program and your presentation server, refer to the documentation of function modules GUI_UPLOAD and GUI_DOWNLOAD. For further information about transferring data between an ABAP program and your application server, refer to the keyword documentation in the ABAP Editor for the terms TRANSFER and READ DATASET.
250
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Passing Data Between Programs
Figure 117: Data Transfer Through the Interface of a Program Unit
Function modules have an interface that you can use to pass data between the calling program and the function module itself (there is also a comparable mechanism for ABAP subroutines). If you are calling an ABAP program that has a standard selection screen, you can pass values to the input fields on the selection screen. There are two ways to do this: • •
2011
You enter a variant for the call (SUBMIT addition USING SELECTION-SET). By entering actual values for the input fields on the selection screen during the call (see next figure).
© 2011 SAP AG. All rights reserved.
251
Unit 9: Appendix
BC414
Figure 118: SUBMIT . . . WITH
The SUBMIT addition VIA SELECTION-SCREEN is used to start the called program through the display of its selection screen. If this addition is not specified, the system executes the program without processing its selection screen. In this case, you can still pass values for the input fields of its selection screen to the program (WITH addition; for syntax, see above). Hint: If you use the “pattern” key in the ABAP Editor to insert a program call using SUBMIT, the system lists – in the inserted command – all the selection screen elements of the program to be called by means of the WITH addition. For more information about the WITH addition, see the ABAP Editor keyword documentation for the term “SUBMIT WITH”.
252
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Passing Data Between Programs
Figure 119: Passing Data Using the ABAP Memory
Using the statement EXPORT TO MEMORY ID , you can copy variables of your program with their current values as data clusters into the ABAP memory. The ID you specify here uniquely identifies the created data cluster (maximum 32 characters). An export to the same memory ID overwrites the corresponding data cluster. The IMPORT FROM MEMORY ID statement allows you to copy data from the specified data cluster into the fields of your ABAP program. The source and target variables must have the same format in the write and read programs. The statement FREE MEMORY ID deletes the corresponding data cluster. FREE MEMORY without the ID addition deletes the entire ABAP memory of the current external session. It is possible to read only part of the variables in the data cluster using IMPORT.
2011
© 2011 SAP AG. All rights reserved.
253
Unit 9: Appendix
BC414
Figure 120: Data Transfer Through the SAP Memory
Using the Object Navigator, you can define parameter IDs for the SAP system (→ entries in table TPARA). The ID parameter must not be longer than 20 characters maximum. Using the SET PARAMETER ID statement, ABAP programs can set a value in the SAP memory of the current session for the specified parameter. This value can be read by all programs of the same session by means of the GET PARAMETER ID statement. A parameter in the SAP memory can also be set by a user entry in a screen field. For this purpose, the screen field must be defined through a data element that is linked with the respective parameter ID. In addition, the SET functions must be activated in the screen field properties. Conversely, a screen input field can display the corresponding parameter value in the SAP memory to the user as input proposal. Prerequisites for this are: • • •
The screen field must be defined through a data element that is linked with the respective parameter ID. The GET function of the screen filed must be active. The screen field must only be occupied by the initial value within the program.
In this way, programs and screens can exchange data through the SAP memory during the same session. For information on the parameter ID linked to a screen input field, choose the F1 help on the input screen →Technical Info.
254
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Passing Data Between Programs
Figure 121: Screen Default Value Through the SAP Memory
The above example shows how you can set default values for input fields of a transaction called by a program. In this way, you can excute the transaction, if required, without displaying the first screen (addition: AND SKIP FIRST SCREEN). Here, you should take note of the prerequisites that must be fulfilled for displaying a default value from the SAP memory by a screen field (see previous figure).
2011
© 2011 SAP AG. All rights reserved.
255
Unit 9: Appendix
BC414
Facilitated Discussion –
Discussion Questions Use the following questions to engage the participants in the discussion. Feel free to use your own additional questions. –
256
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Passing Data Between Programs
Lesson Summary You should now be able to: • Appropriately implement the different methods for data transfer between your program and the programs called from within your program
2011
© 2011 SAP AG. All rights reserved.
257
Unit 9: Appendix
Lesson: 240
BC414
Authorization Checks Lesson Duration: 45 Minutes
Lesson Overview Contents: • • •
Authorization Objects Authorizations Authorization checks
Lesson Objectives After completing this lesson, you will be able to: • • • • •
Find information on authorization objects Create authorization objects Find information on authorizations and profiles Perform authorization checks in your program Link the execution of transaction codes to authorization objects
See Instructor Note in the course introduction.
Business Example You want to link the execution of transaction codes to authorization objects.
258
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Authorization Checks
Program Controlled Authorization Checks
Figure 122: The Authorization Concept
To ensure that each user can only access the data for which he or she has explicit authorization, the application developer must implement the authorization check in his or her application program. For this purpose, you must first develop a correspondingly logical, application-related authorization model (which authorization should be checked during which user action?). Then, in the ABAP Workbench, you must create the authorization object, together with authorization values, that suits the model. Authorizations related to this object are assigned to the user by means of an authorization profile. In the application program, the application developer must check if the corresponding authorization exists for the current user in order to control further processing of the program in accordance with the check results. The check must be performed before the action required by the user is performed. SAP has included the authorization concept in the implementation of its software. You, the customer, must also do this when you enhance the SAP software or whenever you implement new applications in order to ensure data access authorization. The SAP system contains tools that help you to manage authorizations and assign them to user master records.
2011
© 2011 SAP AG. All rights reserved.
259
Unit 9: Appendix
BC414
Figure 123: Authorization Object/Authorization (Example)
You can create several different authorizations for an authorization object. Existing authorizations can be grouped into one authorization profile. An authorization profile should contain all authorizations that are required for executing certain tasks, that is, all the authorizations that are checked in the current user master as to whether they exist when the respective programs/transactions are called. Authorization profiles can be assigned to a user. You can create authorization objects with required fields and authorizations. The maintenance transaction for authorization fields, authorization objects, and authorizations can be found in the SAP Menu under the following path: Tools → ABAP Workbench → Development → Other Tools → Authorization Objects. For more information, see the ABAP Editor keyword documentation under Authorization concept.
Figure 124: Performing Authorization Checks
260
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Authorization Checks
In the application program, you must perform a check before executing the related task. You must check whether the authorization you have defined as necessary exists so that you can control further processing of the program in accordance with the check result. You use the AUTHORITY-CHECK statement to implement this. All the authorization fields, together with the evaluations, must be specified in the AUTHORITY-CHECK statement. If you wish to check whether a particular authorization exists, and the content of the authorization fields does not matter here, write “DUMMY” instead of “FIELD ” behind this authorization field. The check is performed without consideration of the corresponding field. The AUTHORITY-CHECK statement returns the check result by setting the value of the system field SY-SUBRC: • •
0 if the caller has the specified authorization. Different other values if the caller does not have the specified authorization.
You must use this return code to decide how you want to proceed in the program (read/change data, issue an error message or a different action). In the ABAP Editor, use the template for the AUTHORITY-CHECK statement in order to include it in your program.
Figure 125: Authorization Checks for Transactions
At transaction start, the system automatically checks whether the specified transaction code is known, that is, whether it is marked in the table TSTC and whether this is locked. The system then checks whether the caller has the authorization to call the transaction, that is, if he or she has a corresponding authorization for the authorization object S_TCODE.
2011
© 2011 SAP AG. All rights reserved.
261
Unit 9: Appendix
BC414
Then, the system runs through the default authorization checks assigned to the transaction. This means the system checks whether the caller has the default authorization assigned to the transaction. The assignment “Transaction/Default authorization” is specified in the definition of the transaction and is stored in the table TSTCA. Only when all these checks have run successfully will the transaction be allowed to start by the system. Otherwise, processing is terminated with an error message. The authorization checks contained in the application program (AUTHORITY-CHECK) are executed only at transaction runtime.
262
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Authorization Checks
Facilitated Discussion –
Discussion Questions Use the following questions to engage the participants in the discussion. Feel free to use your own additional questions. –
2011
© 2011 SAP AG. All rights reserved.
263
Unit 9: Appendix
BC414
Lesson Summary You should now be able to: • Find information on authorization objects • Create authorization objects • Find information on authorizations and profiles • Perform authorization checks in your program • Link the execution of transaction codes to authorization objects
264
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: 246
Lesson: SAP Table Buffers
SAP Table Buffers Lesson Duration: 15 Minutes
Lesson Overview This lesson explains the SAP table buffer.
Lesson Objectives After completing this lesson, you will be able to: •
Explain the SAP table buffer
See Instructor Note in the course introduction.
Business Example You want to learn about the details and architecture of the SAP table buffer and use them to access tables efficiently.
SAP Table Buffer
2011
© 2011 SAP AG. All rights reserved.
265
Unit 9: Appendix
BC414
Figure 126: SAP Table Buffer
SAP database tables can be buffered at the application server level. The aims of buffering are to: • •
Reduce the time needed to access data with read accesses. Data on the application server can be accessed more quickly than data on the database. Reduce the load on the database. Reading the data from application server buffers reduces the number of database accesses.
The buffered tables are accessed exclusively via database interface mechanisms. When the system executes a Native SQL command, it bypasses the database interface of the application server. Consequently, it does not use the table buffer in the SAP system for read or change accesses. You should, therefore, not use Native SQL statements for tables that are buffered, since inconsistencies could occur between the data in the database and that in the buffer. Not every Open SQL read access to buffered tables reads buffered data. For information on which operations for read accesses are performed directly on the database, refer to the keyword documentation for SELECT.
Updating SAP Table Buffer
Figure 127: Updating SAP Table Buffer
Open SQL commands that change data update both the data on the database and the buffers of the application server on which the program updating the database is running.
266
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: SAP Table Buffers
If a table is buffered on several application servers, synchronization of the other buffers is delayed and triggered as follows: •
•
When data on the database is changed by one of the application servers (more precisely, a program that executes an appropriate OPEN SQL command on one of the application servers), the changed data is registered as such in table DDLOG on the database. The application servers read this table at periodic intervals. If an application server finds relevant entries, the buffer contents are marked in the buffer as being no longer up-to-date. The next read access to the data in the buffered table is performed by the database interface on the database. The buffer is updated at the same time.
The time between the read accesses to the DDLOG table (invalidation period of the buffers) can be set using the profile parameter rdisp/bufreftime.
Buffering Types
Figure 128: Buffering Types
There are three different types of buffering: • •
•
2011
Resident buffering (100%): The whole table is loaded to the table buffer when the table is accessed for the first time. Generic buffering: A generic key (first n key fields) must be specified in the technical settings for the table in the ABAP Dictionary. This is used to divide the contents of the table into generic areas. If data is accessed using one of the generic keys, the entire generic area is loaded to the table buffer. Client-dependent tables are often buffered generically for each client. Single-record buffering: Only single records are read by the database and stored in the table buffer.
© 2011 SAP AG. All rights reserved.
267
Unit 9: Appendix
BC414
Facilitated Discussion –
Discussion Questions Use the following questions to engage the participants in the discussion. Feel free to use your own additional questions. –
268
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: SAP Table Buffers
Lesson Summary You should now be able to: • Explain the SAP table buffer
2011
© 2011 SAP AG. All rights reserved.
269
Unit 9: Appendix
Lesson: 250
BC414
Cluster Tables Lesson Duration: 45 Minutes
Lesson Overview This lesson explains cluster tables.
Lesson Objectives After completing this lesson, you will be able to: •
Explain cluster tables
See Instructor Note in the course introduction.
Business Example You want to use cluster tables to store data for your applications.
Data Cluster
Figure 129: Data Cluster
270
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Cluster Tables
A data cluster is a combination of data objects. Data objects are fields, structured fields, internal tables, and complex structures derived from these. You process data clusters using the ABAP commands EXPORT, IMPORT, and DELETE. Data clusters can be stored in cluster databases tables. You subdivide a cluster database table in the ABAP Dictionary into application areas according to your own criteria and using logically related data clusters. The application area name comprises two characters and is freely selectable. You identify the cluster within the application area using an ID (cluster ID).
Syntax: EXPORT to cluster database table
Figure 130: Syntax – EXPORT to Cluster Database Table
For exporting, you require a cluster database table. The table INDX is a cluster database table for general purposes. Cluster database tables should be created as transparent tables in the ABAP Dictionary and must have a standardized structure. For more information, see the online documentation for the EXPORT command. In the EXPORT statement, specify the data objects of your cluster in a list. To perform the export, specify the cluster database table and the application area within the cluster database table. You identify the cluster itself using the cluster ID. If you want to define a data object name in the cluster that is different from the one in the program, use the optional addition FROM. The data objects can be listed in any order. With an export, there is no write protection facility. Existing clusters, therefore, are overwritten if an EXPORT is performed again. The data is stored in compressed form in the cluster database table.
2011
© 2011 SAP AG. All rights reserved.
271
Unit 9: Appendix
BC414
In your program, you declare an application area for your cluster database table at the start using the TABLES statement. Caution: Header lines in internal tables cannot be exported. Usually, only the table contents are exported. If you are working within language constructions from the object-oriented ABAP extension (ABAP Objects), you must use the name substitutions marked as optional on this slide.
Syntax: IMPORT and DELETE
Figure 131: Syntax – IMPORT and DELETE
In the IMPORT statement, you only need to list a subset of the data objects of your cluster in any order. If you want to define a data object name in the program that is different from the one in the cluster, use the optional addition TO. After the IMPORT, the system outputs a return code (SY-SUBRC). This return code refers to the cluster, rather than to an individual object in the cluster. If the cluster does not exist, the return code is different from zero. The structure of the fields, structures, and internal tables to be imported must correspond to the structure of the objects exported to the data set. If this is not the case, a runtime error occurs. In addition, the objects must be imported using the same name with which they were exported – otherwise, they are not imported. If the cluster exists, the return code is 0, irrespective of whether objects have been imported.
272
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Cluster Tables
Caution: Here too, only the actual table contents of internal tables are imported and therefore the header lines remain unchanged. DELETE always deletes the entire cluster. You cannot delete an individual data object within the cluster. After DELETE, the system outputs a return code. If you are working within language constructions from the object-oriented ABAP extension (ABAP Objects), you must use the name substitutions marked as optional on this slide.
ABAP Cluster Database Tables
Figure 132: ABAP Cluster Database Tables
You can create your own ABAP cluster databases. To do this, proceed as follows: • • • • • • •
2011
Define a database table as a transparent table in the ABAP Dictionary. This table represents its cluster database table. Build the table structure as shown above. The MANDT field can be omitted (it is filled automatically if it exists). The fields RELID, SRTF2, CLUSTR, CLUSTD and the cluster ID are filled automatically within an EXPORT action. Any user-defined fields must be filled before the EXPORT. They can then be evaluated after the IMPORT. You can choose the field names for the cluster ID and your own fields. The remaining field names are specified by the system. The length of the part used for the data cluster is calculated from the total length of the structure minus the length of the first six fields.
© 2011 SAP AG. All rights reserved.
273
Unit 9: Appendix
BC414
Key of Database Table INDX
Figure 133: Key of Database Table INDX
The INDX database is an example of a database table in which you can store data clusters. It is available in your system by default and has a key length of 31 bytes. You can display the table structure using the keyword help for the table structure INDX. The key consists of a client, area, cluster ID, and subsequent record number. The cluster ID has a default length of 22 bytes, but can have any length in a cluster database table. With larger data clusters, the runtime system appends subsequent records with the same length automatically.
274
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Cluster Tables
Example: Catalog for INDX
Figure 134: Example Catalog for INDX
Apart from the key fields and the data cluster, the structure of the database INDX also includes optional fields for administrative information (for example, change, validity date, created by, see structure INDX). You use the SELECT statement to access the key and administration fields - for example, to create a catalog. The system only fills the administration data fields if you fill them before the EXPORT using the MOVE statement (for example, MOVE SY-DATUM TO INDX-AEDAT).
2011
© 2011 SAP AG. All rights reserved.
275
Unit 9: Appendix
BC414
Cluster Tables and Transparent Tables
Figure 135: Cluster Database Tables and Transparent Tables
Cluster database tables contain the cluster data in the desired form. Large quantities of data can be read via the internal cluster table administration using a limited number of accesses (I/Os). Standardization requires that data from several database tables is collected in internal tables, which entails several I/Os. This can, however, be achieved effectively using joins to ABAP Open SQL introduced in release 3.1. Refer also to the unit on ABAP Open SQL. The advantage of this is that individual objects can be read from various tables and linked to each other. In cluster tables, however, only the data from one cluster can be read. Links to data in other clusters are not possible. Access to cluster data requires knowledge of the cluster ID and the application area. The access also returns, at most, the data of one cluster ID, in other words, it does not return several clusters, as is the case with a SELECT loop. In contrast to this, data can be determined in transparent tables on the basis of any logical expression.
276
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: Cluster Tables
Facilitated Discussion –
Discussion Questions Use the following questions to engage the participants in the discussion. Feel free to use your own additional questions. –
2011
© 2011 SAP AG. All rights reserved.
277
Unit 9: Appendix
BC414
Lesson Summary You should now be able to: • Explain cluster tables
278
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: 258
Lesson: SAP Locks – Update and Lock Duration
SAP Locks – Update and Lock Duration Lesson Duration: 5 Minutes
Lesson Overview This lesson explains the influence of the parameter _SCOPE on the locking duration.
Lesson Objectives After completing this lesson, you will be able to: •
Explain how the parameter _SCOPE influences the lifetime of SAP locks
No demo programs exist for this lesson.
Business Example You want to learn more about SAP locks.
Update and Lock Durations for _scope = 1
Figure 136: Update and Lock Durations for _scope = 1
2011
© 2011 SAP AG. All rights reserved.
279
Unit 9: Appendix
BC414
For _SCOPE = 1, the dialog program contains the locks that it generates. The locks remain set until they are released, either using the function module DEQUEUE_, or implicitly at the end of the program. This includes the ABAP statements LEAVE PROGRAM, LEAVE TO TRANSACTION '' and SUBMIT , and termination messages (message type “A” or “X”). If the transaction uses the asynchronous update, the update program has no guarantee that the data to be changed has not been locked already by another user. For this reason, you should not use _SCOPE = 1 for asynchronous updates.
Update and Lock Durations for _scope = 3
Figure 137: Update and Lock Durations for _scope = 3
If you are using asynchronous update and want to be sure that the locks generated in the dialog program remain set for longer than the V1 update function modules are active, you can use the addition _SCOPE = 3. In this case, the lock is shared between the dialog program and the update program. Lock entries that you generate with _SCOPE = 3 must be released both by the dialog program and by the update program. Lock entries with _SCOPE = 3 are only used in a few special cases.
280
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: SAP Locks – Update and Lock Duration
Facilitated Discussion –
Discussion Questions Use the following questions to engage the participants in the discussion. Feel free to use your own additional questions. –
2011
© 2011 SAP AG. All rights reserved.
281
Unit 9: Appendix
BC414
Lesson Summary You should now be able to: • Explain how the parameter _SCOPE influences the lifetime of SAP locks
282
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: 261
Lesson: COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises
COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises Lesson Duration: 30 Minutes
Lesson Overview This lesson explains the impact of the ABAP statements COMMIT WORK and ROLLBACK WORK.
Lesson Objectives After completing this lesson, you will be able to: •
Use the ABAP statements COMMIT WORK and ROLLBACK WORK appropriately
See Instructor Note in the course introduction.
Business Example You want to use the ABAP statements COMMIT WORK and ROLLBACK WORK appropriately.
Actions for COMMIT WORK •
Actions on the database –
2011
• •
All updates that were made during the current dialog step are committed. – All database locks are released. – All open database cursors are closed (even those that were opened using WITH HOLD). All subroutines registered using PERFORM ON COMMIT are executed Update is triggered (CALL FUNCTION IN UPDATE TASK)
•
– COMMIT WORK – does not wait until the end of the update. – COMMIT WORK AND WAIT – waits until the end of the update. – For a local update: Immediate execution of the update modules. Locks ( _SCOPE = 2 ) are:
© 2011 SAP AG. All rights reserved.
283
Unit 9: Appendix
BC414
– –
NOT released if no update requests have come up. Transferred to the update and released when it has ended (however, in case of an error the locks may not be removed automatically)
Actions for ROLLBACK WORK •
Current DB LUW (DB Rollback) is ended:
•
– All changes made in the current dialog step are revoked. – All database locks are released. – All open cursors are closed. Data in the corresponding SAP LUW is deleted: –
•
Registration of update modules registered with CALL FUNCTION IN UPDATE TASK is rejected. – The same applies to the subroutines registered with PERFORM ON COMMIT. – Function modules that were registered for transactional or queued RFC (CALL FUNCTION IN BACKGROUND TASK) are not executed. SAP locks are released ( _scope = 2 )
Actions That a ROLLBACK WORK Does Not Perform • • • • •
284
Undo updates that were committed previously. Undo updates to internal tables and other data objects (program context). Reset values in calculated “contexts”. Undo changes made to operating system files. Undo actions that were executed during synchronous RFCs.
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises
SAP LUW: Overall View
Figure 138: SAP LUW: Overall View
2011
© 2011 SAP AG. All rights reserved.
285
Unit 9: Appendix
286
BC414
© 2011 SAP AG. All rights reserved.
2011
BC414
265
Lesson: COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises
Exercise 9: Complete Solution for “Generating Customer Data Records” (Complete Transaction) Exercise Duration: 0 Minutes
Exercise Objectives After completing this exercise, you will be able to: • -
Business Example -
Task: Complete Solution for “Generating Customer Data Records” Complete Transaction 1.
2011
-
© 2011 SAP AG. All rights reserved.
287
Unit 9: Appendix
BC414
Solution 9: Complete Solution for “Generating Customer Data Records” (Complete Transaction) Task: Complete Solution for “Generating Customer Data Records” Complete Transaction 1.
a)
Model Solution SAPMBC414_CUST_COMPLEX_S
Module Pool *&---------------------------------------------------------------------* *& Modulpool SAPMBC414_CUST_COMPLEX_S *&---------------------------------------------------------------------* INCLUDE MBC414_CUST_COMPLEX_STOP. INCLUDE MBC414_CUST_COMPLEX_SO01. INCLUDE MBC414_CUST_COMPLEX_SI01. INCLUDE MBC414_CUST_COMPLEX_SF01.
SCREEN 100 PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE clear_okcode.
PROCESS AFTER INPUT. MODULE exit AT EXIT-COMMAND. FIELD scustom-name MODULE mark_changed ON REQUEST. MODULE user_command_0100.
Continued on next page
288
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises
TOP Include - Include MBC414_CUST_COMPLEX_STOP *&---------------------------------------------------------------------* *& Include MBC414_CUST_COMPLEX_STOP *&---------------------------------------------------------------------* PROGRAM sapmbc414_cust_complex_s MESSAGE-ID bc414. TYPES gty_flag TYPE c LENGTH 1. DATA gv_result
TYPE gty_flag.
DATA gv_data_changed TYPE gty_flag. DATA ok_code
TYPE syucomm.
TABLES: scustom.
PBO Modules - Include MBC414_CUST_COMPLEX_SO01 *----------------------------------------------------------------------* ***INCLUDE MBC414_CUST_COMPLEX_SO01 *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *&
Module
CLEAR_OKCODE
OUTPUT
*&---------------------------------------------------------------------* MODULE clear_okcode OUTPUT. CLEAR ok_code. ENDMODULE.
" CLEAR_OKCODE
OUTPUT
*&---------------------------------------------------------------------* *&
Module
STATUS_0100
OUTPUT
*&---------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'DYN_0100'. SET TITLEBAR 'DYN_0100'.
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
289
Unit 9: Appendix
BC414
ENDMODULE.
" STATUS_0100
OUTPUT
PAI Modules - Include MBC414_CUST_COMPLEX_SI01 *----------------------------------------------------------------------* ***INCLUDE MBC414_CUST_COMPLEX_SI01 *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *&
Module
EXIT
INPUT
*&---------------------------------------------------------------------* MODULE exit INPUT. CASE ok_code. WHEN 'EXIT'. IF sy-datar IS INITIAL AND gv_data_changed IS INITIAL. *
no changes on screen 100 LEAVE PROGRAM. ELSE. PERFORM ask_save CHANGING gv_result. CASE gv_result. WHEN '1'. ok_code = 'SAVE&EXIT'. WHEN '2'. LEAVE PROGRAM. WHEN 'A'. SET SCREEN '0100'. ENDCASE. ENDIF. WHEN 'CANCEL'. IF sy-datar IS INITIAL AND gv_data_changed IS INITIAL.
*
no changes on screen 100 LEAVE TO SCREEN 0. ELSE. PERFORM ask_loss. ENDIF. ENDCASE.
ENDMODULE.
" EXIT
INPUT
Continued on next page
290
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises
*&---------------------------------------------------------------------* *&
Module
USER_COMMAND_0100
INPUT
*&---------------------------------------------------------------------* MODULE user_command_0100 INPUT. CASE ok_code. WHEN 'SAVE&EXIT'. PERFORM save CHANGING scustom. LEAVE PROGRAM. WHEN 'SAVE'. IF gv_data_changed IS INITIAL. SET SCREEN '0100'. ELSE. PERFORM save CHANGING scustom. SET SCREEN '0000'. ENDIF. WHEN 'BACK'. IF gv_data_changed IS INITIAL. SET SCREEN '0000'. ELSE. PERFORM ask_save CHANGING gv_result. CASE gv_result. WHEN '1'. PERFORM save CHANGING scustom. SET SCREEN '0000'. WHEN '2'. SET SCREEN '0000'. WHEN 'A'. SET SCREEN '0100'. ENDCASE. ENDIF. ENDCASE. ENDMODULE.
" USER_COMMAND_0100
INPUT
*&---------------------------------------------------------------------* *&
Module
MARK_CHANGED
INPUT
*&---------------------------------------------------------------------* MODULE mark_changed INPUT. * set flag to mark changes were made on screen 100 gv_data_changed = abap_true. ENDMODULE.
" MARK_CHANGED
INPUT
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
291
Unit 9: Appendix
BC414
FORM Routines - Include MBC414_CUST_COMPLEX_SF01 *----------------------------------------------------------------------* ***INCLUDE MBC414_CUST_COMPLEX_SF01 *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *&
Form
NUMBER_GET_NEXT
*&---------------------------------------------------------------------* *
PT_BOOKINGS
text
*
PT_BOOKINGS_MOD
text
*
-->PT_CD
text
*----------------------------------------------------------------------* FORM create_change_document USING pt_bookings_mod TYPE gty_t_sbook pt_cd
TYPE gty_t_cd.
DATA ls_sbook_n TYPE sbook. DATA ls_sbook_o TYPE sbook. DATA ls_sbook
TYPE vsbook.
LOOP AT pt_bookings_mod INTO ls_sbook_n. *
read unchanged data from buffer table into work area READ TABLE pt_cd FROM ls_sbook_n INTO ls_sbook_o.
*
build up table of bookings before changes MOVE-CORRESPONDING ls_sbook_o TO ls_sbook. APPEND ls_sbook TO ysbook.
*
build up table of bookings after changes MOVE-CORRESPONDING ls_sbook_n TO ls_sbook. APPEND ls_sbook TO xsbook. ENDLOOP.
* define objectid from key fields of sbook CONCATENATE ls_sbook-mandt ls_sbook-carrid ls_sbook-connid ls_sbook-fldate INTO objectid SEPARATED BY space. * fill interface parameters for function call (which itself is * encapsulated in form CD_CALL_BC414_SBOOK_TAB tcode
= sy-tcode.
utime
= sy-uzeit.
udate
= sy-datum.
username
= sy-uname.
upd_sbook = 'U'.
Continued on next page
310
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises
* perform calls the neccessary function to create change document * 'in update task' PERFORM cd_call_bc414_sbook_tab. ENDFORM.
" CREATE_CHANGE_DOCUMENT
FORMs - Include MBC414_BOOK_CDOC_SF02 *----------------------------------------------------------------------* *
INCLUDE MBC414_BOOK_CDOC_SF02
*----------------------------------------------------------------------* *&---------------------------------------------------------------------* *&
Form
CHECK_SFLIGHT
*&---------------------------------------------------------------------* *
PV_CARRID
text
*
-->PV_CONNID
text
*
-->PV_FLDATE
text
*
PT_BOOKINGS_MOD
text
*
-->PS_SDYN_CONN
text
*----------------------------------------------------------------------* FORM modify_bookings USING pt_bookings_mod TYPE gty_t_sbook ps_sdyn_conn
TYPE sdyn_conn.
CALL FUNCTION 'UPDATE_SBOOK' IN UPDATE TASK EXPORTING it_sbook = pt_bookings_mod. CALL FUNCTION 'UPDATE_SFLIGHT' IN UPDATE TASK EXPORTING iv_carrid = ps_sdyn_conn-carrid iv_connid = ps_sdyn_conn-connid iv_fldate = ps_sdyn_conn-fldate.
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
313
Unit 9: Appendix
BC414
ENDFORM.
" MODIFY_BOOKINGS
*&---------------------------------------------------------------------* *&
Form
SAVE_NEW_BOOKING
*&---------------------------------------------------------------------* *
-->PS_SDYN_BOOK
text
*----------------------------------------------------------------------* FORM save_new_booking USING ps_sdyn_book TYPE sdyn_book. DATA ls_sbook
TYPE sbook.
MOVE-CORRESPONDING ps_sdyn_book TO ls_sbook. * get customer name SELECT SINGLE name FROM scustom INTO ls_sbook-passname WHERE id = ls_sbook-customid. IF ls_sbook-class IS INITIAL. ls_sbook-class = 'Y'. ENDIF. CALL FUNCTION 'INSERT_SBOOK' IN UPDATE TASK EXPORTING is_sbook = ls_sbook. CALL FUNCTION 'UPDATE_SFLIGHT' IN UPDATE TASK EXPORTING iv_carrid = ls_sbook-carrid iv_connid = ls_sbook-connid iv_fldate = ls_sbook-fldate. ENDFORM.
" SAVE_NEW_BOOKING
Include FBC414_SBOOK_TABCDF DATA: OBJECTID
TYPE CDHDR-OBJECTID,
TCODE
TYPE CDHDR-TCODE,
PLANNED_CHANGE_NUMBER
TYPE CDHDR-PLANCHNGNR,
UTIME
TYPE CDHDR-UTIME,
UDATE
TYPE CDHDR-UDATE,
USERNAME
TYPE CDHDR-USERNAME,
CDOC_PLANNED_OR_REAL
TYPE CDHDR-CHANGE_IND,
Continued on next page
314
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises
CDOC_UPD_OBJECT
TYPE CDHDR-CHANGE_IND VALUE 'U',
CDOC_NO_CHANGE_POINTERS TYPE CDHDR-CHANGE_IND.
Include FBC414_SBOOK_TABCDV * table with the NEW content of: SBOOK DATA: XSBOOK TYPE STANDARD TABLE OF VSBOOK. * table with the OLD content of: SBOOK DATA: YSBOOK TYPE STANDARD TABLE OF VSBOOK. DATA: UPD_SBOOK TYPE C.
Include FBC414_SBOOK_TABCDC FORM CD_CALL_BC414_SBOOK_TAB. IF
( UPD_SBOOK NE SPACE )
. CALL FUNCTION 'BC414_SBOOK_TAB_WRITE_DOCUMENT' IN UPDATE TASK EXPORTING OBJECTID
= OBJECTID
TCODE
= TCODE
UTIME
= UTIME
UDATE
= UDATE
USERNAME
= USERNAME
PLANNED_CHANGE_NUMBER
= PLANNED_CHANGE_NUMBER
OBJECT_CHANGE_INDICATOR = CDOC_UPD_OBJECT PLANNED_OR_REAL_CHANGES = CDOC_PLANNED_OR_REAL NO_CHANGE_POINTERS
= CDOC_NO_CHANGE_POINTERS
* updateflag of SBOOK UPD_SBOOK = UPD_SBOOK TABLES XSBOOK = XSBOOK
Continued on next page
2011
© 2011 SAP AG. All rights reserved.
315
Unit 9: Appendix
BC414
YSBOOK = YSBOOK . ENDIF. CLEAR PLANNED_CHANGE_NUMBER. ENDFORM.
316
© 2011 SAP AG. All rights reserved.
2011
BC414
Lesson: COMMIT WORK / ROLLBACK WORK (Details and Summary) + Complete Answers for the Exercises
Lesson Summary You should now be able to: • Use the ABAP statements COMMIT WORK and ROLLBACK WORK appropriately
2011
© 2011 SAP AG. All rights reserved.
317
Unit Summary
BC414
Unit Summary You should now be able to: • Call existing programs from your program using different techniques • Explain the runtime architecture and the storage access options of these programs (ABAP memory and SAP memory) • Appropriately implement the different methods for data transfer between your program and the programs called from within your program • Find information on authorization objects • Create authorization objects • Find information on authorizations and profiles • Perform authorization checks in your program • Link the execution of transaction codes to authorization objects • Explain the SAP table buffer • Explain cluster tables • Explain how the parameter _SCOPE influences the lifetime of SAP locks • Use the ABAP statements COMMIT WORK and ROLLBACK WORK appropriately
318
© 2011 SAP AG. All rights reserved.
2011
BC414
Course Summary
Course Summary You should now be able to: • • • • •
2011
Use ABAP Open SQL statements for database updates Implement the SAP locking concept for database updates Implement different update techniques for database changes Create change documents to log database changes Use numbers derived from number range objects
© 2011 SAP AG. All rights reserved.
319
Course Summary
320
BC414
© 2011 SAP AG. All rights reserved.
2011
Index A ABAP memory, 242, 253 authorization check, 261 concept, 259
C change document object, 197 generated objects, 198 change documents concept, 191 function library, 205 implementation, 200 relevant fields, 195 starage, 193 client/server architecture, 35 COMMIT WORK, 33, 283
D data cluster, 271 DELETE, 272 EXPORT, 271 IMPORT, 272 database commit explicit, 33 implicit, 34 database locks, 52 database LUW, 33 database rollback explicit, 34 implicit, 34 DELETE, 13
G GET parameter, 254
I inline update, 97
L lock module, 59
2011
lock object, 58 lock table, 53
N native SQL, 3 number assignment buffer modes, 169 concept, 156 external, 166 function library, 173 internal, 166 number range object, 161
O object services, 222 open SQL, 3 client specification, 5 DELETE, 12 INSERT, 6 MODIFY, 10 UPDATE, 8
P passing data between programs, 250 PERFORM ON COMMIT, 99 persitence service, 222 programs calls, 143, 240 impact on lock cumulation, 149 impact on LUW, 145
R ROLLBACK WORK, 14, 34, 284
S SAP locks, 51 concept, 53 incorrect usage, 81 lock actions, 66
© 2011 SAP AG. All rights reserved.
321
Index
BC414
lock argument, 69 lock container, 72 lock modes, 74 lock module, 59, 68 lock module parameters, 71 lock object, 58 lock parameters, 68 lock table, 70 optimistic lock pattern, 79 pessimistic lock pattern, 78 release, 67 set, 67 SAP LUW, 33 SAP memory, 242, 254 session internal, 242 main, 242 SET parameter, 254 storage accesses, 243
T
buffer type, 267 synchronization, 266 transaction service, 226 transaction manager, 229 transaction mode, 230 update mode, 231
U update asynchronous mode, 117 concept, 106 local mode, 119 locks, 123 modes, 117 process flow, 106 request, 112 _SCOPE = 1, 280 _SCOPE = 3, 280 synchronous mode, 118 technical implementation, 110 V1/V2, 120 update module, 110
table buffer, 266
322
© 2011 SAP AG. All rights reserved.
2011
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.
2011
© 2011 SAP AG. All rights reserved.
323
View more...
Comments