• No results found

77 Exercise 5: SAP Locking Concept

In document BC414_EN_Col92_FV_Inst_A4.pdf (Page 93-98)

Exercise Duration: 45 Minutes

Exercise Objectives

After completing this exercise, you will be able to:

• Call and use lock modules

• Locate the places in programs where locks must be set and released in order to ensure that the data to be changed is protected adequately against competing accesses

Business Example

Your program developed in the previous unit is to be changed to include locks.

These locks have to prevent the booking data and the flight data from being changed by other programs while they are edited by your program.

Program: SAPMZBOOKINGS_##

Transaction code: ZBOOKINGS_##

Copy template: SAPMBC414_BOOK_LUW_S Model solution: SAPMBC414_BOOK_LOCK_S

Task 1: Prepare and test program

If you have not finished the exercise for the previous unit dealing with LUWs, you can copy the template program and create a transaction to start your copy.

1. If necessary, copy the template program SAPMBC414_BOOK_LUW_S with all constituents. Name the copy SAPMZBOOKINGS_LOCK_##. Create a transaction (name: ZBOOKINGS_LOCK_## ) to start your program.

Save both 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: Set and remove SAP locks

Locks should be used to protect the database changes related to the cancellation of bookings and the creation of a new booking. The check of the user input in the fields of dynpro 100 should be performed without lock protection.

Analyze the source code of your program to find the appropriate code positions to set and release the locks.

To set the logical locks, call the lock modules created in the last exercise. If you have not finished the exercise, call the template lock modules related to the lock objects ESFLIGHT (DB table SFLIGHT), ESBOOK (DB table SBOOK), and ESFLIGHT_SBOOK (DB tables SFLIGHT and SBOOK), respectively.

Handle the exceptions of the lock modules. Possible messages are contained in the message class BC414:

- Data set is already being edited Þ message 060

- Editing terminated (booking already locked) Þ message 061 - Flight and/or bookings are already being edited Þ message 062 - Lock request not successful (sy-subrc = &1) Þ message 063

Hint: Implement the pessimistic lock pattern.

1. Protect the cancellation of existing bookings by calling the appropriate lock modules. Keep in mind that all locks set by a program are automatically removed if the program is ended.

2. Protect the creation of a new booking by calling the appropriate lock modules. Keep in mind that all locks set by a program are automatically removed if the program is ended.

Hint: Saving the data of the new customer will be implemented later using the update concept.

Solution 5: SAP Locking Concept

Task 1: Prepare and test program

If you have not finished the exercise for the previous unit dealing with LUWs, you can copy the template program and create a transaction to start your copy.

1. If necessary, copy the template program SAPMBC414_BOOK_LUW_S with all constituents. Name the copy SAPMZBOOKINGS_LOCK_##. Create a transaction (name: ZBOOKINGS_LOCK_## ) to start your program.

Save both 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 on program SAPMBC414_BOOK_LUW_S. Choose Copy... from the context menu.

b) On the following screen, enter the name of the program you want to create (SAPMZBOOKINGS_LOCK_##). 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. Accept 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_LOCK_## 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_LOCK_##), 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: Set and remove SAP locks

Locks should be used to protect the database changes related to the cancellation of bookings and the creation of a new booking. The check of the user input in the fields of dynpro 100 should be performed without lock protection.

Analyze the source code of your program to find the appropriate code positions to set and release the locks.

To set the logical locks, call the lock modules created in the last exercise. If you have not finished the exercise, call the template lock modules related to the lock objects ESFLIGHT (DB table SFLIGHT), ESBOOK (DB table SBOOK), and ESFLIGHT_SBOOK (DB tables SFLIGHT and SBOOK), respectively.

Handle the exceptions of the lock modules. Possible messages are contained in the message class BC414:

- Data set is already being edited Þ message 060

- Editing terminated (booking already locked) Þ message 061 - Flight and/or bookings are already being edited Þ message 062 - Lock request not successful (sy-subrc = &1) Þ message 063

Hint: Implement the pessimistic lock pattern.

1. Protect the cancellation of existing bookings by calling the appropriate lock modules. Keep in mind that all locks set by a program are automatically removed if the program is ended.

a) An exclusive lock (type “E”) for the selected flight has to be set in the module CHECK_FLIGHT just before the flight is checked.

b) An exclusive lock (type “E”) for all related bookings has to be set in the module USER_COMMAND_0100 (user command BOOKC).

c) All locks have to be removed after the cancellation of the bookings and the update of the flight has been finished. In addition, all locks have to be removed before the dynpro 100 is displayed to the user again.

d) User the Pattern functionality of the ABAP Workbench to create the call of a lock module.

e) See model solution.

2. Protect the creation of a new booking by calling the appropriate lock modules. Keep in mind that all locks set by a program are automatically removed if the program is ended.

Hint: Saving the data of the new customer will be implemented later using the update concept.

a) An exclusive lock (type “E”) for the selected flight has to be set in the module CHECK_FLIGHT just before the flight is checked.

b) An exclusive lock (type “E”) for the new booking has to be set in the module USER_COMMAND_0300 (user command SAVE) just before the booking is saved.

c) All locks have to be removed after the creation of the new booking and the update of the flight has been finished. In addition all locks have to be removed before the dynpro 100 is displayed to the user again.

d) User the Pattern functionality of the ABAP Workbench to create the call of a lock module.

e) See model solution.

Result

In document BC414_EN_Col92_FV_Inst_A4.pdf (Page 93-98)