Академический Документы
Профессиональный Документы
Культура Документы
Exercise 1
Persistent Objects and Service Objects Part 1 In part 1 of the exercise, you will generate the persistent object against table SDEMO_BP. You will then test the generation, by running a simple Web Dynpro application. From SE80, select Local Objects from the listbox and press Enter. Right-click on the $TMP Package and choose, Create -> Class Library -> Class.
In the Create Class dialog, enter the class name as ZCL_MHO_XX_PERS_BP where the XX is your assigned number, enter a description, and mark the radiobutton for Persistent Class. Finally, click the Save button. In the next dialog, select Local Object.
In the next screen, you should see the inherited methods of the IF_OS_STATE interface. Click the Persistence button on the application toolbar.
In the following popup dialog box, enter the name of the table for which the persistent object should be generated. In this case, enter SDEMO_BP.
At the bottom of your screen, you should now see the SDEMO_BP table, as well as its fields. Double-click on the first field, PARTNER_GUID. Notice that double-clicking on the first field, populated data in section just above it.
Click the icon to move this field to the upper part of the screen. Actually what you are doing here is simply adding this field as an attribute of the persistent object class, in which SET and GET methods will be generated in order for you to manipulate this field. Continue clicking the same icon until all fields from the table have been added to the class. When all fields have been added, your screen should look like this.
Now click the Save button, and then the Back button. Examine the class attributes and methods that have been generated. You know should have attributes in the class which correspond to all of the fields that you have added from the SDEMO_BP table. Also, review the SET and GET methods that have been generated.
Next, save the class and activate. A few generated objects will be compiled and activated at the same time. You will then get a dialog asking if you want to activate the Actor class, choose Yes.
You should see 3 classes in the object navigator tree on the left. Of course, you will see your persistent object class that you just created, but you will also see the Actor(or Agent) and Base classes which were generated by the framework.
Finally, you may test your newly created persistent object by simply running transaction ZMHO_POT. This Web Dynpro application works off of your user id, so it is important that you have been using your group number when logging on to the system, as well as when naming your persistent object class. You output should look like this. Notice that your persistent class is being used to retrieve the data.
Persistent Objects and Service Objects Part 2 In this part of the exercise, you will complete a service class which uses persistent objects at a lower level, and test this service class using another Web Dynpro application. Start by copying the class ZCL_MHO_XX_WD_SERVICE. Go to SE80, locate the ZCL_MHO_XX_WD_SERVICE class in package ZMHO and right-click on it, select copy, in the dialog replace XX with your group number. Hit enter, if you get a dialog asking for a package, select local object.
In change mode, go to the properites tab, and change the inheritance so that CL_WD_COMPONENT_ASSISTANCE is the super class or your class. Click the Superclass button, then enter CL_WD_COMPONENT_ASSISTANCE in the input box underneath. Doing this will allow this class to be used as an assistance class in the Web Dynpro framework.
Go to the attributes tab and add a new private global attribute called GR_SERVICE_BP, type reference to CL_NWDEMO_SERVICE_BP. CL_NWDEMO_SERVICE_BP is an encapsulation of the persistent objects similar to what you just created in the first part of this exercise.
Go to the methods tab, double click on the CONSTRUCTOR method, call the constructor of the super class, and also create the gr_service_bp object which you defined in the last step. Your coding should resemble the following.
METHOD constructor. super->constructor( ). * Create CREATE CREATE CREATE instances of service classes OBJECT gr_service_so. OBJECT gr_service_pd. OBJECT gr_service_bp.
ENDMETHOD.
Go back to the methods tab, double click on the method READ_BP_DETAILS, and add the following code to its implementation. The following method uses all of the persistent objects built against all of the business partner tables and returns them to your newly created method. Note: Here is a chance to use the code completion feature delivered with NetWeaver 7.1. First, type the object name(with the -> identifier) gr_service_bp-> and wait, a dialog will appear with a list of methods from which you can choose the read_bp method. Hold down shift, and double click the method name in the dialog, it will then write the method signature for you. You can then uncomment the required parameters.
METHOD read_bp_details. gr_service_bp->read_bp( EXPORTING i_partner_guid IMPORTING es_bp et_bp_addr et_bp_email et_bp_phone et_bp_role et_bp_web ENDMETHOD.
Go back to the methods tab, double click on the method READ_BP_DETAILS_BY_ID, and add the following code to its implementation. This method is very similar in that it will retrieve the same data, but in this case, based off of the partner GUID and not the partner ID. Once again, try using the code completion method. METHOD read_bp_details_by_id. gr_service_bp->read_bp( EXPORTING i_partner_id IMPORTING es_bp et_bp_addr et_bp_email et_bp_phone et_bp_role et_bp_web ENDMETHOD.
10
Save and activate your service class. This class can now be used as an assistance class within the Web Dynpro framework. This will be covered in the next session on Web Dynpro. For now, you can test your service object class by running transaction ZMHO_SOT. Notice that your Service Class is being used to retrieve the data.
11