Exercise 1: Adding business logic to your application At the conclusion of this exercise, you will be able to: - Enhance a Business Object with a new Property - Implement an Event Handler for a Business Object - Enhance a Tile with a new Controller Scenario: You want to show the total amount of orders for a customer on the Customer Detail Tile within the Tile Set Customer Orders. Prerequisites You have installed SAP CRM Mobile Sales 4.0 SP06, including the SAP Mobile Application Studio (MAS). You have installed the training repository (demo_arsdb40) for the SAP MAS 4.0 and created an ODBC source for it. You have reserved the namespace Y_ for this training repository. You have created BOL and UI projects for the training application (DEMBOL and DEM) and have generated the application runtime files from the training repository. Tasks To realize this scenario you have to carry out the following steps: 1) Add a new property to the customer Business Object. This property is used to store the total amount of orders for a customer. 2) Implement the functionality to evaluate the total amount of orders and store the value in the new property defined in 1). 3) Add a new controller to the customer detail Tile to show the total amount of orders. This new controller has to be bound to the new property defined in 1) in order to show the correct data. The result should look like this:
Before After Hints - The customer Business Object is CBusinessPartner. - The customer detail Tile where the new information shall be shown is bpdetail. - The new BO property has to be of a numeric data type and doesn t need to be bound to a segment field of a BDoc. - To evaluate the total amount of orders for a customer you can use an already existing relationship modelled for the customer Business Object. - The new BO property has to be updated whenever a new customer object is loaded. Begin the exercise now.
Exercise 1 - Solution 1. Start the SAP Mobile Application Studio and create a new change list for your enhancements/modifcations To start the SAP Mobile Application Studio, choose Start Programs SAP CRM Mobile SAP Mobile Application Studio. To log on, make the following entries: - DSN: demo_arsdb40 - Login: ARSAdmin - Password: (no password) Create a new change list called Y_Training. 2. Create a new property Y_TotalOrders for Business Object CBusinessPartner In the Object Browser (Hierarchy tab) navigate to Business Library Business Objects CBusinessPartner Properties. Right-click on the Properties-folder and choose New. Enter the necessary attributes (see the following screenshot for details): Save the new property Y_TotalOrders. 3. Implement the Event Handler Loaded for Business Object CBusinessPartner In the Object Browser (Hierarchy tab) navigate to Business Library Business Objects CBusinessPartner Event Handlers. Right-click on the Event Handlers-folder and choose New. Select the Event Loaded from the list of possible events. Enter Y_Loaded as name of the Event Handler. Enter the following line of code for the Event Handler: Y_TotalOrders = ThisBO.Orders.count Save the new Event Handler Y_Loaded.
4. Drag and drop the new property Y_TotalOrders onto the Tile bpdetail In the Object Browser (Hierarchy tab) navigate to Tiles Detail Tiles bpdetail. Right-click on Tile bpdetail and choose Edit. A popup window asks for the creation of a new branch, because you are modifying an SAP object. Enter Y_Training as branch name. (Remark: the branch name is independent of the change list name and doesn t necessarily need to be the same). In the Object Browser (Hierarchy tab) navigate to Business Library Business Objects CBusinessPartner Properties Y_TotalOrders. Drag and drop the property Y_TotalOrders onto the Tile bpdetail. Arrange the newly created controller Y_ctrlTotalOrders nicely with the other already existing controllers on the Tile. The properties of the new controller Y_ctrlTotalOrders should be set like follows: Save the modified Tile bpdetail.
5. Generate your changes Via the menu Build Generation Settings check the generation settings for your BOL and UI project. The settings should look like follows: Via the menu View Generation List, select all change list objects for generation (should be the default). Via the menu Build Generate, generate the new runtime files. 6. Start the application To start the application, run the MobileClient.exe in C:\Program Files\SAP\Mobile\bin\ and choose MSA (DEM). Login: crmuser Password: crm NOTE: the application could also be started by using any other password, because other than in the standard mobile applications, for this demo application there is no programmed event to verify the login data. Choose BusinessPartners Customer Orders and check if the new field Total orders is visible and containing the correct amount of orders for a corresponding customer. Remark: In the training database there are two customers (ADCOM COMPUTER and MEDIA STORE) with assigned orders.
Exercise 2: Raising messages depending on certain conditions At the conclusion of this exercise, you will be able to: - Create new Messages with and without parameters - Implement an UI Event Handler - Access the Business Object Layer from the User Interface Layer Scenario: In addition to the scenario in Exercise 1 you want to show a corresponding message to the user indicating if there are orders for the selected customer or not. Prerequisites You have installed SAP CRM Mobile Sales 4.0 SP06, including the SAP Mobile Application Studio (MAS). You have installed the training repository (demo_arsdb40) for the SAP MAS 4.0 and created an ODBC source for it. You have reserved the namespace Y_ for this training repository. You have created BOL and UI projects for the training application (DEMBOL and DEM) and have generated the application runtime files from the training repository. You have successfully completed Exercise 1. Tasks To realize this scenario you have to carry out the following steps: 1) Create two new messages for the two conditions you want to indicate to the user. i. The current customer has <n> orders assigned. You need to include two parameters to this message. One parameter which is filled with the total amount of orders for the current customer during runtime, and a second parameter which is filled with the customer name. ii. The current customer has no orders assigned. Here you don t need any parameters, because the message to be shown is the same for every customer with no orders assigned. 2) Implement the functionality to raise the respective message depending on the conditions described in 1). When the first condition holds true the message should be of type information. Otherwise (no orders for the customer) it should be of type warning. The result should look like this:
Before After
Hints - Parameters are included in message descriptions like that: <message text> %1% <message text> %2% <message text> - Use the Object Browser in the MS Visual Basic development environment to learn how the method RaiseMessage of the BusinessRootObject is designed and to be used. - Implement the appropriate <Anchor>OnUpdate Event Handler on the customer Tile to raise the messages depending on the respective condition. - To access the BusinessRootObject from the UI you can use the element gservices of class GlobalData. Begin the exercise now.
Exercise 2 - Solution 1. Start the SAP Mobile Application Studio and choose your change list which you have created in Exercise 1 To start the SAP Mobile Application Studio, choose Start Programs SAP CRM Mobile SAP Mobile Application Studio. To log on, make the following entries: - DSN: demo_arsdb40 - Login: ARSAdmin - Password: (no password) Choose the change list Y_Training from the drop down list on the change list selection screen. 2. Create two new messages for the two conditions: <n> orders / no orders assigned to a customer Look Up ID: Y_TotalOrder, Error Code: 1 and Look Up ID: Y_TotalOrder, Error Code: 2 Open the message editor via the menu Tools Message Editor. Right-click on the screen area and choose New from the context menu. In the opening message window enter the Look Up ID, Error Code, Source and Description. Save the new message. Repeat the last three steps for the second message. The result should look like follows:
3. Implement the Event Handler Y_CBusinessPartneronUpdate on Tile bpdetail In the Object Browser (Hierarchy tab) navigate to Tiles Detail Tiles bpdetail and double-click on the Tile to open it. In the Tile design window navigate to bpdetail Class Event Handlers. Right-click on the Event Handlers-folder and choose Add. Select <Anchor>CBusinessPartner from the upper left drop down box in the ScriptEditor window. Select onupdate from the upper right drop down box in the ScriptEditor window. Press the Begin Edit button in the tool bar to switch to the edit mode. Notice that in the lower right input field the name of the Event Handler Y_CBusinessPartneronUpdate is automatically created. Enter the source code for the Event Handler. One possible solution is: Dim params(1) If acbusinesspartner.bo.y_totalorders <> 0 Then params(0) = acbusinesspartner.bo.y_totalorders params(1) = acbusinesspartner.bo.mname1 gservices.bol.raisemessage "Y_TotalOrder", 1, EMS_INFO, params() Else gservices.bol.raisemessage "Y_TotalOrder", 2, EMS_WARNING End If Save the new Event Handler. 4. Generate your changes Cf. step 5 in Exercise 1. 5. Start the application Cf. step 6 in Exercise 1. In Tile Set BusinessPartners / Customer Orders skip through various customers to check if the correct messages are displayed. Remark: In the training database, e.g. the customer ADCOM COMPUTER has orders assigned. So it is advisable to search for customers with search term AD* in Tile Set BusinessPartners / Business Partner Search and skip through the resulting list of customers in Tile Set BusinessPartners / Customer Orders afterwards. OPTIONAL question: There is a little bug in the implementation on this scenario. What is it? How can it be solved?
Copyright 2004 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, 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, z/os, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, and Informix are trademarks or registered trademarks of IBM Corporation 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. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. SAP assumes no responsibility for errors or omissions in these materials.