You are on page 1of 32

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Mobile offline application development: a complete guide using Mobile Infrastructure tools
Applies to:
SAP NetWeaver Mobile Infrastructure (MI).

Summary
This article is mainly for the newbies in MI which provides with step by step development procedure for mobile applications from the backend/middleware using Mobile Infrastructure.(Up to generation of MeRep XML). Here a simple mobile application has been developed and explained with coding. This article provides link to other published article, which explains step by step procedure to develop mobile application using MeRep XML with NWDS. Thus this article can be taken as a guide to develop applications in MI. Author(s): Karthick Lakkaraju Company: Cognizant Technology Solutions Created on: 3 June 2007

Author Bio
Karthick Lakkaraju is presently working for Cognizant. For the past 1.6 years he has been working for SAP-NetWeaver MI. He has developed a few applications in Smart sync and presented in Tech Ed 2006. He is one of the top contributors in the area of NetWeaver Mobile (Forums). Expertise: MI Backend/Middleware development, ABAP, Mobile infrastructure development tools.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 1

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Table of Contents
Introduction: ..................................................................................................................................... 3 BAPI Wrappers and its types: ...................................................................................................... 3 How to develop BAPI Wrappers: ................................................................................................. 4 GETLIST BAPIWRAPPER SAMPLE CODING:......................................................................... 12 GETDETAIL BAPIWRAPPER SAMPLE CODING: ................................................................... 13 CREATE BAPIWRAPPER SAMPLE CODING: ......................................................................... 13 MODIFY BAPIWRAPPER SAMPLE CODING:.......................................................................... 15 DELETE BAPIWRAPPER SAMPLE CODING:.......................................................................... 17 SYNCBO DESIGN: .................................................................................................................... 18 CREATION OF MCD: ................................................................................................................ 25 Download of MeRep XML: ......................................................................................................... 27 Furthur development with MeRep XML using NWDS:.............................................................. 29 Related Content:............................................................................................................................ 30 Disclaimer and Liability Notice....................................................................................................... 31

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Introduction:
SAP Netweaver MI (Mobile Infrastructure) is a technology platform for offline access to SAP systems or other ERP systems via portable devices like PDA or Laptop. Here step by step development process for mobile applications from backend/middleware is clearly explained. A sample application with one syncbo has been developed here.

How to develop BAPI wrappers.(In Backend). How to develop BAPI wrappers.(In Backend)(For single syncbo). How to design Syncbos (Mapping, Generating, replicating the syncbo) (In Middleware). Creating MCD for the syncbo.(In Middleware). Generating MeRep XML.(In Middleware). Link provided to article on how to proceed with generated MeRep XML and further develop the application.

BAPI Wrappers and its types:


BAPI Wrappers are normal function modules which are RFC enabled , wrapped and follow certain rules to comply a standard interface. All the business logic of the application resides inside the BAPI Wrappers (coding) There are 5 BAPI wrappers: GETLIST : Returns a list of business object header data based on the selection criteria specified in the Import parameters. GETDETAIL: Returns one header data as Export parameter out of the header data list based on the object key(s) specified in the Import parameters. It also returns one or more list of item entries associated with the header data. CREATE: Creates a single business object, and returns object key(s) MODIFY: Modifies the business object header and also its item data. DELETE: Deletes the specified business object (including the items). All the wrappers are not mandatory, only Getlist and Getdetail are mandatory. Generated code make assumptions about the interface of the BAPI wrappers, so it needs to follow certain rules:

RFC enabled. Parameter named RETURN of type BAPIRET2 structure, needs to be defined as Export or Table parameters. Parameters can only refer to a structure or field of a structure. No changing parameters. No Exceptions. Consistency between all the 5 Bapi Wrappers must be kept, while defining Export, Import, Table parameters. All BAPIs must be stored in the same Function Group.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 3

Mobile offline application development: a complete guide using Mobile Infrastructure tools

How to develop BAPI Wrappers:


