on 07-03-2015 7:32 AM
Dear Experts,
I am trying to run a java program for extracting data using IDoc from SAP. For this, i need to connect to the SAP server. For server connection, i have given the following parameters.
jco.server.connection_count=2
jco.server.gwhost=192.168.1.1
jco.server.progid=SAPSERVER
jco.server.gwserv=sapgw00
jco.server.repository_destination=ABAP_AS_WITH_POOL
But am getting the following errors.
com.sap.conn.jco.JCoException: (129) JCO_ERROR_SERVER_STARTUP: Server startup failed at Fri Jul 03 11:57:38 IST 2015.
This is caused by either a) erroneous server settings, b) the backend system has been shutdown, c) network problems. Will try next startup in 1 seconds.
Could not start server: Connect to SAP gateway failed
Connection parameters: PROGID="SAPSERVER" GWHOST=192.168.1.1 GWSERV=sapgw00
ERROR service '?' unknown
TIME Fri Jul 03 11:57:38 2015
RELEASE 721
COMPONENT NI (network interface)
VERSION 40
RC -3
DETAIL NiErrSet
COUNTER 2
ERROR service 'sapgw53' unknown
TIME Fri Jul 03 11:57:40 2015
RELEASE 721
COMPONENT NI (network interface)
VERSION 40
RC -3
MODULE nixxsl.cpp
LINE 184
DETAIL NiSrvLGetServNo: service name cached as unknown
COUNTER 3
Is it possible to use IDocs for data extraction from SAP system?
If so, Please share if you have any example program for extraction .
Thanks in advance.
Here is my sample code
package com.sapdata.IdocTest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Properties;
import com.sap.conn.idoc.IDocDocumentList;
import com.sap.conn.idoc.IDocXMLProcessor;
import com.sap.conn.idoc.jco.JCoIDoc;
import com.sap.conn.idoc.jco.JCoIDocHandler;
import com.sap.conn.idoc.jco.JCoIDocHandlerFactory;
import com.sap.conn.idoc.jco.JCoIDocServer;
import com.sap.conn.idoc.jco.JCoIDocServerContext;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.ext.ServerDataProvider;
import com.sap.conn.jco.server.DefaultServerHandlerFactory.FunctionHandlerFactory;
import com.sap.conn.jco.server.JCoServer;
import com.sap.conn.jco.server.JCoServerContext;
import com.sap.conn.jco.server.JCoServerContextInfo;
import com.sap.conn.jco.server.JCoServerErrorListener;
import com.sap.conn.jco.server.JCoServerExceptionListener;
import com.sap.conn.jco.server.JCoServerFactory;
import com.sap.conn.jco.server.JCoServerFunctionHandler;
import com.sap.conn.jco.server.JCoServerTIDHandler;
public class IDocServerExample {
public static void main(String[] a) {
try {
// See provided examples of configuration files MYSERVER.jcoServer and BCE.jcoDestination
JCoIDocServer server = JCoIDoc.getServer("SERVER");
server.setIDocHandlerFactory(new MyIDocHandlerFactory());
server.setTIDHandler(new MyTidHandler());
MyThrowableListener listener = new MyThrowableListener();
server.addServerErrorListener(listener);
server.addServerExceptionListener(listener);
server.setConnectionCount(1);
server.start();
} catch (Exception e) {
e.printStackTrace();
}
}
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static Properties serverConnectionProperties;
static {
serverConnectionProperties = new Properties();
serverConnectionProperties.setProperty(ServerDataProvider.JCO_GWHOST, "192.168.1.1");
serverConnectionProperties.setProperty(ServerDataProvider.JCO_GWSERV, "sapgw00");
serverConnectionProperties.setProperty(ServerDataProvider.JCO_PROGID, "SAPSERVER");
serverConnectionProperties.setProperty(ServerDataProvider.JCO_REP_DEST, "ABAP_AS_WITH_POOL");
serverConnectionProperties.setProperty(ServerDataProvider.JCO_CONNECTION_COUNT, "2");
createServerDataFile("MYSERVER", serverConnectionProperties);
}
static void createServerDataFile(String destinationName,
Properties connectProperties) {
File destCfg = new File(destinationName + ".jcoServer");
try {
FileOutputStream fos = new FileOutputStream(destCfg, false);
connectProperties.store(fos, "for tests only !");
fos.close();
} catch (Exception e) {
System.out.println(e);
throw new RuntimeException(
"Unable to create the destination files", e);
}
}
static Properties clientConnectProperties;
static {
clientConnectProperties= new Properties();
clientConnectProperties.setProperty(DestinationDataProvider.JCO_ASHOST,"192.168.1.1");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "00");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_USER,"SAPUSER");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_PASSWD,"SAPUSER");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_TYPE, "3");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_TRACE, "0");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_MSHOST, "SAPSERVER");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_R3NAME, "ECC");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_GROUP, "PUBLIC");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_REPOSITORY_DEST, "ECC");
createDestinationDataFile("ECC", clientConnectProperties);
clientConnectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
clientConnectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,"10");
createDestinationDataFile(DESTINATION_NAME2, clientConnectProperties);
}
static void createDestinationDataFile(String destinationName,
Properties connectProperties) {
File destCfg = new File(destinationName + ".jcoDestination");
try {
FileOutputStream fos = new FileOutputStream(destCfg, false);
connectProperties.store(fos, "for tests only !");
fos.close();
} catch (Exception e) {
System.out.println(e);
throw new RuntimeException(
"Unable to create the destination files", e);
}
}
static class MyIDocHandler implements JCoIDocHandler {
public void handleRequest(JCoServerContext serverCtx, IDocDocumentList idocList)
{
// The method is used to listen the SAP IDOC ports, idoc sent to the port, the method will be generated by
// the idoc xml file
FileOutputStream fos = null;
OutputStreamWriter osw = null;
try {
IDocXMLProcessor xmlProcessor = JCoIDoc.getIDocFactory().getIDocXMLProcessor();
// JCoIDoc.getIDocFactory When () getIDocXMLProcessor ();
fos = new FileOutputStream(serverCtx.getTID() + "_idoc.xml");
osw = new OutputStreamWriter(fos, "UTF8");
xmlProcessor.render(idocList, osw, IDocXMLProcessor.RENDER_WITH_TABS_AND_CRLF);
osw.flush();
} catch (Throwable thr) {
thr.printStackTrace();
} finally {
try {
if (osw != null)
osw.close();
if (fos != null)
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
static class MyIDocHandlerFactory implements JCoIDocHandlerFactory {
private JCoIDocHandler handler = new MyIDocHandler();
public JCoIDocHandler getIDocHandler(JCoIDocServerContext serverCtx) {
return handler;
}
}
static class MyThrowableListener implements JCoServerErrorListener, JCoServerExceptionListener {
public void serverErrorOccurred(JCoServer server, String connectionId, JCoServerContextInfo ctx, Error error) {
System.out.println(">>> Error occured on" + server.getProgramID() + "connection" + connectionId);
error.printStackTrace();
}
public void serverExceptionOccurred(JCoServer server, String connectionId, JCoServerContextInfo ctx,
Exception error) {
System.out.println(">>> Error occured on" + server.getProgramID() + "connection" + connectionId);
error.printStackTrace();
}
}
static class MyTidHandler implements JCoServerTIDHandler {
public boolean checkTID(JCoServerContext serverCtx, String tid) {
System.out.println("checkTID called for TID =" + tid);
return true;
}
public void confirmTID(JCoServerContext serverCtx, String tid) {
System.out.println("confirmTID called for TID =" + tid);
}
public void commit(JCoServerContext serverCtx, String tid) {
System.out.println("commit called for TID =" + tid);
}
public void rollback(JCoServerContext serverCtx, String tid) {
System.out.print("rollback called for TID =" + tid);
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Remya,
if you like to use the logical port name sapgw00, you need to make sure that its mapping is contained in /etc/services:
sapgw00 3300/tcp
Alternatively, you can specify the port directly in jco.server.gwserv, i.e. jco.server.gwserv=3300.
The rest of your question is too generic. Certainly, there exist scenarios, in which it makes sense to use IDocs as exchange format. But discussing this in this forum does not fit to its scope. You should ask very concrete questions in order to get concrete answers.
Best regards,
Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Remya,
I don't think that you are really getting the same error message when trying with gwserv=3300.
Please compare the error messages carefully.
And did you restart your JCo server program?
Besides, are you telling us that you are running an SAP gateway program on IP 192.168.1.1?
That is hard to believe...
Best regards,
Stefan
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.