Skip to Content
0
Former Member
Jul 28, 2006 at 09:29 AM

JCO disconnection

152 Views

For connecting to SAP system using java,

_____________________________________________________________________________________

import java.io.*;

import java.sql.*;

import java.util.*;

import java.lang.Object.*;

import java.io.*;

import com.sap.mw.jco.*;

import com.sap.mw.jco.JCO.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class appjco2 extends HttpServlet

{

private JCO.Client client = null;

static final String SID = "R3";

IRepository repository;

JCO.Pool pool = JCO.getClientPoolManager().getPool(SID);

public void init(ServletConfig conf) throws ServletException

{

super.init(conf);

try{JCO.addClientPool( SID, // Alias for this pool

3, // Max. number of connections

"555", // SAP client

"JYOTI", // userid

"ABAP", // password

"EN", // language

"10.72.24.62", // host name

"00" );

repository = JCO.createRepository("MY11", SID);

}catch(JCO.Exception e){}

}

public void doGet (

HttpServletRequest request,

HttpServletResponse response

) throws ServletException, IOException

{

try{

// Retrieves and prints information about the remote system

PrintWriter out = response.getWriter();

// Get a function template from the repository

IFunctionTemplate ftemplate = repository.getFunctionTemplate("ZRFC_UPDATE_PERDATA1");

// if the function definition was found in backend system

if(ftemplate != null) {

// Create a function from the template

JCO.Function function = ftemplate.getFunction();

// Get a client from the pool

JCO.Client client = JCO.getClient(SID);

String sno;

String begda1;

String endda1;

String awart;

String sub;

String s;

sno = request.getParameter("sno") ;

begda1 = request.getParameter("begda1") ;

endda1 = request.getParameter("endda1") ;

awart = request.getParameter("awart") ;

sub = request.getParameter("sub") ;

System.out.println(sub);

String year1 = begda1.substring(6,10) ;

String month1 = begda1.substring(3,5) ;

String dd1 = begda1.substring(0,2) ;

String begda = year1month1dd1;

String year2 = endda1.substring(6,10) ;

String month2 = endda1.substring(3,5) ;

String dd2 = endda1.substring(0,2) ;

String endda = year2month2dd2;

if ( (begda!= null) && (endda!=null) && (awart!=null)){

function.getImportParameterList().setValue(sno,"PERNR");

function.getImportParameterList().setValue(begda,"BEGDA");

function.getImportParameterList().setValue(endda,"ENDDA");

function.getImportParameterList().setValue(awart,"AWART");

client.execute(function) ;

// The export parameter

String sys = function.getExportParameterList().getString("SYS1");

s = function.getExportParameterList().getString("STATUS1");

String s1 = function.getExportParameterList().getString("STATUS_20011");

String error = function.getExportParameterList().getString("ERROR");

// String p1 = function.getExportParameterList().getString("STATUS_20011");

JCO.Table codes_u = function.getTableParameterList().getTable("TA_PA0002");

JCO.Table codes = function.getTableParameterList().getTable("MESSTAB");

String surname = codes_u.getString("NACHN");

String fname = codes_u.getString("VORNA");

System.out.println("appjco-----");

System.out.println(s);

if ( s != "1"){

response.setContentType("text/plain");

response.setHeader("Stat",s);

response.setHeader("SurName",surname);

response.setHeader("FirstName",fname);

response.setHeader("begda",begda1);

response.setHeader("Stat1",s1);

// response.setHeader("Statp",p1);

response.setHeader("Error",error);

System.out.println(error);

}else{

System.out.println(error);

response.setHeader("Stat1",s1);

response.setHeader("Error",error);

System.out.println(client);

}

// Release the client into the pool

// do not forget to close the client connection

}

}

}

catch (NullPointerException e) {}

finally {

try{

if( client != null){

JCO.removeClientPool(SID);

JCO.releaseClient(client);

}

}catch(JCO.Exception ex){}

}}

public void destroy()

{

client.reset();

client.disconnect();

}

}

____________________________________________________________________________________

1) Using JCO, called function 'ZRFC_UPDATE_PERDATA1' to update abseneces in SAP system

through webpage.

2) If there is no error in updation, web page (servlet) run properly.

But if there is error in updation, same page behaves abruptly.

3) Evenif I closed the RFC connection using java, in sap system it shows live.

Please give some suggestions.