BAPI Wrapper Wizard ensures that all the assumptions are met. Before creating BAPI Wrappers, backend tables have to be created. EXAMPLE: Z1CUSTOMER (Header table) Z1CUSTOMERADD (Item table 1) Z1EMAIL (Item table 2) These item tables are related to the header table with foreign key relationship. Logon to the backend system and Go To transaction MEREP_SBUILDERGOTO-->BAPI Wrapper Wizard

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 4

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Press Continue to proceed further.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 5

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Fill the names of the BAPI Wrappers (only which are required). Here sample application will be developed including the code. Press Continue

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 6

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Here Z1CUSTOMER is the header table which is existing in the backend. Press Continue.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 7

Mobile offline application development: a complete guide using Mobile Infrastructure tools

These are the fileds of the header table with the header key field checked. Press continue.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 8

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Add the entries and provide with the item tables (child tables of header table) with SID:010,020,030 etc.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 9

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Either Export or Table parameters should be checked. This will ensure that parameter RETURN of type BAPIRET2 will be filled in Export or Table parameters. Press continue.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 10

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Here Function Group name should be provided where all the BAPIs are stored in this function group. Here Function group will be automatically generated. Press Continue and then press complete in the next screen. Save the functiongroup. Now all the 5 BAPIWRAPPERS are generated and activated. Goto se37 and provide the name of the bapiwrappers which were created using BAPI Wrapper Wizard.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 11

Mobile offline application development: a complete guide using Mobile Infrastructure tools

GETLIST BAPIWRAPPER SAMPLE CODING:

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 12

Mobile offline application development: a complete guide using Mobile Infrastructure tools

GETDETAIL BAPIWRAPPER SAMPLE CODING:

CREATE BAPIWRAPPER SAMPLE CODING:


FUNCTION ZSAMPLE_CREATE. *"-------------------------------------------------------------------*"*"Global Interface: *" IMPORTING *" VALUE(I_TOP) TYPE Z1CUSTOMER *" EXPORTING *" VALUE(E_ZCUSTOMERID) TYPE Z1CUSTOMER-ZCUSTOMERID *" TABLES *" T_010 STRUCTURE Z1CUSTOMERADD *" T_020 STRUCTURE Z1EMAIL *" RETURN STRUCTURE BAPIRET2 *"-------------------------------------------------------------------DATA: z11customerid LIKE z1customer-zcustomerid. TABLES : z1customer. DATA: z11addressid LIKE z1customeradd-zaddressid. TABLES : z1customeradd.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 13

Mobile offline application development: a complete guide using Mobile Infrastructure tools

DATA: z11sequencenumber LIKE z1email-zsequencenumber.. TABLES : z1email. DATA: lds_return LIKE bapireturn1. DATA: gdf_message_dummy TYPE string. SELECT MAX( zcustomerid ) FROM z1customer INTO z11customerid. z11customerid = z11customerid + 1. i_top-zcustomerid = z11customerid. INSERT z1customer FROM i_top. DATA: zcustomerid LIKE z1customer-zcustomerid, wa_i_t_010 LIKE LINE OF t_010, wa_i_t_020 LIKE LINE OF t_020. zcustomerid = z11customerid. e_zcustomerid = zcustomerid. LOOP AT t_010 INTO wa_i_t_010. wa_i_t_010-zcustomerid = zcustomerid. SELECT MAX( zaddressid ) FROM z1customeradd INTO z11addressid. z11addressid = z11addressid + 1. wa_i_t_010-zaddressid = z11addressid. INSERT z1customeradd FROM wa_i_t_010. ENDLOOP. LOOP AT t_020 INTO wa_i_t_020. wa_i_t_020-zcustomerid = zcustomerid. SELECT MAX( zsequencenumber ) FROM z1email INTO z11sequencenumber. z11sequencenumber = z11sequencenumber + 1. wa_i_t_020-zsequencenumber = z11sequencenumber. INSERT z1email FROM wa_i_t_020. ENDLOOP. ENDFUNCTION.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 14

Mobile offline application development: a complete guide using Mobile Infrastructure tools

MODIFY BAPIWRAPPER SAMPLE CODING:


