Reading Sample
1.10 Creating your own data objects
Before we work on our own interface example, we must first create some objects at database and application level—in the target system.
Although learning about interface technologies sometimes seems like completing a marathon, it is worthwhile. The scenario for our custom objects is rather sporty as well: it is based on data for athletes. This data will be stored in a central system and will be accessible for external applications via RFC.
We will create the following objects as the foundation for the interfaces which we will create afterwards:
- Database table
- Authorization object, authorization, and role
- Message class
- Lock objects
- Number range
We will create a table with basic information about the athlete (ID, name, date of birth, country).
Custom package ZSPORTS
You can create your own package for all your objects so that you can transport the objects later. We will use package ZSPORTS with a leading Z for the customer namespace.
Therefore, we create database table ZATHLETE as part of the package ZSPORTS. Create the table, maintain a short text, and maintain the delivery class as A. Set the parameter Data Browser/Table View Maint. to Display/Maintenance allowed.
Then maintain the respective fields as shown in Figure 1.18.
Figure 1.18: New transparent table ZATHLETE
Create and reference your own data elements, as shown in Figure 1.18.
For the field COUNTRY, specify a foreign key: select the line, then select the icon Foreign Keys. Confirm the dialog box to create a proposal with values table T005. In the subsequent dialog box (see Figure 1.19), enter a short text and click Copy to close the dialog box and to transfer the foreign key.
Figure 1.19: Creating a foreign key for the field COUNTRY
Save the table. Choose Goto • Technical Settings to set Data Class to APPL0 and Size Category to 0. Choose Extras • Enhancement Categories to set enhancement categories to Can Be Enhanced (Deep). Finally, activate the table.
It is a good idea to enter information in the table so that our RFMs can provide data later. In the table maintenance function, choose Utilities • Table Contents • Create Entries and create several entries for the table.
Prerequisite for direct table maintenance
There are two prerequisites for allowing direct maintenance of table entries from transaction SE11. The first prerequisite is that we have already prepared the table-specific part on the Delivery and Maintenance tab in the Table View Maint. area, as described above. Secondly, the client settings must allow the maintenance, which is typically not the case for client 000. You can check the client-specific settings in transaction SCC4.
To restrict the access to our athletic results, we create an authorization object. Use the context menu on our package ZSPORTS and select Create • Other (1) • Authorization Object. Specify ZATHLETE in the Object field, enter a text in the Text field, and enter the value BC_A in the Class field (see the left part of Figure 1.20). Press Enter to enable the Authorization Fields table, enter the field ACTVT, and click the column Short Description so that the respective information for the existing field is provided. Save the object.
Figure 1.20: Creating an authorization object
You can now assign the permitted activities using the respective button Permitted Activities on the lower part of the screen. A dialog box Define Values opens. Allow the values 01 (Create), 02 (Change), 03 (Display), and 06 (Delete) (see the right part of Figure 1.20). Click Transfer to close the dialog box and close the new authorization object.
In the next step, we have to create an authorization for the authorization object and assign this authorization to our user. Start the Profile Generator (transaction PFCG), enter the role name ZATHLETE, and click Single Role to create the role. You have to maintain a short text and save the role before you can continue. Choose the Authorizations tab—this is displayed with a red icon because no profile is maintained and no authorization data exists (see Figure 1.21).
Figure 1.21: Role maintenance in transaction PFCG
On the Authorizations tab, click Change Authorization Data. The first dialog box lists information for first-time users, the second dialog box offers templates. Close the latter by clicking . Now the screen for maintaining role authorizations is displayed (see Figure 1.22).
Figure 1.22: Initial screen for role maintenance
Click , add the authorization object ZATHLETE in the dialog box, and close the dialog box. Now we have to maintain the activities, so open the complete hierarchy down to the line Activity as shown in Figure 1.23.
Figure 1.23: Manual maintenance of role authorization
By clicking the yellow icon (Empty Field), we can easily assign all activities—the yellow icons turn green. Save the role and accept the proposed name for the profile. Use the icon to generate the role and press F3 to navigate back to the role overview. The profile name is added and the Authorizations tab is now displayed with a green icon.
Choose the User tab to maintain your user ID in the User Assignments table (left part of Figure 1.24). Save the role, then click User Comparison and click Complete Comparison in the dialog box to have the authorization assigned to your user (right part of Figure 1.24).
Figure 1.24: User assignment to a role
The successful profile comparison is listed in the upper right-hand side of the dialog box (fields User, Date, and Time). Close the dialog box by clicking .
The User tab now appears with a green icon as well. The role assignment to your user prepares your user for the AUTHORITY-CHECK
statement that we will implement in the coding later. Save the role. Back in the Object Navigator, create a message class for the package ZSPORTS, using the context menu Create • Other (1) • Message Class. Enter the name ZSPORTS and enter the following messages:
000 & & & & 001 Error during processing: & 002 Missing authorization 003 Invalid data 004 No entry found 005 Object locked
Table 1.1: Messages for message class ZSPORTS
Objects for database changes
The following two objects (lock object and number range) will only be relevant later when we extend our data model to function modules writing data to the database.
We have to create a lock object to follow the principle of the ABAP lock mechanism. Therefore, use the context menu Create • Dictionary Object • Lock Object on package ZSPORTS and enter EZATHLETE in the Lock Object field in the dialog box. Press Enter to proceed to the maintenance of the lock object. Enter a short text and switch to the TABLES tab (see Figure 1.25).
Figure 1.25: Lock object maintenance
Specify table ZATHLETE as the primary table on the TABLES tab, specifying the value Write Lock for the Lock Mode field. Activate the object and choose Goto • Lock Modules to verify that the function modules ENQUEUE_ZATHLETE and DEQUEUE_ZATHLETE were created.
To enable continuous numbering of our athletes, we need an internal number range. Start transaction SNRO, enter ZATHLETE as the object name and click to create the number range object. Specify a short and long text for the object. Set the Number Length Domain field to CHAR10 and the Warning % field to 10.0 (see Figure 1.26). Save the object and confirm the warning in the dialog box with Yes.
Figure 1.26: Create number range object
Now click Number Ranges and then Change Intervals to display the list of intervals. Click the icon, and in the dialog box, enter a new interval 1 ranging from 0000000001 to 0000010000 (see Figure 1.27).
Figure 1.27: Inserting a new interval for a number range
Press Enter to close the dialog box, save the number range, and ignore the warning that appears.
The object list for our package now shows the ABAP objects, see Figure 1.28. The number range, the role, and the authorization are not listed here.
Figure 1.28: Object list of our own objects as preparation
All contents. Learn more. Discover now.
et.training - Your learning platform for SAP software
- Access to all learning content1
- Regular new releases
- Intelligent search algorithm
- Innovative reading experience
- Customized learning paths
- Certificates & QA tests2
1 You get access to all learning content. Online trainings, certificates are NOT part of the flat rate.
2 More information on request.