Вы находитесь на странице: 1из 11

SDN DAY MHO TRACK ABAP Essentials

Exercises / Solutions Rich Heilman / SAP Labs

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.

= i_partner_guid = = = = = = es_bp et_bp_addr et_bp_email et_bp_phone et_bp_role et_bp_web ).

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.

= i_partner_id = = = = = = es_bp et_bp_addr et_bp_email et_bp_phone et_bp_role et_bp_web ).

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

Copyright 2007 SAP AG. All Rights Reserved


No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, System i, System i5, System p, System p5, System x, System z, System z9, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, POWER5+, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. The information in this document is proprietary to SAP. No part of this document may be reproduced, copied, or transmitted in any form or for any purpose without the express prior written permission of SAP AG. This document is a preliminary version and not subject to your license agreement or any other agreement with SAP. This document contains only intended strategies, developments, and functionalities of the SAP product and is not intended to be binding upon SAP to any particular course of business, product strategy, and/or development. Please note that this document is subject to change and may be changed by SAP at any time without notice. SAP assumes no responsibility for errors or omissions in this document. SAP does not warrant the accuracy or scompleteness of the information, text, graphics, links, or other items contained within this material. This document is provided without a warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall have no liability for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. This limitation shall not apply in cases of intent or gross negligence. The statutory liability for personal injury and defective products is not affected. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third-party Web pages nor provide any warranty whatsoever relating to third-party Web pages.

SAP assumes no responsibility for errors or omissions in these materials

Вам также может понравиться