FUNCTION zsample_modify. *"-------------------------------------------------------------------*"*"Global Interface: *" IMPORTING *" VALUE(I_TOP) TYPE Z1CUSTOMER *" TABLES *" T_010 STRUCTURE Z1CUSTOMERADD *" T_020 STRUCTURE Z1EMAIL *" RETURN STRUCTURE BAPIRET2 *"-------------------------------------------------------------------DATA: it_z1customer TYPE TABLE OF z1customer, wa_it_z1customer LIKE LINE OF it_z1customer. DATA: lds_return LIKE bapireturn1, gdf_message_dummy TYPE string .

SELECT * FROM z1customer INTO CORRESPONDING FIELDS OF TABLE it_z1customer WHERE zcustomerid = i_top-zcustomerid. LOOP AT it_z1customer INTO wa_it_z1customer. ENDLOOP. IF sy-subrc = 0. DELETE z1customer FROM wa_it_z1customer. ENDIF. INSERT z1customer FROM i_top. DATA: zcustomerid LIKE z1customer-zcustomerid, wa_i_t_010 LIKE LINE OF t_010, wa_i_t_020 LIKE LINE OF t_020. DATA: wa2_t_010 TYPE z1customeradd, dt_zaddressid TYPE z1customeradd-zaddressid. DATA: it3_t_010 TYPE TABLE OF z1customeradd, wa3_t_010 TYPE z1customeradd. zcustomerid = i_top-zcustomerid. SELECT * FROM z1customeradd INTO TABLE it3_t_010 WHERE zcustomerid = i_top-zcustomerid. LOOP AT t_010 INTO wa3_t_010. DELETE it3_t_010 WHERE zaddressid = wa3_t_010-zaddressid AND zcustomerid = wa3_t_010-zcustomerid. ENDLOOP. DELETE z1customeradd FROM TABLE it3_t_010.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 15

Mobile offline application development: a complete guide using Mobile Infrastructure tools

LOOP AT t_010 INTO wa2_t_010. IF wa2_t_010-zaddressid = '00000000'. SELECT MAX( zaddressid ) FROM z1customeradd INTO dt_zaddressid. dt_zaddressid = dt_zaddressid + 1. wa2_t_010-zaddressid = dt_zaddressid. wa2_t_010-zcustomerid = i_top-zcustomerid. ENDIF. MODIFY z1customeradd FROM wa2_t_010. ENDLOOP. DATA: wa2_t_020 TYPE z1email, dt_zsequencenumber TYPE z1email-zsequencenumber. DATA: it3_t_020 TYPE TABLE OF z1email, wa3_t_020 TYPE z1email. SELECT * FROM z1email INTO TABLE it3_t_020 WHERE zcustomerid = i_top-zcustomerid. LOOP AT t_020 INTO wa3_t_020. DELETE it3_t_020 WHERE zsequencenumber = wa3_t_020-zsequencenumber AND zcustomerid = wa3_t_020-zcustomerid. ENDLOOP. DELETE z1email FROM TABLE it3_t_020. LOOP AT t_020 INTO wa2_t_020. IF wa2_t_020-zsequencenumber = '00000000'. SELECT MAX( zsequencenumber ) FROM z1email INTO dt_zsequencenumber. dt_zsequencenumber = dt_zsequencenumber + 1. wa2_t_020-zsequencenumber = dt_zsequencenumber. wa2_t_020-zcustomerid = i_top-zcustomerid. ENDIF. MODIFY z1email FROM wa2_t_020. ENDLOOP. ENDFUNCTION.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 16

Mobile offline application development: a complete guide using Mobile Infrastructure tools

DELETE BAPIWRAPPER SAMPLE CODING:


FUNCTION ZSAMPLE_DELETE. *"-------------------------------------------------------------------*"*"Global Interface: *" IMPORTING *" VALUE(I_ZCUSTOMERID) TYPE Z1CUSTOMER-ZCUSTOMERID *" TABLES *" RETURN STRUCTURE BAPIRET2 *"-------------------------------------------------------------------DATA: it_z1customer TYPE TABLE OF z1customer, wa_it_z1customer LIKE LINE OF it_z1customer. DATA: it_z1customeradd TYPE TABLE OF z1customeradd, wa_it_z1customeradd LIKE LINE OF it_z1customeradd. DATA: it_z1email TYPE TABLE OF z1email, wa_it_z1email LIKE LINE OF it_z1email. DATA: lds_return LIKE bapireturn1, gdf_message_dummy type string .

