117 Exercise 6: Organizing Database Updates
Solution 6: Organizing Database Updates
Task 1: Prepare and Test Program
If you have not finished the previous exercise dealing with locks, you can copy the template program and create a transaction to start your copy.
1. If necessary, copy the template program SAPMBC414_BOOK_LOCK_S with all constituents. Name the copy SAPMZBOOKINGS_UPDATE_##.
Create a transaction (name: ZBOOKINGS_UPDATE_## ) 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.
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_LOCK_S. Choose Copy... from the context menu.
b) On the following screen, enter the name of the program you want to create (SAPMZBOOKINGS_UPDATE_##). 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_UPDATE_## 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_UPDATE_##), 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).
Task 2: Implement Database Updates Using Asynchronous Updates (1)
Your program is to be changed so that the cancellation of existing bookings is performed using the asynchronous update technique.
1. The function modules UPDATE_SFLIGHT and UPDATE_SBOOK are used to update the table entries in the DB tables SLFIGHT and SBOOK.
Can these function modules also be used to perform the updates using the update technique?
Answer: Yes, both function modules can be used to perform the updates using the update technique. This is because the flag “update function module” is set on the Properties tab.
2. Modify your program so that the updates to the DB tables SFLIGHT and SBOOK are performed using the update technique:
Call the corresponding function modules capable of performing updates in the MODIFY_BOOKINGS subroutine.
Insert the statement COMMIT WORK in the PAI module USER_COMMAND_0200.
Be aware of the fact that the locks set using “_SCOPE = 2” are passed to the update program and therefore must not be explicitly released in the dialog program.
a) See model solution.
Task 3: Implement Database Updates Using Asynchronous Updates (2)
Your program is to be enhanced so that the creation of a new booking is performed using the asynchronous update technique.
The data for a new booking is entered on screen 300. Clicking the Save icon (function code SAVE) should insert the new booking in the SBOOK table and should modify the flight in question in the SFLIGHT table.
To generate a new entry in the DB table SBOOK, use the function module INSERT_SBOOK, which is capable of performing updates. To update the related flight, use the function module UPDATE_SFLIGHT.
1. Create a new subroutine (name: SAVE_NEW_BOOKING) in the include ending with F02. The form should have one parameter to interchange the structure SDYN_BOOK. In the form, this parameter will only be read.
Call the subroutine from the PAI module USER_COMMAND_0300 (directly behind the lock request for the new booking). Pass the structure SDYN_BOOK to the subroutine.
a) 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). The parameter should be passed using the addition USING.
2. Implement the source code of the subroutine:
- Create a local data object of type SBOOK.
- Fill the local data object with the information contained by the subroutine’s parameter.
- The local data object contains the customer number but not the customer name. Thus, read the customer name from the database table SCUSTOM and store it in the field PASSNAME of your structure.
- If the flight class was not entered by the user, set the corresponding field value in your structure to ’Y’.
- Finally insert the data of the new customer in DB table SBOOK and update DB table SFLIGHT.
a) See model solution.
3. Insert the statement COMMIT WORK in the PAI module USER_COMMAND_0300.
a) See model solution.
4. Check whether the statements to set or release locks (related to the creation of a new booking) have to be adapted. Implement the changes if necessary.
a) The new booking and the related flight are locked using _SCOPE = 2.
This means that the locks are transferred to the update program, which cares for the deletion of the locks. Thus, you cannot delete the locks from your program.
=> Delete the statement CALL FUNCTION 'DEQUEUE_ALL', which can be found directly behind the call of subroutine SAVE_NEW_BOOKING.
Result