Installation of SAP JCo in HP UX
Environment
1.
Download
appropriate distribution package into an arbitrary directory
{sapjco-install-path}.
2.
Next,
change to the installation directory:
a.
cd
{sapjco-install-path} [return]
and extract the archive:
i.
gunzip
sapjco-hp*.tgz [return]
ii.
tar
xvf sapjco-hp*.tar [return]
3.
Then
add {sapjco-install-path} to the SHLIB_PATH environment variable.
a.
export
SHLIB_PATH=/usr/sap/{sapjco-install-path}
4.
Finally,
add {sapjco-install-path}/sapjco.jar to your CLASSPATH environment variable.
a.
export
CLASSPATH=/usr/sap/{sapjco-install-path}/sapjco.jar
Testing
the RFC call from SAP to Java
Java Side:
1.
Create
following program in java:
Basically
I was creating an OCR utility in sap for document/image scanning.
package ocr;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
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;
import com.sap.conn.jco.server.JCoServer;
import com.sap.conn.jco.server.JCoServerContext;
import com.sap.conn.jco.server.JCoServerFactory;
import com.sap.conn.jco.server.JCoServerFunctionHandler;
public class DefineJCoServer
{
static String SERVER_NAME1 = "SERVER";
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "sap host name");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "sysnr");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "client");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "sap_user_id");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "sap_user_passwd");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDataFile(DESTINATION_NAME1, "jcoDestination", connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDataFile(DESTINATION_NAME2, "jcoDestination", connectProperties);
Properties servertProperties = new Properties();
servertProperties.setProperty(ServerDataProvider.JCO_GWHOST, "gateway_host_address");
servertProperties.setProperty(ServerDataProvider.JCO_GWSERV, "sapgw+sysnr");
servertProperties.setProperty(ServerDataProvider.JCO_PROGID, "JCO_SERVER");
servertProperties.setProperty(ServerDataProvider.JCO_REP_DEST, "ABAP_AS_WITH_POOL");
servertProperties.setProperty(ServerDataProvider.JCO_CONNECTION_COUNT, "2");
createDataFile(SERVER_NAME1, "jcoServer", servertProperties);
}
static void createDataFile(String name, String suffix, Properties properties)
{
File cfg = new File(name+"."+suffix);
if(!cfg.exists())
{
try
{
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
}
}
}
static class OcrHandler implements JCoServerFunctionHandler
{
public void handleRequest(JCoServerContext serverCtx, JCoFunction function)
{
System.out.println("------------------Call from
SAP----------------------------------");
/*Ocr.setUp();
System.out.println("------------------OCR Setup
Complete----------------------------------");
Ocr ocr = new Ocr();
ocr.startEngine("eng",
Ocr.SPEED_FASTEST); // English
System.out.println("----OCR
Engine Started------");
String s = ocr.recognize(new File[]
{new File("test.png")},
Ocr.RECOGNIZE_TYPE_ALL,
Ocr.OUTPUT_FORMAT_PLAINTEXT); // PLAINTEXT | XML | PDF | RTF
System.out.println("Result:
" + s);
ocr.stopEngine();*/
}
}
static void startServer()
{
JCoServer server;
try
{
server = JCoServerFactory.getServer(SERVER_NAME1);
}
catch(JCoException ex)
{
throw new RuntimeException("Unable to create
the server " + SERVER_NAME1 + " because of " + ex.getMessage(), ex);
}
JCoServerFunctionHandler OcrHandler = new OcrHandler();
DefaultServerHandlerFactory.FunctionHandlerFactory factory = new
DefaultServerHandlerFactory.FunctionHandlerFactory();
factory.registerHandler("ZHR_OCR_CONVERSION", OcrHandler);
server.setCallHandlerFactory(factory);
server.start();
System.out.println("The program can be stoped using
<ctrl>+<c>");
}
public static void main(String[] a)
{
startServer();
}
}
Compile and Execute the
code.
Here java –d64 is used as
it should use java 64 bit environment.
2.
Create
an RFC
a.
Create
RFC in SAP side using tcode SM59
Here program id must be as
specified in Java program in the following code
servertProperties.setProperty(ServerDataProvider.JCO_PROGID, "JCO_SERVER");
b.
Test the
RFC connection
3.
Create
SAP Remote enabled function in SE37 tcode
Here
we have not written any code in function module and all the processing is
written in java side.
4.
Create
SAP test program and call the above created function in that test sap program
As
I was working on ocr so I passed url for ocr processing. Destination ‘JCORFC’
is the destination/RFC we created in SM59.
The
function call in the test program will pass the parameter values to Java function
handler and there you can write your own code for processing. And pass the
final result back to SAP by setting the export parameter values using JCo.
The
execution of the above sap program will simply write the console line:
This comment has been removed by the author.
ReplyDelete