SELECT * FROM z1customer INTO CORRESPONDING FIELDS OF TABLE it_z1customer WHERE zcustomerid = i_zcustomerid. LOOP AT it_z1customer INTO wa_it_z1customer. ENDLOOP. IF sy-subrc = 0. DELETE z1customer FROM wa_it_z1customer. ENDIF. SELECT * FROM z1customeradd INTO CORRESPONDING FIELDS OF TABLE it_z1customeradd WHERE zcustomerid = i_zcustomerid. LOOP AT it_z1customeradd INTO wa_it_z1customeradd. DELETE z1customeradd FROM wa_it_z1customeradd. ENDLOOP. SELECT * FROM z1email INTO CORRESPONDING FIELDS OF TABLE it_z1email WHERE zcustomerid = i_zcustomerid. LOOP AT it_z1email INTO wa_it_z1email. DELETE z1email FROM wa_it_z1email. ENDLOOP. ENDFUNCTION.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 17

Mobile offline application development: a complete guide using Mobile Infrastructure tools

SYNCBO DESIGN:
Now BAPI Wrappers are created in backend. Now we have to design the syncbos in middleware. Syncbos are used to define the data exchange between client and server. Logon to Middleware system and goto MEREP_SBUILDER and provide with the Syncbo ID which has to be created

And press create incon.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 18

Mobile offline application development: a complete guide using Mobile Infrastructure tools

And select the syncbo type (Here T01-Timed two way has been selected).

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 19

Mobile offline application development: a complete guide using Mobile Infrastructure tools

If BAPI Wrappers reside in the same system where syncbos are been created then select Default RFC destination. Otherwise select Syncbo specific and provide with RFC destination of the backend system. (In this example application BAPIs reside in the same system) Press enter.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 20

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Fill in all the details. (Getlist and Getdetail are mandatory). Press on the mapping screen on the top left corner. This will take you to the mapping screen as below.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 21

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Double clieck on the tables tab of ZSAMPLE_GETLIST BAPI Wrapper.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 22

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Map the fields which should be visible to the client and save. Come back to the mapping screen and double click on tables tab of ZSAMPLE_GETDETAIL BAPI Wrapper

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 23

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Check the key field and also mapping fields. Similarly check the key field and map the fields for the z1email table also. Double click the tables tab of Create bapi wrapper and check the mapping fields and similarly for modify bapi wrapper also. Now save the syncbo and Generate the syncbo.(Ctrl + F3). Now autogenerated Synchronizer code will be generated which consists of REPLICATOR,UPLOAD,DOWNLOAD.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 24

Mobile offline application development: a complete guide using Mobile Infrastructure tools

CREATION OF MCD:
Goto transaction MI_MSD / MI_MCD and fill the details. Press create MCD.

Fill in all the details and select the created syncbo as shown below: Can select multiple syncbos also. Save the MCD.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 25

Mobile offline application development: a complete guide using Mobile Infrastructure tools

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 26

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Download of MeRep XML:


Goto transaction MEREP_SBUILDER Gotodownload Metadata XML.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 27

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Select the MCD which was created and press enter. MeRep XML is generated and downloaded on the desktop.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 28

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Furthur development with MeRep XML using NWDS:


Now this MeRep XML is used for futhur development from the client side using NWDS. Furthur steps on how to use MeRepXML has been explained step by step in the below published article. https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/mobile/Mobile%20Application%2 0Development%20using%20NWDS%20and%20Mobile%20Infrastructure.pdf

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 29

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Related Content:
BAPIWRAPPERS: http://media.sdn.sap.com/public/html/submitted_docs/MI/MDK_2.5/content/appdev/smartsync/bapi_wrapper_type s.html Syncbo Design and mapping http://media.sdn.sap.com/public/html/submitted_docs/MI/MDK_2.5/content/appdev/smartsync/defining_syncbo.ht ml

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 30

Mobile offline application development: a complete guide using Mobile Infrastructure tools

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 31

Mobile offline application development: a complete guide using Mobile Infrastructure tools

SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 32

You might also like