163 Exercise 7: Number Assignment
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.
- 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.
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
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).
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_##).
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”.
2. 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.
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”.
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.
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”.
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.
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) 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).
2. 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) See model solution.
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.
a) See model solution.
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.
* Get next free number in the number range '01'
* of number object 'SBOOKID'
PERFORM get_number USING sdyn_book-carrid