cancel
Showing results for 
Search instead for 
Did you mean: 

Executing BAPI

Former Member
0 Kudos

our java code was able to login to SAP client however when executing BAPI, we encountered this error message:

error message: null

Error: , error message: null

java.lang.NullPointerException

Any advice ?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

error came from bapi.

Former Member
0 Kudos

Hai ,

Check once when you are giving exact input parameters to that bapi.

had you check this check list

--> Configure the connection

--> Creating the Repository

--> Setting Input Parameters to BAPI

--> Executing the BAPI

--> Capture the output.

Can you paste your code for reference

regards,

Former Member
0 Kudos

import java.util.*;

import com.sap.mw.jco.*;

public class HR_ZBAPI_1

{

static private String TEST_FNAME = "ZBAPI_1";

static private String TEST_EMPLOYEENUMBER = "001";

static private Calendar TEST_PRINTDATE = new GregorianCalendar(2006, Calendar.NOVEMBER, 25);

private JCO.Client mConnection;

private JCO.Repository mRepository;

public HR_ZBAPI_1()

{

;

Former Member
0 Kudos

Where's the rest of the code that is really setting up the JCo connection and making the BAPI call?

PS. use the Code tag in your post for proper formatting of the code.

Message was edited by:

Pascal Willemsen

Former Member
0 Kudos

Hi sorry, heres the full code,

many thanks in advance.

import java.util.*;
import com.sap.mw.jco.*;

public class HR_ZBAPI_1
{
  static private String TEST_FNAME = "ZBAPI_1"; 
  static private String TEST_EMPLOYEENUMBER = "001";
  static private Calendar TEST_PRINTDATE = new GregorianCalendar(2006, Calendar.NOVEMBER, 25);
  
  private JCO.Client mConnection;
  private JCO.Repository mRepository;
  
  
  public HR_ZBAPI_1() 
  {
    ;
  }
  
  
  public HR_ZBAPI_1(JCO.Client mConnection, JCO.Repository mRepository)  
  {
    this.mConnection = mConnection;
    this.mRepository = mRepository;     
  }
  
  private String executeFunction(String name) throws Exception
  {
    JCO.Function function = null;
           
    try 
    {
      function = this.createFunction(name);
                       
      function.getImportParameterList().setValue(TEST_EMPLOYEENUMBER, "EMPLOYEENUMBER");
            
      Date printDt = TEST_PRINTDATE.getTime();
      function.getImportParameterList().setValue(printDt, "PRINTDATE");
      
      mConnection.execute(function);
      
      JCO.Structure returnStructure = function.getExportParameterList().getStructure("RETURN");
      
      if(! ( returnStructure.getString("TYPE").equals("") || 
            returnStructure.getString("TYPE").equals("S") ) //||
            //returnStructure.getString("TYPE").equals("W") ) 
            )
      {
        System.out.println("Return Type: " + returnStructure.getString("TYPE"));
        System.out.println("Return Message: " + returnStructure.getString("MESSAGE")); 
        return returnStructure.getString("MESSAGE");
      } 
      
      JCO.Table tab = function.getTableParameterList().getTable("ZRESULT");
            
      return "";
      
    }
    catch (Exception ex) 
    { 
      System.out.println("Execute bapi function error: " + name + ", error message: " + ex.getMessage());
      throw ex;
    }
  }
  
  private JCO.Function createFunction(String name) throws Exception 
  {
    try 
    {
      IFunctionTemplate ft = mRepository.getFunctionTemplate(name.toUpperCase());
              
      return ft.getFunction();
    }
    catch (Exception ex) 
    {            
      System.out.println("Create bapi function error: " + name + ", error message: " + ex.getMessage());
      throw ex;
    }
  }
  
  public static void main (String args[]) 
  {
    JCO.Client mConnection;
    JCO.Repository mRepository;
    String errMessage = null;
    
    try 
    {
      mConnection =
      JCO.createClient("", // SAP client
      "",           // userid
      "",               // password
      """,                 // language
      "",         // application server host name
      "");                // system number
      
      mConnection.connect();
      mRepository = new JCO.Repository("1", mConnection);
      
      HR_ZBAPI_1 zbapi1 = new HR_ZBAPI_1(mConnection, mRepository);
      
      errMessage = zbapi1.executeFunction(TEST_FNAME);
      mConnection.disconnect();
      
      System.out.println("Main: " + errMessage);
      
    }
    catch (Exception ex) {
      System.out.println("Error: " + ", error message: " + ex.getMessage());
      ex.printStackTrace();
      System.exit(1);
    }
    finally
    {
      mConnection = null;
      mRepository = null;
    }
     
  }
}

former_member182294
Active Contributor
0 Kudos

Hi,

Can you add printStackTrace() in each of your methods before <b>throw</b> statement. Please post the stack trace.

Regards

Abhilash