on 07-28-2006 10:29 AM
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.
Hi everybody,
Thanks for reply.
I tried all th options which you have given.But still there is problem.
I want to clear one thing here.
Configuration for web server is as follows:
I am using servletrunner in background.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to handle the JCO exception and the function return information. If the function return information indicates there is an error call bapi_rollback. If the function was successful call bapi_commit, that is of course assuming your bapi supports external uow setting and does not autocommit.
Enjoy
Hi,
1) Using JCO, called function 'ZRFC_UPDATE_PERDATA1' to update abseneces in SAP system through webpage.
Make Sure all the Import Parameters are contains non empty (and not null)values for all of the non optional field.
2) If there is no error in updation, web page (servlet) run properly.But if there is error in updation, same page behaves abruptly.
Make the program to behave normal if it also caught in error.Handle it in the catch part.
try{
}catch(Exception e){
out.println("Do The rest");
}
3) Evenif I closed the RFC connection using java, in sap system it shows live.
in finally
if(client.isAlive()){
client.disconnect();
JCO.releaseClient(client);
}
Kind Regards
Mukesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I moved the topic to Java, as it is not .NET...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This was the same problem even I had faced with a minor difference. I was not updating anything.
Here are few suggesstions:
1. Pad up values with zeros before inserting.
2. Check to see connections opening/closing in the program.If u still find connections open, try restarting the server.It will close all existing open connections.
3. Use client pool for JCO Connection.
regds,
Sukanta Rudra
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.