Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
How to part 2 build an agentry based app from scratch
1. SAP How-to Guide
SAP Mobility
SAP Mobile Platform (SMP)
How To Build an Agentry Based App from Scratch
Connecting to a SAP ERP Back-end - Part 2
provided by SAP Mobile - Rapid Innovation Group
Applicable Releases:
SAP Mobile Platform 2.3
Agentry 6.X
Version 1.0
June 2013
4. Typographic Conventions
Icons
Type Style
Description
Icon
Example Text
Words or characters quoted
from the screen. These
include field names, screen
titles, pushbuttons labels,
menu names, menu paths,
and menu options.
Cross-references to other
documentation
Example text
Emphasized words or
phrases in body text, graphic
titles, and table titles
Example text
File and directory names and
their paths, messages,
names of variables and
parameters, source text, and
names of installation,
upgrade and database tools.
Example text
User entry texts. These are
words or characters that you
enter in the system exactly
as they appear in the
documentation.
<Example text>
Variable user entry. Angle
brackets indicate that you
replace these words and
characters with appropriate
entries to make entries in the
system.
EXAMPLE TEXT
Keys on the keyboard, for
example, F2 or ENTER.
Description
Caution
Note or Important
Example
Recommendation or Tip
5. Table of Contents
1.
Business Scenario .................................................................................................................1
2.
Background Information .......................................................................................................1
3.
Prerequisites ..........................................................................................................................1
4.
Step-by-Step Procedure ...................................................................................................... 3
4.1
Adding Transactions to your Agentry Project ............................................................... 4
4.1.1
Create Class Handler and BAPI Wrapper in the SAP ERP Back-end............. 4
4.1.2
Create MDO Object and BAPI Wrappers in the Configuration Panel ............ 9
4.1.3
Create required Java Classes in the Agentry Editor.......................................13
4.1.4
Create Agentry Definitions for the Transactions ........................................... 32
4.1.5
Create Steps and Screens for the AddBooking Transaction ....................... 53
4.1.6
Create the Agentry definition to fetch the bookings ..................................... 69
4.1.7
Define Mobile Application Parameters for the Transaction and Fetch ....... 84
4.1.8
Test Application in ATE .................................................................................... 88
4.2
Data Tables ..................................................................................................................... 94
4.3
Complex Tables ............................................................................................................ 106
4.3.1
4.3.2
Create Agentry Editor Definitions .................................................................. 116
4.3.4
Enter Mobile Application Parameter ............................................................. 127
4.3.5
5.
Create MDO Object in Configuration Panel ................................................... 110
4.3.3
4.4
Create the Back-end Business Logic for the Complex Table ..................... 106
Test the Mobile Application in ATE ............................................................... 129
Deployment of the Mobile Application on SAP Mobile Platform 2.3 ....................... 131
Appendix ........................................................................................................................... 140
5.1
Appendix A – Source Code for Z00_CREATE_FLIGHT_BOOKING......................... 140
5.2
Appendix B – Source code for Z00_BAPI_CRT_FLIGHT_BOOKING ...................... 145
5.3
Appendix C – Source code for Z00_BAPI_GET_FLIGHT_BOOKING ...................... 146
5.4
Appendix D – Source code for Z00_GET_AIRPORT_DATA_TABLE ....................... 147
5.5
Appendix E – Source code for Z00_GET_CARRIER_COMPLEX_TAB.................... 149
5.6
Appendix F – Source code for Z00_BAPI_GET_CARRIER_CT ................................ 153
6. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
1.
Business Scenario
This How-to guide will show you step by step how to add transations, data tables and complex
tables into a very simple mobile app based on Agentry, which was previously created by following
the How-to Build an Agentry based app from scratch connecting to an ERP SAP back-end Part 1.
2.
Background Information
The Agentry technology also allows building custom mobile apps and this How-to guide is meant to
show how you can start the scratch with building a metadata driven app using the Agentry
technology and connecting to an SAP back-end.
The example we are providing here is aiming at building a simple mobile app that fetches data from
an SAP ERP back-end and displays that data on the mobile device. At the end of this guide, you will
be able to see data from the back-end in your mobile app simulation in the Agentry Test
Environment tool.
For that purpose, in order to extend the previously built mobile app (see Business Scenario) this
guide will take you through creating of transactions in your Agentry project to allow you to insert
data into the SAP ERP back-end as well as the creation of data tables, complex tables and finally,
the deployment of the mobile app on the SAP Mobile Platform 2.3
3.
Prerequisites
In order to be able to follow all the steps mentioned in this guide, you need to have the following in
place:
•
An installed and running SAP ERP system that you can connect to and for which you have a
developer key
•
Agentry SAP Framework Administration installed in the SAP ERP back-end you intend to use
in this exercise
•
Access to the installation file for Agentry Server 6.0.31 or higher, either as a standalone or as
part of the SAP Mobile Platform 2.3*
*If you have the SAP Mobile Platform 2.3, in order to be able to develop a new Agentry based
app, you will need the SAP Mobile SDK as well, which will include the Agentry Development
Server, the Agentry Editor plugin, the Agentry Test Environment
•
Access to the installation file for Agentry Server Administrator 6.0.31 or higher
•
Access to the installation file for Agentry Editor Plugin (either individually downloaded from
the SAP Service Marketplace or as a part of the SAP Mobile SDK 2.3)
•
Installed Eclipse Indigo 3.7.2 on the machine where you intend to do this exercise
•
Installed Java Runtime 1.6 or higher on the machine you will be using for this exercise
•
Valid license keys
•
Administration rights on the machine you’re working on
•
Administration rights for the SAP Control Center (for the deployment of the mobile app on
SAP Mobile Platform 2.3)
•
Successful completion of the exercises described in previous guide: How-to Build an
Agentry based app from scratch connecting to an ERP SAP back-end Part 1
October 2013
1
7. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
You can install the Agentry Server, the Agentry Editor and the Agentry Test Environment
components on the same machine.
A previous understanding of the Agentry technology is a must for this How-to Guide.
ABAP and Java understanding is recommended.
October 2013
2
8. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4.
Step-by-Step Procedure
We assume that at this point you have built a very simple mobile app that fetches the flight
schedule (or other example data of your choice from your SAP ERP back-end system) and displays
it on the mobile device/ Agentry Test Environment.
Next we will insert new screens and transactions that will allow you to choose a schedule and create
a flight booking that will be updated then in the SAP ERP back-end, adding more complexity to your
app. The booking information captured in the device is sent to the back-end, on the next transmit,
with the local Booking IDs and a unique booking ID gets generated by the backend. We will create a
rule for the generation of unique IDs, consistent with the data in the back-end, for the cases where
data is created on the mobile device locally. Then as a part of the exercise, in addition to the
transaction, we will create a new fetch definition to retrieve all the bookings created by the current
user and display it in a screen. In the example SAP ERP backend we have used for the purpose of
this guide, the Flight Booking information is stored in a table called SBOOK.
We will start by creating the backend business logic required to create a booking in the SAP
System. You can find the source code for the needed ABAP Class and a BAPI Wrapper Class in the
Appendix section of this document. In addition, we will then create the MDO object and BAPI
Wrapper configurations to link the back-end ABAP classes and the BAPI Wrapper function module
created in the ABAP system.
In the Agentry Editor, we will create the POJO, steplet, stephandler and BAPI Java classes for the
creation of the booking as well as the fetch of the bookings created by the user. We will then create
transaction definitions and their properties in the Agentry Editor as well as the required UI
elements.
In addition, for exemplification purposes, we will create data tables and complex tables as well,
which can be then tested in the Agentry Test Environment only. Please note, that the data table and
complex tables are not included in the functional mobile app, which is why they are only visible in
the test environment tool.
Finally, we will deploy the mobile app on SAP Mobile Platform 2.3
October 2013
3
9. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4.1 Adding Transactions to your Agentry Project
...
Exer cise 1 - Agent ry S erv er Ins tall ation
4.1.1 Create Class Handler and BAPI Wrapper in the SAP ERP Back-end
1.
Let us begin by creating the back-end business logic first. We will first create the Class
handler, then the BAPI Wrapper, one of each for creating a flight booking and retrieving the
bookings for the logged user.
2. Launch Transaction SE24 from SAP GUI
Enter: Object type: Z00_CREATE_FLIGHT_BOOKING
(
If you haven’t created the Z00 template class, you can do so by using the source code
provided in the Appendix section A of this document)
3. Click on
to copy the Class to be used by your application
Enter:
Copy to: ZXX_CREATE_FLIGHT_BOOKING (XX being your unique number)
4. Click on
button
If you are prompted with Create Object Directory Entry, input Z##_FLIGHTBOOKING as
Package. Click OK at next screen
5.
You will come to the next window, as shown below
October 2013
4
10. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
6. Click on the
7. Click on the
button
button
8. Click on the
button
9. Launch Transaction /nse37 to launch the Function Builder
10. Enter Function Module name
Function Module: Z00_BAPI_CRT_FLIGHT_BOOKING
(
If you haven’t created the Z00 template class, you can do so by using the source code
provided in the Appendix section B of this document)
October 2013
5
11. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
11. Click on
button
Enter the following details:
To Function module: Z00_BAPI_CRT_FLIGHT_BOOKING
Function group: ZXX_FLIGHTBOOKING_FGRP
(where XX is your unique number)
12. Click on
button and the OK on the next screen
13. Enter Function Module: ZXX_BAPI_CRT_FLIGHT_BOOKING (where XX is your unique
number)
14. Click on
button
Change the highlighted section of the source code to:
October 2013
6
12. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
ZXX_BAPI_CRT_FLIGHT_BOOKING (XX being your unique number)
15. Click on the
button
We have just created the BAPI Wrapper for Create Flight Booking. Click OK on the next
screen.
Next we will create one for retrieving the Bookings for the user.
16. Click on the
button
Enter:
Function Module: Z00_BAPI_GET_FLIGHT_BOOKING
(
If you haven’t created the Z00 template class, you can do so by using the source code
provided in the Appendix section C of this document)
October 2013
7
13. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
17. Click on the
button. Enter the following details
To Function module: ZXX_BAPI_GET_FLIGHT_BOOKING (XX is your unique number)
Function group: ZXX_FLIGHTBOOKING_FGRP
18. The Function Module is copied successfully,
Enter:
Function Module: ZXX_BAPI_GET_FLIGHT_BOOKING (XX is your unique number)
19. Click on
20. Click on the
button
button and click OK on the next screen.
We have created now the Class Handler and the BAPI Wrappers.
October 2013
8
14. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4.1.2 Create MDO Object and BAPI Wrappers in the Configuration Panel
21. Next we will create MDO Object and BAPI Wrappers in the Configuration Panel. Launch
Transaction /n/syclo/configpanel in the SAP ERP back-end
22. Click on the
link
23. Click on the
button
Enter:
Mobile Data Object Id: ZXX_CREATE_FLIGHT_BOOKING (XX is your Unique number)
Description: XX Create Flight Booking
Data Object Type: Standard Data Object
Mobile Application: XX Flight Booking App (XX is your Unique number)
Data Object Handler: Z00_CREATE_FLIGHT_BOOKING: Flight MDO Class Handler
Get Method: GET
Create Method: CREATE
Data Object Active: Checked
October 2013
9
15. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
24. Click on the
25. Click on
26. Click on the
button
to choose the Transport Request
link
27. Click on
link
28. Select the Mobile Application Filter to display your application configuration
29. Click on the
30. Click on the
October 2013
button
button next to the BAPI Wrapper Name field
10
16. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
Enter:
Function Module: ZXX_BAPI_CRT_FLIGHT_BOOKING
31. Click on
button
32. Choose the BAPI Wrapper and click on the
button
33. Click on the Assignment tab
Enter:
Mobile Application: XX Flight Booking App (XX being your unique Number)
Mobile Data Object id: XX Create Flight Booking (Your MDO Object which you created)
Method Type: Create method
Active Flag: Checked
34. Click on the
button
35. Click on the
button to choose your transport request
36. We will create another BAPI Wrapper to fetch the Bookings made by the user
37. Click on the
October 2013
button
11
17. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
38. Click on the
button next to the BAPI Wrapper Name field
Enter:
Function Module: ZXX_BAPI_GET_FLIGHT_BOOKING
39. Click on
button
40. Choose the BAPI Wrapper and click on the
button
41. Click on the Assignment tab
Enter:
Mobile Application: XX Flight Booking App (XX being your unique Number)
Mobile Data Object id: XX Create Flight Booking (Your MDO Object which you created)
Method Type: Get method
Active Flag: Checked
October 2013
12
18. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
42. Click on the
43. Click on the
button
button to choose your transport request
4.1.3 Create required Java Classes in the Agentry Editor
1.
Launch Agentry Editor and switch to Java Perspective
2. Right-click on the package com.syclo.sap.sflight.customer.steplet > New > Class
October 2013
13
19. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
3. Enter the name of the Java file
Name: FlightBookingSteplet
October 2013
14
20. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4. Click on
button
5. Replace the source with the one provided here:
package com.syclo.sap.sflight.customer.steplet;
import com.syclo.agentry.AgentryException;
import com.syclo.agentry.BusinessLogicException;
import com.syclo.agentry.TransactionSession;
import com.syclo.sap.Steplet;
import com.syclo.sap.sflight.customer.stephandler.FlightBookingStephandler;
public class FlightBookingSteplet extends Steplet{
public FlightBookingSteplet(TransactionSession session)
throws AgentryException, BusinessLogicException {
super(session);
}
@Override
public boolean execute() throws AgentryException {
try{
FlightBookingStephandler handler = new
FlightBookingStephandler((com.syclo.sap.User)_user);
handler.createBooking();
return true;
}
catch(Throwable exception){
throwExceptionToClient(exception);
return false;
}
}
}
6. Click on the
button
7. Right-click on the package com.syclo.sap.sflight.customer.stephandler > New > Class
October 2013
15
21. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
8. Enter the name of the Java file
Name: FlightBookingStephandler
9. Click on
button
10. Replace the source with the one provided here:
package com.syclo.sap.sflight.customer.stephandler;
October 2013
16
22. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
import java.util.GregorianCalendar;
import com.syclo.sap.StepHandler;
import com.syclo.sap.User;
import com.syclo.sap.sflight.customer.bapi.FlightBookingBapi;
import com.syclo.sap.sflight.customer.object.FlightBooking;
public class FlightBookingStephandler extends StepHandler{
com.syclo.sap.User user = null;
public FlightBookingStephandler(User usr) {
super(usr);
user = (com.syclo.sap.User)usr;
// TODO Auto-generated constructor stub
}
public void createBooking() throws Exception{
FlightBooking[] array = null;
FlightBooking sbookObj = new FlightBooking();
FlightBookingBapi bapi = new FlightBookingBapi(user, new GregorianCalendar());
bapi.run(sbookObj);
bapi.processResults();
/*ArrayList<SAPObject> sbookList = bapi.processResults();
array = new MyFlightBooking[sbookList.size()];
array = sbookList.toArray(array);
return array;*/
}
}
11. Click on the
button
12. Right-click on the package com.syclo.sap.sflight.customer.bapi > New > Class
October 2013
17
23. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
13. Enter the name of the Java file
Name: FlightBookingBapi
14. Click on
button
15. Replace the source file with the one provided here:
package com.syclo.sap.sflight.customer.bapi;
import java.util.ArrayList;
import java.util.GregorianCalendar;
October 2013
18
24. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
import com.sap.mw.jco.JCO;
import com.syclo.sap.Logger;
import com.syclo.sap.SAPObject;
import com.syclo.sap.User;
import com.syclo.sap.bapi.AbstractFetchBAPI;
import com.syclo.sap.sflight.customer.object.FlightSchedule;
public class FlightBookingBapi extends AbstractFetchBAPI{
public User user = null;
public FlightBookingBapi(User u, GregorianCalendar lu) throws Exception {
super(u, lu);
user = (User) u;
// TODO Auto-generated constructor stub
}
@Override
public ArrayList<? extends SAPObject> processResults() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void setParameters(SAPObject obj) throws Exception {
super.setParameters(obj);
try {
Logger log = new Logger(_user, "FetchBAPI_Java_Class");
//Pass Transaction Vales to BAPI_WRAPPER
JCO.Structure jcoStructure = _imports.getStructure("IS_SBOOK");
String carrierID = user.getString("transaction.CarrierID");
setValue(jcoStructure, log, "CARRID", carrierID);
String connectionID = user.getString("transaction.ConnectionID");
setValue(jcoStructure, log, "CONNID", connectionID);
String flightDate = user.getString("transaction.FlightDate");
setValue(jcoStructure, log, "FLDATE", flightDate);
String passName = user.getString("transaction.PassName");
setValue(jcoStructure, log, "PASSNAME", passName);
} catch (Exception e) {
user.rethrowException(e, true);
October 2013
19
25. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
}
}
}
16. Click on the
button
17. Right-click on the package com.syclo.sap.sflight.customer.object > New > Class
18. Enter the name of the Java file
Name: FlightBooking
October 2013
20
26. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
19. Click on
button
20. Replace the source code with the one provided here:
package com.syclo.sap.sflight.customer.object;
import com.sap.mw.jco.JCO.Table;
import com.syclo.sap.User;
import com.syclo.sap.SAPObject;
import com.syclo.sap.bapi.BAPI;
public class FlightBooking extends SAPObject {
public String CarrierID;
public String ConnectionID;
public String FlightDate;
public String BookingID;
public String Order_Date;
public String PassName;
public String Booking_User;
public String Reserved;
public String Cancelled;
October 2013
21
27. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
public String ClassType;
public String getClassType() {
return ClassType;
}
public void setClassType(String class1) {
ClassType = class1;
}
public String getCancelled() {
return Cancelled;
}
public void setCancelled(String cancelled) {
Cancelled = cancelled;
}
public String getReserved() {
return Reserved;
}
public void setReserved(String reserved) {
Reserved = reserved;
}
public FlightBooking(Table arg0) throws Exception{
setCarrierID(arg0.getString("CARRID"));
setConnectionID(arg0.getString("CONNID"));
setFlightDate(arg0.getString("FLDATE"));
setBookingID(arg0.getString("BOOKID"));
setOrder_Date(arg0.getString("ORDER_DATE"));
setPassName(arg0.getString("PASSNAME"));
setBooking_User(arg0.getString("BOOKING_USER"));
setReserved(arg0.getString("RESERVED"));
setCancelled(arg0.getString("CANCELLED"));
setClassType(arg0.getString("CLASS"));
}
public FlightBooking() {
CarrierID = "";
ConnectionID = "";
FlightDate = "";
BookingID = "";
Order_Date = "";
PassName = "";
Booking_User = "";
Reserved = "";
October 2013
22
28. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
Cancelled = "";
ClassType = "";
}
public String getFlightDate() {
return FlightDate;
}
public void setFlightDate(String flightDate) {
FlightDate = flightDate;
}
public String getBookingID() {
return BookingID;
}
public void setBookingID(String bookingID) {
BookingID = bookingID;
}
public String getOrder_Date() {
return Order_Date;
}
public void setOrder_Date(String order_Date) {
Order_Date = order_Date;
}
public String getPassName() {
return PassName;
}
public void setPassName(String passName) {
PassName = passName;
}
public String getBooking_User() {
return Booking_User;
}
public void setBooking_User(String booking_User) {
Booking_User = booking_User;
}
@Override
public String getID() {
return getBookingID();
}
October 2013
23
29. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
public String getCarrierID() {
return CarrierID;
}
public void setCarrierID(String carrierID) {
CarrierID = carrierID;
}
public String getConnectionID() {
return ConnectionID;
}
public void setConnectionID(String connectionID) {
ConnectionID = connectionID;
}
@Override
public void setNotes(Table arg0) throws Exception {
}
@Override
public void setProperties(Table arg0) throws Exception {
// TODO Auto-generated method stub
}
}
21. Click on the
button
22. Next, we will create the Java source files for the Fetch, in order to retrieve the bookings
created by the logged user
23. Right-click on the package com.syclo.sap.sflight.customer.steplet > New > Class
October 2013
24
30. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
24. Enter the name of the Java file
Name: FlightBookingGetSteplet
October 2013
25
31. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
25. Click on
button
26. Replace the source code with the one provided here:
package com.syclo.sap.sflight.customer.steplet;
import com.syclo.agentry.AgentryException;
import com.syclo.agentry.BusinessLogicException;
import com.syclo.agentry.FetchSession;
import com.syclo.sap.Steplet;
import com.syclo.sap.sflight.customer.object.FlightBooking;
import com.syclo.sap.sflight.customer.stephandler.FlightBookingGetStephandler;
public class FlightBookingGetSteplet extends Steplet{
public FlightBooking[] _returnData;
public FlightBookingGetSteplet(FetchSession session)
throws AgentryException, BusinessLogicException {
super(session);
}
October 2013
26
32. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
@Override
public boolean execute() throws AgentryException {
try{
FlightBookingGetStephandler handler = new
FlightBookingGetStephandler((com.syclo.sap.User)_user);
_returnData = handler.getMyBookings();
return true;
}
catch(Throwable exception){
throwExceptionToClient(exception);
return false;
}
}
}
27. Click on the
button
28. Right-click on the package com.syclo.sap.sflight.customer.stephandler > New > Class
29. Enter the name of the Java file
Name: FlightBookingGetStephandler
October 2013
27
33. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
30. Click on
button
31. Replace the source code with the one provided here:
package com.syclo.sap.sflight.customer.stephandler;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import com.syclo.sap.SAPObject;
import com.syclo.sap.StepHandler;
import com.syclo.sap.User;
import com.syclo.sap.sflight.customer.bapi.FlightBookingGetBapi;
import com.syclo.sap.sflight.customer.object.FlightBooking;
public class FlightBookingGetStephandler extends StepHandler{
com.syclo.sap.User user = null;
public FlightBookingGetStephandler(User usr) {
super(usr);
October 2013
28
34. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
user = (com.syclo.sap.User)usr;
// TODO Auto-generated constructor stub
}
public FlightBooking [] getMyBookings() throws Exception{
FlightBooking[] array = null;
FlightBooking spfliObj = new FlightBooking();
FlightBookingGetBapi bapi = new FlightBookingGetBapi(user, new
GregorianCalendar());
bapi.run(spfliObj);
ArrayList<SAPObject> spfliList = bapi.processResults();
array = new FlightBooking[spfliList.size()];
array = spfliList.toArray(array);
return array;
}
}
32. Click on the
button
33. Right-click on the package com.syclo.sap.sflight.customer.bapi > New > Class
34. Enter the name of the Java file
Name: FlightBookingGetBapi
October 2013
29
35. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
35. Click on
button
36. Replace the source code with the one provided here:
package com.syclo.sap.sflight.customer.bapi;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import com.sap.mw.jco.JCO;
import com.syclo.sap.SAPObject;
import com.syclo.sap.User;
import com.syclo.sap.bapi.AbstractFetchBAPI;
import com.syclo.sap.sflight.customer.object.FlightBooking;
public class FlightBookingGetBapi extends AbstractFetchBAPI{
public User user = null;
public FlightBookingGetBapi(User u, GregorianCalendar lu) throws Exception {
super(u, lu);
October 2013
30
36. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
user = (User) u;
// TODO Auto-generated constructor stub
}
@Override
public ArrayList<SAPObject> processResults() throws Exception {
ArrayList<SAPObject> spfliTab = new ArrayList<SAPObject>();
JCO.Table _sTab = _tables.getTable("ET_SBOOK");
int rows = _sTab.getNumRows();
for(int i = 0; i<rows; i++)
{
_sTab.setRow(i);
FlightBooking spfliLine = new FlightBooking(_sTab);
spfliTab.add(spfliLine);
}
return spfliTab;
// TODO Auto-generated method stub
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
@Override
public void setParameters(SAPObject obj) throws Exception {
// TODO Auto-generated method stub
super.setParameters(obj);
try {
Logger log = new Logger(_user, "FetchBAPI_Java_Class");
//City From
String cityFrom = user.getString("fetch.CityFrom");
JCO.Field jcocityFrom = _imports.getField("IS_CITY_FROM");
setValue(jcocityFrom, log, cityFrom);
October 2013
//City To
String cityTo = user.getString("fetch.CityTo");
JCO.Field jcocityto = _imports.getField("IS_CITY_TO");
setValue(jcocityto, log, cityTo);
//Date
String date = user.getString("fetch.Date");
JCO.Field jcodate = _imports.getField("IS_TRAVEL_DATE");
setValue(jcodate, log, user.eval("<<fetch.Date format="%d.%m.%Y">>"));
String cityFromLow = user.getString("fetch.CityFrom");
String cityFromHigh = user.getString("fetch.CityFrom");
setFilterRange("IT_CITY_FROM", "I", "EQ", cityFromLow, "");
31
37. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
//
//
//
//
//City To
String cityToLow = user.getString("fetch.CityTo");
String cityToHigh = user.getString("fetch.CityTo");
setFilterRange("IT_CITY_TO", "I", "EQ", cityToLow, "");
} catch (Exception e) {
user.rethrowException(e, true);
}
}
}
37. Click on the
button
38. We do not need to create the Object Class because we will use the same FlightBooking Java
Class
4.1.4 Create Agentry Definitions for the Transactions
1. In the Agentry Editor, switch to the Agentry perspective, if you haven’t already done so
2. We will now create a new Object called FlightBooking to store the Booking information
3. Locate the Class Constructor for FlightBooking.java,
Agentry Connector Studio > Object Wizard
October 2013
Right-click >
32
38. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4. Click on Object Wizard
October 2013
33
39. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
5. Click on the
October 2013
button
34
40. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
6. Click on the
October 2013
button
35
41. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
7. Change Key Property to – BookingID and click on
October 2013
button
36
42. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
8. Uncheck all the Transactions (Add, Edit, Delete) and click on the
October 2013
button
37
43. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
9. Uncheck the Get Step and click on the
button
10. You will notice that the new Object FlightBooking is created with all the properties
October 2013
38
44. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
11. Next we will create a Transaction
12. Click on Transactions in the Project Explorer
13. Click on the
button
14. Then select > to add an Object > “FlightBooking” Object
October 2013
39
45. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
15. In the next screen, accept the default selections
16. Click on
button
Update the below information on the Transaction Definitions
Name: AddBooking
Display Name: Add Booking
October 2013
40
46. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
17. Click on the
button
18. Next, we need to create a Rule to create an automatic BookingID for the new booking that
we create locally on the mobile device. The actual Booking ID is provided by the back-end
system, but we need to generate a local Booking ID to identify it uniquely on the mobile
device first. In the next steps, we will create a rule that will determine a unique ID on the
client.
19. Click on Properties
20. Double click on BookingID
October 2013
41
47. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
21. In the same screen, under Transaction Property Settings section
22. Change the Initial Value to “Rule - before data entry”
23. Click on the
button
24. Click on the
button next to Rule:
25. Choose Add New Rule
October 2013
42
48. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
26. Change the Name of the Rule to – “InitialBookingID”
27. Click on
button
For the next section: Please read carefully the following instructions, prior to commencing each
step.
October 2013
43
49. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
28. Within this screen, there are three main sections. On the left side are the different rule
terms; including function and data terms that may be added to the rule. In the center there
is the current rule function within the rule and one or more fields containing the parameters
to that function. On the right, you have the structure view. This view presents the rule logic
in a tree control representing its structure.
29. To define the InitialBookingID rule logic, select the field in the center portion of the screen
labeled Rule Entry Point. This term will be the root term of the rule logic and its return value
will be the one returned by the rule to the rule’s caller.
30. In the list of items on the left, select the function tab
. By default, this will display all the
rule functions available to the rule definition. Above this list, you have a drop down control
from which a function category can be selected. This will filter the list of rule functions to
only those within that category. Change this selection now to the String category.
31. In the list of functions now displayed, double-click the CONCATENATE function. The Rule
Editor will now appear as follows:
October 2013
44
50. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
Note the center portion of the screen now lists the CONCATENATE function. Below you
have the short description for this function. Clicking the function name along the top of the
list will display the functions long description.
32. The field displayed for this function is the first parameter to the function and is labeled
String 1. Selecting the field will display the parameter’s short description, as shown in the
above example. This parameter description includes information on whether the parameter
is required or optional and the data type expected.
On the right side of the Rule Editor, note the addition of the CONCATENATE function call to
the Structure View.
33. The first parameter to the CONCATENATE function is the constant value LOCAL_. This
value can be typed directly in the String 1 parameter field. Note that as you enter this text, a
second field, String 2, will be added to the parameter fields. Also, note that the structure
view now contains the LOCAL_ text as the first parameter to the CONCATENATE function:
October 2013
45
51. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
34. The second argument to the CONCATENATE function must be the total number of current
local FlightBooking objects plus one. To determine this value additional logic will be needed.
This will begin with a call to the Conversion function FROM_INTEGRAL_NUMBER. Select
the String 2 field in the Rule Editor. Then select the category Conversion in the functions list
on the left. Within the list now displayed, double-click the function
FROM_INTEGRAL_NUMBER - making this the second parameter to the CONCATENATE
function. Since a function was selected, that function will now be the one displayed in the
middle section of the Rule Editor. Again also note the update to the Structure View:
October 2013
46
52. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
35. The parameter to the FROM_INTEGRAL_NUMBER function will be another function call to
the Math function SUM. Set this by selecting the Conversion Parameter field and then
selecting the Mathematical category in the function term list on the left. In the list of
functions now displayed, double-click the SUM function.
The SUM function will add all parameter values and return the result. For this rule the logic
needed is to add the total number of local FlightBooking object instances and add one to
that total. The first parameter to the SUM function will then be a call to the Property
function COUNT. Select the Number 1 parameter field in the Rule Editor and select the
COUNT function for this parameter from the Property category of functions.
The COUNT function counts the number of object instances in a given collection property.
This collection property is provided as the first parameter to the COUNT function. As an
optional second parameter to the COUNT function, is the Include Criteria. The term
provided as this function parameter will be evaluated once for each object in the provided
collection property. Each object in the collection for which the term returns true will be
counted. Objects for which the term returns false will be ignored.
October 2013
47
53. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
For this rule, the collection to be counted is the FlightBooking collection property. This
should then be the first parameter to the COUNT function. Select the Object Collection
parameter field in the Rule Editor. Then select the properties list by clicking the Properties
icon
found just to the right of the parameter fields. This displays a popup menu that will
include the menu item FlightBookingCollection. Select this item in the menu, which will set
this collection property as the Object Collection parameter for the COUNT function.
The rule function structure will now appears as follows:
36. The “Include Criteria” parameter field will now be enabled. This term is evaluated once for
each object instance in the collection property provided as the Object Collection parameter
to COUNT. The “Include criteria” needed for this rule is to evaluate the BookingID property
of a FlightBooking object and determine if the first six characters begin with the text
“LOCAL_”. If it does, the term provided as the Include Criteria to the COUNT function
should return true, which will then cause the object to be counted. If it does not begin with
this text the term should return false, and the object will not be counted.
The “Include Criteria” parameter, then, begins with a function call to the Logical function
EQSTR. This function compares two or more string values and returns true if they are all
equal or false if any one of its parameters is different. For this rule the EQSTR function
will compare the first six characters of the BookingID property to the constant value
LOCAL_ and return true if they are equal. To obtain these first six characters, the function
LEFT will be used, which is a String function.
October 2013
48
54. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
37. To implement this portion of the logic, select the Include Criteria parameter. Click on
, in
the list of functions select the Logical category and then double-click the EQSTR function.
This function will now be displayed in the center of the Rule Editor. Select the String 1
parameter field. Then select the String function category and select the function LEFT.
38. The Structure of the rule will now appears as follows:
39. The LEFT function is now displayed in the Rule Editor. Select the Source String parameter
field and then click the Properties icon
. The only item displayed in the menu will be
Browse Properties... Select this item to display the Target Browser screen. In the tree
control displayed, select the item Other Objects | “FlightBooking” Object | “BookingID”
Property.
40. Click the OK button to return to the Rule Editor. This property will now be the first
parameter to the LEFT function.
October 2013
49
55. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
41. The second argument to LEFT is the number of characters to extract from the first
parameter, counting from the left. Enter the value 6 in the Length parameter field. The
Structure View will now appear as follows:
42. The second argument to the EQSTR function must now be provided. To return to this
function, select it in the Structure view on the right side of the Rule Editor. The function and
its parameters will now be displayed in the Rule Editor. String 1 will be set to the function
LEFT. Select String 2 and enter the text LOCAL_ in the field.
43. Finally, in the Structure View select the function call to SUM, which will display the function
in the Rule Editor. The Number 1 parameter field will be set to COUNT. Select the Number 2
parameter field and enter the value of 1.
The InitialBookingID rule has now been defined. Review the Structure view and verify it
matches the following example:
The logic of this rule, as defined above will result in the return value of a string value
containing LOCAL_n, where n is the total number of local FlightBooking objects in the
FlightBooking collection property, plus 1.
44. Click on the
button
45. This will return you back to the BookingID property definition
October 2013
50
56. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
46. Click on the
button
47. Next, we will set the initial values of the fields CarrierID, ConnectionID, FlightDate and
OrderDate, since these values are already available in our FlightSchedule Object
48. Click on the
button
49. Double-click on the Property CarrierID
50. Click on the dropdown for Initial Value and choose “From a different object property”
51. Click on the
October 2013
button next to the Other Property Field, choose Browse Objects
51
57. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
52. You will see the below screen
Expand the Other Objects node > “Flight Schedule” Object > Choose “CarrierID” Property
53. Click on the
54. Click on the
button
button
55. Click on the
button to get back to the Properties list
56. Double-click on the ConnectionID Field
57. Click on the dropdown for Initial Value and choose “From a different object property”
58. Click on the
button next to the Other Property Field, choose Browse Objects
59. Choose Other Objects > FlightSchedule Object > ConnectionID
60. Click on the
61. Click on the
October 2013
button
button
52
58. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
62. Click on the
button to get back to the Properties list
63. Double-click on the FlightDate Field
64. Click on the dropdown for Initial Value and choose “From a different object property”
65. Click on the
button next to the Other Property Field, choose Browse Objects
66. Choose Other Objects > FlightSchedule Object > FlightDate
67. Click on the
68. Click on the
69. Click on the
button
button
button to get back to the Properties list
4.1.5 Create Steps and Screens for the AddBooking Transaction
1.
Click on the Steps Node under the Project Explorer
2. You will see the Steps defined for this module
3. Click on
button > Java Steplet > Existing Class
4. In the next screen, choose the FlightBookingSteplet
October 2013
53
59. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
5. Click on
button
6. Click on Transactions under Project Explorer
October 2013
54
60. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
7. Double click on the AddBooking Transaction
8. You will see the Transaction definition
October 2013
55
61. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
9. Click on Update Steps
10. Click on the
October 2013
button
56
62. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
11. Double-click on the newly added Transaction Step
Update the following details:
Step: NewJavaSteplet2 (By choosing the
Response to Client: Delete Client Object
button)
12. Click on the
button
13. Now, we will create Screenset for the AddBooking Transaction
14. Click on Screensets in the Project Explorer
October 2013
57
63. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
15. Click on the
button
Update the following details:
Displays: Transaction – AddBooking
Name: AddBooking
16. Click on the
button
17. Click on Platforms
October 2013
58
64. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
18. Click on
> Windows Mobile > Pocket PC Portrait
Update the following details:
Caption: Add Booking
19. Click on the
button
20. Click on Platform Screens
October 2013
59
65. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
21. Click on
button
Add the following fields in the same order
22. Click on
button
Update the following details:
Name: AddBooking_PPC_Detail1
Caption: Create Booking
October 2013
60
66. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
23. Click on the
button
24. Click on Fields
25. Double-click on the field BookingID
26. Check the Read-only checkbox
27. Click on the
28. Click on the
October 2013
button
button to go back to the Fields list
61
67. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
29. Similarly we will make the following fields as Read-only
CarrierID
ConnectionID
FlightDate
30. Double-click on the field CarrierID
31. Check the Read-only checkbox
32. Click on the
button
33. Click on the
button to go back to the Fields list
34. Double-click on the field ConnectionID
35. Check the Read-only checkbox
36. Click on the
button
37. Click on the
button to go back to the Fields list
38. Double-click on the field FlightDate
39. Check the Read-only checkbox
40. Click on the
button
41. Under Project Explorer, select Actions
42. Click on the
button
Update the following details:
Name: AddBooking
Display Name: Add Booking
October 2013
62
68. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
43. Click on the
button
44. Click on Action Steps
45. Click on the
button > Transaction
46. Update the following values:
Step Name: AddBookingActionStep
Transaction: AddBooking
Screen Set: AddBooking
October 2013
63
69. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
47. Click on the
button
48. Click on the
button
49. Click on the
button > Apply
October 2013
64
70. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
50. Next we will create a button on the Details Page to invoke the AddBooking Transaction
51. Expand the node Screen Set from the Project Explorer, Expand ShowFlightScheduleDetails
–ScreenSet > Expand Screen > ShowFlightScheduleDetails_PPC_Detail1 > Choose Buttons
October 2013
65
71. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
52. Click on the
button
Update the following fields:
Name: BookFlight
Label: Book Flight
53. Click on the
button next to the Target field
54. Click on Browse
October 2013
66
72. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
55. Choose “FlightBookingModule” Module’s Main Object (“Main Object”)
56. Click on
October 2013
button
67
73. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
57. Click on the
October 2013
button
68
74. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4.1.6 Create the Agentry definition to fetch the bookings
Next we will create the Agentry definitions to fetch the bookings made by the current user
1.
Click on the Steps node under the Project Explorer
2. You will see the Steps defined for this module
3. Click on
button > Java Steplet > Existing Class
4. On the next screen, type FlightBookingGetSteplet (click Enter) and choose the
FlightBookingGetSteplet from Matching items
October 2013
69
75. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
5. Click on the
button
6. Under the Project Explorer, click on Fetches
7. Click on the
button > FlightBookingCollection
Update the following information
Name: GetBooking
Display Name: GetBooking
Main Fetch: Checked
October 2013
70
76. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
8. Click on the
button
9. Click on Server Exchange Step
10. Click on the
button
Update the following details:
Step: NewJavaSteplet3
October 2013
71
77. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
11. Click on the
button
12. Next, we will create a new screen to show up the list of all bookings made by the current
user
13. Expand the Screen Set node under Project Explorer > Expand ShowFlightSchedule Screen
set > choose Screens
14. Click on the
button > List Screen > FlightBookingCollection
15. Choose the following fields in the same order
October 2013
72
78. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
16. Click on
button
Update the following details:
Name: ShowFlightBookings_PPC_List1
Caption: My Bookings
October 2013
73
79. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
17. Click on the
button
18. Under the Project Explorer, click on Actions
19. Double-click on the existing AddBooking Action
October 2013
74
80. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
20. Click on the Action Steps
21. We will not add another Action Step to show the locally created booking on the mobile
device
22. Click on the
October 2013
button > Navigation
75
81. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
23. Update the below fields:
Step Name: ShowBookingStep
Screen Set: ShowFlightSchedules
Close Screen Set(s): Close all screen sets except for the main screen set
Screen: ShowFlightBookings_PPC_List1
24. Click on the
button
25. Next, we will add a Transmit button to the ShowFlightBookings_PPC_List1 screen
October 2013
76
82. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
26. Expand the Screen Sets Node from the Project Explorer > Expand ShowFlightSchedules
Screenset > Expand Screens > Expand ShowFlightBookings_PPC_List1 Screen > Click on
Buttons
27. Click on the
button
Set the Action to Transmit
Update the following fields:
Name: Transmit
Label: Transmit
Action: Transmit
October 2013
77
83. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
28. Click on the
button
29. We are now done with the definitions in the Agentry Editor, we will now publish the
definitions to the Agentry Server
30. Click on the
October 2013
button to publish the definitions to the Agentry Server
78
84. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
31. Click on the
October 2013
button
79
85. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
October 2013
80
86. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
32. Click on the
button
33. Now we will export the Jar files which contains the Java Classes
34. Click on File > Export
October 2013
81
87. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
35. In the next screen,
36. Expand Java > choose JAR file
37. Click on
button
Update the following values:
Select ZFlightBooking under Select resources to export
Uncheck .classpath and .project
October 2013
82
88. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
Select options Export all output folders for checked projects
Select Export Java source files and resources
38. Click on
October 2013
button
83
89. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
39. Since you already exported the Jar file for the Fetch exercise in the previous guide (See
section Business Scenario of this document), the system prompts asking if you want to
replace the existing Jar file
40. Click on
button
4.1.7 Define Mobile Application Parameters for the Transaction and Fetch
1.
From the SAP GUI, launch Transaction /n/syclo/configpanel
2. Config Panel is launched
October 2013
84
90. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
3. Click on the link
4. From the Defined Mobile Application List, click on your Application Configuration
(ZXX_FLIGHTBOOKING)
5. Click on the Parameters tab
October 2013
85
91. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
6. Click on the
button
7. Click on the
button
Enter the following Parameter Detail:
Parameter Group: SAPOBJECT
Param. Name: FlightBooking
Param. Value: com.syclo.sap.sflight.customer.object.FlightBooking
Active Flag: Checked
8. Click on the
button
Enter the following Parameter Detail:
Parameter Group: BAPI_WRAPPER
Param. Name: com.syclo.sap.sflight.customer.bapi.FlightBookingBapi
October 2013
86
92. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
Param. Value: ZXX_BAPI_CRT_FLIGHT_BOOKING (XX is your Unique number)
Active Flag: Checked
9. Click on the
button
Enter the following Parameter Detail:
Parameter Group: BAPI_WRAPPER
Param. Name: com.syclo.sap.sflight.customer.bapi.FlightBookingGetBapi
Param. Value: ZXX_BAPI_GET_FLIGHT_BOOKING (XX is your Unique number)
Active Flag: Checked
10. Click on the
button
11. Click on the
button to choose the transport request
Your Parameter List should be as follows:
October 2013
87
93. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
12. Restart the Agentry Server
4.1.8 Test Application in ATE
1.
Launch the Agentry Test Environment
Enter UserID and Password (the same credentials you would use to log into the SAP ERP
back-end)
2. Click on OK
3. Choose your server from the list
October 2013
88
94. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4. Click on OK Button
5. Choose your Server and click on OK Button
October 2013
89
95. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
6. Choose a Flight Schedule and click on Details
7. Click on Book Flight button
October 2013
90
96. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
Your Name
Enter a Passenger Name and click on the
Button
8. You should see the Local Object that you have created, listed with the ID Local_1
9. Click on Transmit button
Choose Connection: Network Connection
October 2013
91
97. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
And click on Start button
October 2013
92
98. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
10. Click on OK button
11. Notice the highlighted section, you will see the Local Object has been replaced with a
unique number assigned by the back-end system
October 2013
93
99. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4.2 Data Tables
1.
Let us now see how to create a Data Table in your Agentry project.
Data tables have two columns, one of which is an index/primary key and the other has
descriptive content. Data tables are most often used as dropdown lists for selecting a value
for a field on the mobile device.
2. We will begin by creating the back-end business logic to provide the values for the Data
Table
3. Launch Transaction /nse24 in SAP GUI
4.
Enter Object type: Z00_GET_AIRPORT_DATA_TABLE
(
If you haven’t created the Z00 template class, you can do so by using the source code
provided in the Appendix section D of this document)
5. Click on the
button and Enter
Copy to: ZXX_GET_AIRPORT_DATA_TABLE
October 2013
94
100. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
6. Click on the
button
Choose Package: ZXX_FLIGHTBOOKING
7. Click on
button
8. Choose the Transport Request
9. Click on the
October 2013
button
95
101. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
10. Click on the
11. Click on the
12. Click on the
button
button
button
13. Next we need to create the MDO Object in the Configuration Panel
14. Launch Transaction /n/syclo/configpanel from the SAP GUI
October 2013
96
102. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
15. Click on the
October 2013
link
97
103. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
16. Click on the
button
Enter the following data:
Mobile Data Object Id: ZXX_AIRPORT_DATA_TABLE (XX is your unique number)
Description: XX Airport Data Table
Data Object Type: Data Table
Mobile Application: XX Flight Booking App (Your Mobile Application Configuration)
Data Object Handler: ZXX_GET_AIRPORT_DATA_TABLE : Class Handler to GET DT
Get Method: GET
Data Object Active: Checked
17. Click on the
button
18. Click on the
button to choose your transport request
19. Next step is to create the Agentry Definitions for the data table. Launch Eclipse and switch
to Agentry (Properties) Perspective
20. From the Project Explorer, choose Data Table node
October 2013
98
104. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
21. Click on the
button > via BackendSAPConnection > Existing Class
22. Enter com.syclo.sap.DataTable
October 2013
99
105. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
23. Click on
button
Update the following information:
Name: dt_Airport
Display Name: Airport Data Table
October 2013
100
106. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
24. Click on the
button
25. We are now done with the definitions in the Agentry Editor, we will now publish the
definitions to the Agentry Server
26. Click on the
27. Click on the
October 2013
button to publish the definitions to the Agentry Server
button
101
107. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
28. Click on the
button
29. In the next step, we need to define Parameters for the Mobile Application Configuration
30. Launch Transaction /n/syclo/configpanel from the SAP GUI
October 2013
102
108. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
31. Click on the
choose your Application Configuration
link. From the Defined Mobile Applications list
32. Click on the Parameters tab
October 2013
103
109. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
33. Click on the
button
34. Click on the
button
Enter the following Parameter Detail:
Parameter Group: DT_MDOID
Param. Name: dt_Airport
Param. Value: ZXX_AIRPORT_DATA_TABLE (where XX is your unique user number)
Active Flag: Checked
35. Click on the
button
36. Click on the
button to choose your Transport Request
37. Restart the Agentry Server
38. Test Application in Agentry Test Environment by perform a Transmit
October 2013
104
110. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
39. Click on Inspect > Data Table > dt_Airport
October 2013
105
111. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4.3 Complex Tables
...
4.3.1 Create the Back-end Business Logic for the Complex Table
1.
Let us now see how to create a Complex Table in Agentry. Unlike the Data Tables, Complex
Tables have multiple fields and are meant to store large amounts of data. They are
searchable and Indexes provide the structure and search behavior to the complex table. A
complex table must have at least one index, which is the primary index (created on the field
containing the unique identifier for each record).
2. We will begin by creating the back-end business logic first to provide the values for the
Complex Table
3. Launch Transaction /nse24 in SAP GUI
Enter Object Type: Z00_GET_CARRIER_COMPLEX_TAB
(
If you haven’t created the Z00 template class, you can do so by using the source code
provided in the Appendix section E of this document)
4.
Click on
button and enter:
Copy to: ZXX_GET_CARRIER_COMPLEX_TAB
October 2013
106
112. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
5. Click on
button
6. Click on
button
7. Choose the Transport Request
8. Click on the
button
9. Click on the
October 2013
107
113. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
10. Click on the
button
11. Click on the
button
12. Launch Transaction /nse37
Enter Function Module: Z00_BAPI_GET_CARRIER_CT
(
If you haven’t created the Z00 template class, you can do so by using the source code
provided in the Appendix section F of this document)
October 2013
108
114. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
13. Click on the
button
Enter the following:
To Function module: ZXX_BAPI_GET_CARRIER_CT
Function group: ZXX_FLIGHTBOOKING_FGRP
14. Click on the
button
15. Click on the
button in your newly created function module
(ZXX_BAPI_GET_CARRIER_CT)
October 2013
109
115. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
16. Click on the
button and then on OK.
4.3.2 Create MDO Object in Configuration Panel
1. Launch Transaction /n/syclo/configpanel from the SAP GUI
October 2013
110
116. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
2. Click on the
October 2013
link
111
117. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
3. Click on the
button
Enter the following data:
Mobile Data Object Id: ZXX_CARRIER_COMPLEX_TABLE (XX is your unique number)
Description: XX Carrier Complex Table
Data Object Type: Complex Table
Mobile Application: XX Flight Booking App (Your Mobile Application Configuration)
Data Object Handler: ZXX_GET_CARRIER_COMPLEX_TAB: Class Handler for Get Flight CT
Get Method: GET
Data Object Active: Checked
4. Click on the
5. Click on the
6. Click on the
7. Click on the
October 2013
button
button to choose the Transport Request
link
link
112
118. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
8. Click on the
button
9. Click on the
button next to the BAPI Wrapper Name
Enter:
Function Module: ZXX_BAPI_GET_CARRIER_CT
10. Click on the
October 2013
button
113
119. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
11. Choose the Function Module and click on the
12. Click on the Assignments tab
button
13. Click on the
button
Enter the following values:
Mobile Application: XX Flight Application (Your Application Configuration Copy)
Mobile Data Object Id: ZXX_CARRIER_COMPLEX_TABLE
Method Type: Get method
Active Flag: Checked
Default Assignment: Checked
Your Mobile Data Object Assignment List should look like this:
October 2013
114
120. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
14. Click on the
15. Click on the
October 2013
button
button to choose the transport request
115
121. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4.3.3 Create Agentry Editor Definitions
1. In the Agentry Editor, switch to the Java Perspective
2. Right-click on the package com.syclo.sap.sflight.customer.object > New > Class
Enter Name: FlightCarrierCT
October 2013
116
122. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
3. Click on
button
4. Replace the source code with the provided here:
package com.syclo.sap.sflight.customer.object;
import com.sap.mw.jco.JCO.Table;
import com.syclo.sap.ComplexTableObject;
public class FlightCarrierCT extends ComplexTableObject {
public String CARRID;
October 2013
117
123. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
public String CARRNAME;
public String CURRCODE;
public String URL;
public String getCARRID() {
return CARRID;
}
public void setCARRID(String cARRID) {
CARRID = cARRID;
}
public String getCARRNAME() {
return CARRNAME;
}
public void setCARRNAME(String cARRNAME) {
CARRNAME = cARRNAME;
}
public String getCURRCODE() {
return CURRCODE;
}
public void setCURRCODE(String cURRCODE) {
CURRCODE = cURRCODE;
}
public String getURL() {
return URL;
}
public void setURL(String uRL) {
URL = uRL;
}
@Override
public String getID() {
return getCARRID();
}
@Override
public void setNotes(Table arg0) throws Exception {
October 2013
118
124. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
// TODO Auto-generated method stub
}
@Override
public void setProperties(Table arg0) throws Exception {
setCARRID(arg0.getString("CARRID"));
setCARRNAME(arg0.getString("CARRNAME"));
setCURRCODE(arg0.getString("CURRCODE"));
setURL(arg0.getString("URL"));
}
@Override
public void setPropertiesForDeletedRecord(Table arg0) throws Exception {
// TODO Auto-generated method stub
}
}
5. Switch to the Agentry (Properties) Perspective
6. Under the Project Explorer click on Complex Table
7. Click on
October 2013
button > BackendSAPConnection > Existing Class
119
125. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
8. Enter Class Name in Select entries: com.syclo.sap.ComplexTable
9. Click on
button
Update the following fields:
Name: ct_Carrier
Display Name: Carrier Complex Table
October 2013
120
126. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
10. Click on the
11. Click on Fields
button
12. Click on the
button
13. Click on the
button
14. Click on
October 2013
button
121
127. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
15. Click on the
button
16. Click on the
button
17. Click on
button
18. Click on the
button
19. Click on the
button
20. Click on
21. Click on the
October 2013
button
button
122
128. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
22. Click on the
button
You should have the following fields populated:
23. Click on
button
24. Click on Indexes
25. Click on the
October 2013
button
123
129. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
26. Click on the
button
27. Click on the
button
Your ct_Carrier Java Complex Table Indexes should look like the following screen:
October 2013
124
130. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
28. Publish the Agentry Definitions to the Agentry Server
. The publish window should show
2 new definitions.
29. Export the ZFlightBooking. jar File to the Server as well, as you did in the previous chapter.
30. Click on File > Export
October 2013
125
131. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
31. Expand Java > choose JAR file
32. Click on
October 2013
button
126
132. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
33. Click on
button
4.3.4Enter Mobile Application Parameter
1.
Launch Transaction /n/syclo/configpanel from SAP GUI
October 2013
127
133. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
2. Click on
link
3. Choose your Mobile Application Configuration
4. Click on the Parameters Tab
5. Click on the
6. Click on the
button
button
Parameter Group: CT_SAPOBJECT
Param. Name: ct_Carrier
Param. Value: com.syclo.sap.sflight.customer.object.FlightCarrierCT
Active Flag: Checked
7. Click on the
October 2013
button
128
134. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
8. The Param Value should be the Z##_BAPI_GET_CARRIER_CT created by you
9. Click on the
button
10. Click on the
button and Continue on screen prompt
Your Parameter List should look like the following (note that it includes other
parameters added from previous exercises):
11. Restart the Agentry Server
4.3.5 Test the Mobile Application in ATE
1.
Perform a transmit in the Agentry Test Environment
You will now see ct_Carrier Complex Table from File > Inspect Menu.
October 2013
129
135. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
October 2013
130
136. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4.4 Deployment of the Mobile Application on SAP Mobile
Platform 2.3
1. Stop your Agentry Development Server
2. Locate the Agentry Server Directory
3. Right Click on the folder Application and choose Add to Application.zip
October 2013
131
137. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
4. You will notice that a Zip File Application.zip is created
5. Double Click on the Application.zip file
6. Locate the following files in your Agentry Server Directory
Agentry.ini
JavaBE.ini
librfc32.dll
sapjcorfc.dll
SAPCommon-121161.jar
sapjco.jar
ini4j.jar
ZFlightBooking.jar
7. Multiple select the above files using Ctrl Key+ Click and then drag and drop these files into
the Application.zip
October 2013
132
138. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
8.
Click on OK
9. Close the Application.zip file
10. Now we need to deploy the Application to SMP2.3 using SAP Control Center. Start SMP
Services
11. Launch and login to the SAP Control Center
October 2013
133
139. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
12. Click on the Applications Node
13. Click on the
October 2013
button
134
140. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
14. Enter the following,
Application ID: com.sap.FlightBooking
Display name: FlightBooking
Description: FlightBooking Application
Client SDK Type: Agentry (Choose from Dropdown)
Security configuration: Agentry (disabled after choosing Client SDK Type)
Domain: default (disabled after choosing Client SDK Type)
October 2013
135
141. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
15. Select the Checkbox: Application File
16. Click on the
button, Locate the Agentry Server directory
17. Chose ZIP Files form the File of type dropdown
October 2013
136
142. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
18. Select the Application.zip file that you created in the previous step.
19. Click on the
October 2013
button
137
143. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
20. Click on the
button
21. On the SAP Control Center, you will get a Success message
22. Restart the SMP Services
23. Reset the Agentry Test Environment. Now you can test your application in the ATE. You
should see in the Agentry Server list your production Agentry Server running.
24. In addition, you can check the Agentry logs under:
...SAPMobilePlatformServersUnwiredServerlogs<YourApplication>
October 2013
138
144. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
25. To Change Log level, Expand the Applications Node, chose your Application, Select the
Logs Tab and set your log levels.
October 2013
139
145. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
5.
Appendix
5.1 Appendix A – Source Code for Z00_CREATE_FLIGHT_BOOKING
class Z00_CREATE_FLIGHT_BOOKING definition
public
inheriting from /SYCLO/CL_CORE_DO_HANDLER_BASE
create public .
public section.
*"* public components of class Z00_CREATE_FLIGHT_BOOKING
*"* do not include other source files here!!!
methods /SYCLO/IF_CORE_DO_HANDLER~CREATE
redefinition .
methods /SYCLO/IF_CORE_DO_HANDLER~GET
redefinition .
protected section.
*"* protected components of class Z00_CREATE_FLIGHT_BOOKING
*"* do not include other source files here!!!
private section.
*"* private components of class Z00_CREATE_FLIGHT_BOOKING
*"* do not include other source files here!!!
ENDCLASS.
CLASS Z00_CREATE_FLIGHT_BOOKING IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method Z00_CREATE_FLIGHT_BOOKING>/SYCLO/IF_CORE_DO_HANDLER~CREATE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IREF_RFC_OO_DATA
TYPE REF TO /SYCLO/CL_CORE_RFC_OO_DATA
* +--------------------------------------------------------------------------------------</SIGNATURE>
method /SYCLO/IF_CORE_DO_HANDLER~CREATE.
*CALL METHOD SUPER->/SYCLO/IF_CORE_DO_HANDLER~CREATE
* EXPORTING
* IREF_RFC_OO_DATA =
* .
October 2013
140
146. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
DATA: lref_exception TYPE REF TO cx_root.
*Tables and Structures
DATA: ls_bapi_output TYPE /syclo/core_bapi_output_str.
DATA: lt_in_ooref_param TYPE abap_parmbind_tab,
ls_abap_param TYPE abap_parmbind.
DATA: ls_return TYPE bapiret2.
*Variables
DATA: ls_sbook type SBOOK,
lv_carrid type sbook-carrid,
lv_connid type sbook-connid,
lv_fldate type sbook-fldate,
lv_order_date type sbook-order_date,
lv_reserved type sbook-reserved,
lv_passname type sbook-passname,
lv_booking_user type sbook-booking_user,
lv_bookid type sbook-bookid.
data return type INRI-RETURNCODE.
*Field Symbols
FIELD-SYMBOLS: <wa> TYPE ANY,
<table> TYPE ANY TABLE,
<bapi_return> TYPE bapiret2_t.
*****************************************************
* Main Section
*****************************************************
TRY.
* Step 1 - Convert OO parameter into required format
iref_rfc_oo_data->get_ooref_param_tab(
IMPORTING et_in_ooref_param_tab = lt_in_ooref_param ).
LOOP AT lt_in_ooref_param INTO ls_abap_param.
CASE ls_abap_param-name.
WHEN 'IS_SBOOK'.
ASSIGN ls_abap_param-value->* TO <wa>.
October 2013
141
147. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
ls_sbook = <wa>.
ENDCASE.
ENDLOOP.
ASSIGN iref_rfc_oo_data->dref_return->* TO <bapi_return>.
*
lv_unitr = ls_reading-recdu.
*
lv_record_val = ls_reading-recdv.
lv_carrid = ls_sbook-carrid.
lv_connid = ls_sbook-connid.
lv_fldate = ls_sbook-fldate.
ls_sbook-order_date = SY-DATUM.
lv_order_date = SY-DATUM.
lv_reserved = 'X'.
lv_passname = ls_sbook-passname.
lv_booking_user = sy-uname.
ls_sbook-booking_user = sy-uname.
* Generate Next Booking ID Number
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object
= 'SBOOKID'
subobject = lv_carrid
toyear
= lv_order_date(4)
IMPORTING
number
= lv_bookid
returncode = return
EXCEPTIONS
OTHERS
= 1.
CASE sy-subrc.
WHEN 0.
CASE return.
WHEN 1.
*
number of remaining numbers critical
ls_return-type = 'W'.
ls_return-message = 'Nearing End of Number Range'.
APPEND ls_return TO <bapi_return>.
WHEN 2.
*
last number
October 2013
142
148. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
ls_return-type = 'W'.
ls_return-message = 'No More Numbers in Number Range'.
APPEND ls_return TO <bapi_return>.
WHEN 3.
*
no free number left over
ls_return-type = 'E'.
ls_return-message = 'Number Range Full'.
APPEND ls_return TO <bapi_return>.
ENDCASE.
WHEN 1.
*
internal error
ls_return-type = 'E'.
ls_return-message = 'Internal Error in Number Range'.
APPEND ls_return TO <bapi_return>.
ENDCASE.
ls_sbook-bookid = lv_bookid.
ls_sbook-mandt = '800'.
insert into SBOOK CLIENT SPECIFIED values ls_sbook.
if sy-subrc eq 0.
ls_return-type = 'S'.
ls_return-message = 'Booking Successful Booking Reference No ' && ls_sbook-bookid .
APPEND ls_return TO <bapi_return>.
else.
ls_return-type = 'E'.
ls_return-message = 'Booking Failed'.
APPEND ls_return TO <bapi_return>.
endif.
GET REFERENCE OF ls_sbook-bookid INTO ls_abap_param-value.
ls_abap_param-kind = /syclo/cl_core_constants=>rfc_exporting.
ls_abap_param-name = 'EV_BOOKING_ID'.
iref_rfc_oo_data->copy_to_ooref_param(
EXPORTING is_abap_param = ls_abap_param ).
* Class-Based Exception Handling
CATCH cx_root INTO lref_exception.
"#EC CATCH_ALL
/syclo/cl_core_appl_logger=>logger->catch_class_exception(
EXPORTING iv_mobile_user = me->str_bapi_input-mobile_user
iv_mobile_id = me->str_bapi_input-mobile_id
October 2013
143
149. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
iref_exception = lref_exception
iref_return_tab = iref_rfc_oo_data->dref_return ).
ENDTRY.
endmethod.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method Z00_CREATE_FLIGHT_BOOKING>/SYCLO/IF_CORE_DO_HANDLER~GET
* +-------------------------------------------------------------------------------------------------+
* | [--->] IREF_RFC_OO_DATA
TYPE REF TO /SYCLO/CL_CORE_RFC_OO_DATA
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD /SYCLO/IF_CORE_DO_HANDLER~GET.
DATA: lt_abap_param TYPE abap_parmbind_tab,
ls_abap_param TYPE abap_parmbind,
ls_return TYPE bapiret2.
DATA: lref_exception TYPE REF TO cx_root.
DATA: lt_sbook TYPE TABLE OF sbook. "Business data, in our case SBOOK table
FIELD-SYMBOLS: <source> TYPE any,
<return> TYPE bapiret2_t.
ASSIGN iref_rfc_oo_data->dref_return->* TO <return>.
* Retrieve BAPI Import Parameters
iref_rfc_oo_data->get_ooref_param_tab(
IMPORTING et_in_ooref_param_tab = lt_abap_param ).
*Step 1. Timestamp for mobile
IF me->mobile_timestamp_in IS INITIAL.
me->mobile_timestamp_out =
/syclo/cl_core_do_services=>get_sys_timestamp( ).
October 2013
144
150. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
ENDIF.
*Step 2. Fetch the data
select * from sbook into table lt_sbook where booking_user eq sy-uname.
*Step 3. Map the data to return parameters
TRY.
IF lt_sbook[] IS NOT INITIAL.
GET REFERENCE OF lt_sbook[] INTO ls_abap_param-value.
ls_abap_param-kind = /syclo/cl_core_constants=>rfc_table.
ls_abap_param-name = 'ET_SBOOK[]'.
iref_rfc_oo_data->copy_to_ooref_param(
EXPORTING is_abap_param = ls_abap_param ).
ENDIF.
CATCH cx_root INTO lref_exception.
"#EC CATCH_ALL
me->logger->catch_class_exception(
EXPORTING iv_mobile_user = me->str_bapi_input-mobile_user
iv_mobile_id = me->str_bapi_input-mobile_id
iv_user_guid = me->str_bapi_input-user_guid "<-ins 310_700 bugid 25317
iref_exception = lref_exception
iref_return_tab = iref_rfc_oo_data->dref_return ).
ENDTRY.
ENDMETHOD.
ENDCLASS.
5.2 Appendix B – Source code for Z00_BAPI_CRT_FLIGHT_BOOKING
FUNCTION Z00_BAPI_CRT_FLIGHT_BOOKING.
*"---------------------------------------------------------------------*"*"Local Interface:
*" IMPORTING
*"
VALUE(IS_BAPI_INPUT) TYPE /SYCLO/CORE_BAPI_INPUT_STR OPTIONAL
*"
VALUE(IS_SBOOK) TYPE SBOOK OPTIONAL
*" EXPORTING
*"
VALUE(ES_BAPI_OUTPUT) TYPE /SYCLO/CORE_BAPI_OUTPUT_STR
*"
VALUE(EV_BOOKING_ID) TYPE SBOOK-BOOKID
*" TABLES
*"
ET_RETURN STRUCTURE BAPIRET2 OPTIONAL
October 2013
145
151. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
*"---------------------------------------------------------------------**********************************************************************
* Data Declaration Section
**********************************************************************
*Constants
CONSTANTS: lc_bapi_name TYPE funcname VALUE 'Z00_BAPI_CRT_FLIGHT_BOOKING'.
**********************************************************************
* Template Section
**********************************************************************
INCLUDE /syclo/core_bapi_template_incl.
ENDFUNCTION.
5.3 Appendix C – Source code for Z00_BAPI_GET_FLIGHT_BOOKING
FUNCTION Z00_BAPI_GET_FLIGHT_BOOKING.
*"-------------------------------------------------------------------*"*"Local Interface:
*" IMPORTING
*"
VALUE(IS_BAPI_INPUT) TYPE /SYCLO/CORE_BAPI_INPUT_STR
*" EXPORTING
*"
VALUE(ES_BAPI_OUTPUT) TYPE /SYCLO/CORE_BAPI_OUTPUT_STR
*" TABLES
*"
ET_SBOOK STRUCTURE SBOOK OPTIONAL
*"
ET_RETURN STRUCTURE BAPIRET2 OPTIONAL
*"-------------------------------------------------------------------sy-debug = 'X'.
INCLUDE /syclo/core_bapi_template_incl.
ENDFUNCTION.
October 2013
146
152. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
5.4 Appendix D – Source code for Z00_GET_AIRPORT_DATA_TABLE
class Z00_GET_AIRPORT_DATA_TABLE definition
public
inheriting from /SYCLO/CL_CORE_DT_HANDLER
create public .
public section.
*"* public components of class Z00_GET_AIRPORT_DATA_TABLE
*"* do not include other source files here!!!
protected section.
*"* protected components of class Z00_GET_AIRPORT_DATA_TABLE
*"* do not include other source files here!!!
methods GET_DATA_TABLE
redefinition .
private section.
*"* private components of class Z00_GET_AIRPORT_DATA_TABLE
*"* do not include other source files here!!!
ENDCLASS.
CLASS Z00_GET_AIRPORT_DATA_TABLE IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method Z00_GET_AIRPORT_DATA_TABLE->GET_DATA_TABLE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IREF_RFC_OO_DATA
TYPE REF TO /SYCLO/CL_CORE_RFC_OO_DATA
* +--------------------------------------------------------------------------------------</SIGNATURE>
method GET_DATA_TABLE.
*OO Reference Variables
DATA: LREF_EXCEPTION TYPE REF TO CX_ROOT,
LREF_DO_SERV TYPE REF TO /SYCLO/CL_CORE_DO_SERVICES.
DATA: LT_DATA_TABLE TYPE /SYCLO/CORE_DT_TAB,
LS_DATA_TABLE TYPE /SYCLO/CORE_DT_STR.
*Tables & Structures
October 2013
147
153. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
"The following structure contains reference to all available filters
"from ConfigPanel. Filter name is consistent with what is declared
"in filter service method GET_DATA_FILTER_LIST
DATA: BEGIN OF LS_DOF_FILTER_VALS,
CITY
TYPE REF TO /SYCLO/CORE_RANGE_TAB,
END OF LS_DOF_FILTER_VALS.
*Constants
CONSTANTS: LC_MTHD TYPE /SYCLO/CORE_DO_MTHD_DTE VALUE 'GET'.
*********************************************************************
* Main Section
*********************************************************************
TRY.
ME->MESSAGE = 'Entering method ~ GET_DATA_TABLE...'(M01).
ME->LOGGER->LOGINFO( IV_MOBILE_USER = ME->STR_BAPI_INPUT-MOBILE_USER
IV_MOBILE_ID = ME->STR_BAPI_INPUT-MOBILE_ID
IV_USER_GUID = ME->STR_BAPI_INPUT-USER_GUID
IV_MESSAGE = ME->MESSAGE
IV_SOURCE = ME->SOURCE ).
"Set return time stamp at begining if exchange process not used
IF ME->STR_BAPI_INPUT-TIMESTAMP_FROM_MOBILE IS INITIAL.
ME->STR_BAPI_OUTPUT-TIMESTAMP_TO_MOBILE =
/SYCLO/CL_CORE_DO_SERVICES=>GET_SYS_TIMESTAMP( ).
ENDIF.
LREF_DO_SERV = /SYCLO/CL_CORE_DO_SERVICES=>GET_DO_SERVICE(
IREF_LOGGER = ME->LOGGER ).
ME->OREF_MDO_DATA->MAP_LOCAL_DOF_FILTER(
CHANGING CS_FILTERS = LS_DOF_FILTER_VALS ).
SELECT ID AS KEY
NAME
AS VALUE
FROM SAIRPORT
INTO CORRESPONDING FIELDS OF TABLE LT_DATA_TABLE.
LS_DATA_TABLE-DO_ID = ME->STR_DO_SETTING-DO_ID.
MODIFY LT_DATA_TABLE FROM LS_DATA_TABLE TRANSPORTING DO_ID
WHERE DO_ID IS INITIAL.
October 2013
148
154. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
ME->TAB_DATA_TABLE[] = LT_DATA_TABLE[].
* Class-Based Exception Handling
CATCH CX_ROOT INTO LREF_EXCEPTION.
"#EC CATCH_ALL
ME->LOGGER->CATCH_CLASS_EXCEPTION(
EXPORTING IV_MOBILE_USER = ME->STR_BAPI_INPUT-MOBILE_USER
IV_MOBILE_ID = ME->STR_BAPI_INPUT-MOBILE_ID
IV_USER_GUID = ME->STR_BAPI_INPUT-USER_GUID
IREF_EXCEPTION = LREF_EXCEPTION
IREF_RETURN_TAB = IREF_RFC_OO_DATA->DREF_RETURN ).
ENDTRY.
endmethod.
ENDCLASS.
5.5 Appendix E – Source code for Z00_GET_CARRIER_COMPLEX_TAB
class Z00_GET_CARRIER_COMPLEX_TAB definition
public
inheriting from /SYCLO/CL_CORE_CT_HANDLER
create public .
public section.
*"* public components of class Z00_GET_CARRIER_COMPLEX_TAB
*"* do not include other source files here!!!
protected section.
*"* protected components of class Z00_GET_CARRIER_COMPLEX_TAB
*"* do not include other source files here!!!
methods GET_COMPLEX_TABLE
redefinition .
private section.
*"* private components of class Z00_GET_CARRIER_COMPLEX_TAB
*"* do not include other source files here!!!
ENDCLASS.
October 2013
149
155. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
CLASS Z00_GET_CARRIER_COMPLEX_TAB IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method Z00_GET_CARRIER_COMPLEX_TAB->GET_COMPLEX_TABLE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IREF_RFC_OO_DATA
TYPE REF TO /SYCLO/CL_CORE_RFC_OO_DATA
* | [<-->] CREF_COMPLEX_TABLE
TYPE REF TO DATA
* +--------------------------------------------------------------------------------------</SIGNATURE>
method GET_COMPLEX_TABLE.
*OO Reference Variables
data: lref_exception type ref to cx_root,
lref_do_serv type ref to /syclo/cl_core_do_services.
"#EC NEEDED
*Tables and Structures
data: ls_return type bapiret2.
data: lt_flt_temp
type standard table of scarr.
*Table & Structures
"The following structure contains reference to all supported output parameter
"from MDO handler. Output parameter name is set to the same as what is declared
"in receiving BAPI warpper signature for simplicity.
data: begin of ls_mdo_output_vals,
et_complex_table
type ref to /syclo/pm_buspartner_tab,
et_exchange_action_deleted type ref to /syclo/pm_buspart_deleted_tab,
end of ls_mdo_output_vals.
data: begin of ls_flt_key,
CARRID type S_CARR_ID,
end of ls_flt_key,
lt_flt_key like standard table of ls_flt_key.
*Variables
data: lv_select_clause type string.
*Field Symbols
field-symbols:
<filter_tab> type /syclo/pm_buspartner_tab,
October 2013
150
156. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
<list_value> type /syclo/pm_buspartner_str,
<return> type bapiret2_t.
*Constants
constants: lc_mthd type /syclo/core_do_mthd_dte value 'GET'.
*****************************************************
* Main Section
*****************************************************
try.
me->message = 'Entering method ~ GET_COMPLEX_TABLE...'(m02).
me->logger->loginfo( iv_mobile_user = me->str_bapi_input-mobile_user
iv_mobile_id = me->str_bapi_input-mobile_id
iv_user_guid = me->str_bapi_input-user_guid
iv_message = me->message
iv_source = me->source ).
if me->str_bapi_input-timestamp_from_mobile is initial.
me->str_bapi_output-timestamp_to_mobile =
/syclo/cl_core_do_services=>get_sys_timestamp( ).
endif.
*----------------------------------------------------------------------*
* Step 1 - Initialization
*----------------------------------------------------------------------*
"Build Filter from Filter Service & BAPI Input
lref_do_serv = /syclo/cl_core_do_services=>service.
"-->Initialize output tables
create data: ls_mdo_output_vals-et_complex_table,
ls_mdo_output_vals-et_exchange_action_deleted.
assign iref_rfc_oo_data->dref_return->* to <return>.
*----------------------------------------------------------------------*
* Step 2 - "Perform main SQL selection
*----------------------------------------------------------------------*
*Build Keys
October 2013
151
157. How To Build an Agentry based app from scratch connecting to a SAP ERP back-end – Part2
select CARRID from SCARR into table lt_flt_key.
if lt_flt_key[] is initial.
ls_return-type = 'I'.
ls_return-message = 'No data found'(i02).
append ls_return to <return>.
return.
else.
sort lt_flt_key[].
delete adjacent duplicates from lt_flt_key[].
endif.
select * from scarr into corresponding fields of table lt_flt_temp.
sort lt_flt_temp.
delete adjacent duplicates from lt_flt_temp.
if lt_flt_temp[] is initial.
ls_return-type = 'I'.
ls_return-message = 'No data found'(i02).
append ls_return to <return>.
return.
endif.
*----------------------------------------------------------------------*
* Step 3 - Prepare MDO output data
*----------------------------------------------------------------------*
if lt_flt_temp[] is not initial.
assign ls_mdo_output_vals-et_complex_table->* to <filter_tab>.
<filter_tab> = lt_flt_temp[].
endif.
" -->return output data to MDO data object,
" output data in MDO data are mapped to BAPI Wrapper
" data container automatically by POSTPROCESS_MAPPING
me->oref_mdo_data->set_mdo_output_via_ref_struct(
exporting is_mdo_output = ls_mdo_output_vals ).
* Class-Based Exception Handling
catch cx_root into lref_exception.
"#EC CATCH_ALL
/syclo/cl_core_appl_logger=>logger->catch_class_exception(
exporting iv_mobile_user = me->str_bapi_input-mobile_user
October 2013
152