Skip to Content
0
Former Member
Feb 01, 2013 at 10:34 AM

Calling SAP BAPI "BAPI_FLIGHT_GETLIST" from native Android application

39 Views

Hello experts,

I try to develop a simple native Android application that calls the SAP BAPI "BAPI_FLIGHT_GETLIST". I created the MBO and generated the Java Object API code. I tried the SUP tutorial (http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01734.0213/doc/html/title.html) and it was successfull. Afterwards I tried to simplify the code and adapt it to call my BAPI_FLIGHT_GETLIST MBO. However, it does not work for some reason. I debugged it several times but do not find the reason :-(

Do you have an idea whats wrong? A tutorial or working sample native Android applications that calls SAP BAPIs would also be very helpful. I saw already this discussion thread (http://scn.sap.com/thread/3195793). This did also not work :-(

My Generic List is always empty :-(

Here is my code:

------------------------------

package com.example.testandroid;

import android.app.Activity;

import android.app.ProgressDialog;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.TextView;

import com.sybase.collections.GenericList;

import com.sybase.mobile.Application;

import com.sybase.mobile.ConnectionProperties;

import com.sybase.mobile.RegistrationStatus;

import com.sybase.persistence.ConnectionProfile;

import com.sybase.persistence.LoginCredentials;

import com.sybase.persistence.Query;

import com.sybase.persistence.QueryResultSet;

import com.sybase.persistence.SynchronizationGroup;

import com.sybase.persistence.SynchronizeException;

import de.tum.sup.android.mbo.SAPFlights;

import de.tum.sup.android.mbo.SAPFlightsMBODB;

public class MainActivity extends Activity {

private static String username = "supAdmin";

private static String password = "secret";

private static String host = "my sup server address";

private static int port = 5001;

private static int sync_port = 2480;

private static int timeout = 60;

boolean initializationDone = false;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initializeApplication();

}

private void initializeApplication() {

Application app = Application.getInstance();

app.setApplicationIdentifier("SAPFlightsMBO");

app.setApplicationContext(MainActivity.this);

Thread dataThread = new Thread(new DataThread());

dataThread.start();

GenericList<SAPFlights> flights = SAPFlights.findAll();

Log.d("Flight Log", "Size " + flights.size());

}

public class DataThread implements Runnable {

public void run() {

try {

Application app = Application.getInstance();

SAPFlightsMBODB.setApplication(app);

ConnectionProperties connProps = app.getConnectionProperties();

LoginCredentials loginCredentials = new LoginCredentials(

username, password);

connProps.setLoginCredentials(loginCredentials);

connProps.setServerName(host);

connProps.setPortNumber(port);

if (app.getRegistrationStatus() != RegistrationStatus.REGISTERED) {

app.registerApplication(timeout);

} else

{

app.startConnection(timeout);

}

ConnectionProfile cp = SAPFlightsMBODB.getSynchronizationProfile();

cp.setServerName(host);

cp.setPortNumber(sync_port);

cp.setNetworkProtocol("http");

cp.setAsyncReplay(true);

cp.setDomainName("default");

cp.save();

if (!SAPFlightsMBODB.isSynchronized("default")) {

SAPFlightsMBODB.synchronize();

}

} catch (Exception e) {

Log.d("Flight Log", e.toString());

} finally {

initializationDone = true;

}

}

}

}