Exercise Duration: 20 Minutes
Exercise Objectives
After completing this exercise, you will be able to:
• Change several data records, optimized with respect to performance, in database tables
Business Example
You want to make direct changes to several data records from your program.
Program: ZTRAVELAG_##
Copy template: SAPBC414_TRAVELAG_T Model solution: SAPBC414_TRAVELAG_SQL_S
Task 1: Prepare and test program
Copy the template program.
1. Copy the template program SAPBC414_TRAVELAG_T with all subobjects to ZTRAVELAG_##, where ## is your group number. As this is an executable program (type 1), a transaction code is not required.
2. The copied program generates a list (screen 100) that presents the data of the travel agencies maintained in the database table STRAVELAG. By selecting one or more lines and clicking the icon in the application toolbar, the user can change the data of the corresponding travel agencies on the subsequent screen (200). Analyze the program flow if the screen 200 (used to change multiple travel agencies) is displayed, some information is changed, and the SAVE icon is clicked.
Which function code is related to the SAVE icon? Which module processes this function code? Which internal table contains the data changed by the user?
Use the debugger to analyze the program flow. Start the debugger by entering /hin the command field of screen 100 before you start editing the data.
Task 2: Implement database changes
Extend the program to include the database dialog.
1. Create a subroutine (name: SAVE_CHANGES) that encapsulates the code to perform the database changes. The subroutine should have a parameter to interchange the internal table containing the modified data. Call the subroutine if the user clicks the SAVE icon on screen 200.
2. Implement the database changes:
In the subroutine, write the changed address data back to the STRAVELAG database table. When doing so, note the performance aspects. If the save is successful, the message S030 is to be sent; if not, use the message I048 to inform the user.
Solution 2: Changing Several Data Records
Task 1: Prepare and test program
Copy the template program.
1. Copy the template program SAPBC414_TRAVELAG_T with all subobjects to ZTRAVELAG_##, where ## is your group number. As this is an executable program (type 1), a transaction code is not required.
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 SAPBC414_TRAVELAG_T. Choose Copy... from the context menu.
b) On the following screen, enter the name of the program you want to create (ZTRAVELAG_##). 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 allows you to enter the names of the includes that will be created during the copy process. Enter the names according to the following convention: All includes should start with the name of your program (ZTRAVELAG_##). The last three characters of the include name should be copied from the template include (e.g. TOP).
Do not forget to select all includes that should be copied. Then click Copy.
e) When being asked for the package, enter ZBC414_##. Press Enter.
f) Finally, assign all new objects to the transport request created by your trainer. 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) To test the program, choose Execute → Direct Processing from the program’s context menu.
2. The copied program generates a list (screen 100) that presents the data of the travel agencies maintained in the database table STRAVELAG. By selecting one or more lines and clicking the icon in the application toolbar, the user can change the data of the corresponding travel agencies on the subsequent screen (200). Analyze the program flow if the screen 200 (used to change multiple travel agencies) is displayed, some information is changed, and the SAVE icon is clicked.
Which function code is related to the SAVE icon? Which module processes this function code? Which internal table contains the data changed by the user?
Use the debugger to analyze the program flow. Start the debugger by entering /hin the command field of screen 100 before you start editing the data.
Answer:
The function code SAVE is related to the SAVE icon.
The function code is processed in module USER_COMMAND_0200.
The internal table containing the changed data has the name GT_TRAVELAG_SEL. It is filled in the module TRANS_FROM_0200.
Task 2: Implement database changes
Extend the program to include the database dialog.
1. Create a subroutine (name: SAVE_CHANGES) that encapsulates the code to perform the database changes. The subroutine should have a parameter to interchange the internal table containing the modified data. Call the subroutine if the user clicks the SAVE icon on screen 200.
a) Create the subroutine via forward navigation:
In module USER_COMMAND_0200, locate the cursor in the section processed for the function code SAVE. Enter the statement to call the subroutine. The internal table containing the modified data (GT_TRAVELAG_SEL) should be passed to the subroutine via the addition USING.
b) Double-click on the subroutine’s name. Define the subroutine in the include containing all the other forms (ZTRAVELAG_##F01).
c) Do not forget to rename and type the interface parameter of the subroutine. The name should start with PT_ (parameter is internal table).
2. Implement the database changes:
In the subroutine, write the changed address data back to the STRAVELAG database table. When doing so, note the performance aspects. If the save is successful, the message S030 is to be sent; if not, use the message I048 to inform the user.
a) See the model solution below.
Result