The author, who has never used Java, built a Java environment including JCo (SAP Java Connector) to connect to the SAP system. This is the procedure at that time. It took about a day to build, but it's faster if you know Java (it took a while because I was looking at the Java compilation procedure and grammar).
This article was first posted in December 2017, with JCo 3.0.17 being the latest. Some information has been updated. The JCo used is the latest 3.1.2 as of May 2020. ~~ JCo3.0.17 does not support Java 9, so the environment is built with Java 8. The SAP recommendation is the SAP JVM, but this time I chose the Oracle JVM (because it was a hassle to download and unzip from the SAP site). ~~ It is built in Windows10 64-bit environment.
Be sure to check the following information in advance. All require SAP Support Portal authentication.
Source of information | Contents |
---|---|
SAP Connector Information | ThelatestinformationaboutSAPconnectors *Sometimestheremaybemistakes,sopleaserefertothelinkednotes.(Thenoteiscorrect) |
Note 2786882 "SAP JCo 3.1 release and support strategy」 | JCo3.Latest information about 1 |
Various notes and KBA | component"BC-MID-CON-JCO"Check in advance for any information to keep in mind about JCo |
Download the JDK from the Java SE Download Page (http://www.oracle.com/technetwork/java/javase/downloads/index.html). It's not the latest Java 9, so scroll down a bit.
Accept the license terms and download for Windows x64.
I installed it by referring to "[Even beginners can easily understand] How to install JDK for Windows". Run the downloaded installation file.
Since the environment is Windows, enter "sysdm.cpl" with the Windows button + R (Run). Enter the environment variables in the advanced system settings.
Add the new path to the system environment variable Path.
Enter the path in the installed JDK. Please note that the path differs depending on the installed version.
Also create a new system environment variable JAVA_HOME.
Add the same path that you added to Path.
Check if it is installed correctly from the command line. Display the installed Java version with the following command.
java -version
Create your first Java program, compile and run it. Since it is a simple check, I am running it with a text editor instead of an IDE like Eclipse.
Create a "jsample" folder in the C drive and save the following code as "sample.java" with a text editor (the character code is S-JIS, but it is unconfirmed if it is possible with others).
sample.java
class sample{
public static void main(String args[]){
System.out.println("Hello World!");
}
}
At the command prompt, move the path to the "jsample" folder and execute the following command.
javac sample.java
A file called sample.class is created in the same folder.
By executing the following command in this state, "Hello World" is output.
java sample
The Windows environment requires something called Visual Studio 2005 C / C ++ runtime libraries. Details can be found in Note 2786882 “SAP JCo 3.1 release and support strategy”.
On Windows platforms, JCo 3.1 requires the Visual Studio 2013 C/C++ runtime libraries to be installed on the system. If not present, download and install the "Visual C++ 2013 Redistributable Package" from the Microsoft knowledge base article https://support.microsoft.com/en-us/help/4032938 and choose the package, which corresponds to the used Locale and JVM bit-width (x64 for 64-bit or x86 for 32-bit).
Since it is 64bit, download (in Japanese) the linked vcredist_x64.exe
and install it.
You can download JCo from SAP Connector Information. Click "64bit x86" in "Microsoft Windows and Windows Server".
Create a directory "SAPJCo" on the C drive of your local PC, unzip the downloaded file, and place it.
Similar to "1.3. Post-installation processing". Since the environment is Windows, enter "sysdm.cpl" with the Windows button + R (Run). Enter the environment variables in the advanced system settings.
Add the new path to the system environment variable Path.
Enter the path where you expanded the JCo file here.
Also create a new system environment variable CLASS_PATH.
Add the path created in "1.5.1. Folder Creation and Coding" and sapjco3.jar with a semicolon combination with the path (C: \ jsample; C: \ SAPJCo \ sapjco3.jar).
Enter the following at the command prompt to confirm the installation.
java -jar C:\SAPJCo\sapjco3.jar
If you see a screen like this, you are successful.
Finally, check the communication with the SAP system using JCo with the following code. Change the Host name and user password as appropriate, and save it in a text editor (IDE such as Eclipse is OK) with the file name "ConnectionTest.java". The location to put the file is the C drive "jsample" folder created in "1.5.1. Creating and coding folders".
ConnectionTest.java
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
public class ConnectionTest
{
static String ABAP_AS = "ABAP_AS_WITHOUT_POOL";
//SAP system information
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "xxxx"); //Enter the host name correctly
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "00");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "400");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "fukuhara");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "xxxx");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDataFile(ABAP_AS, "jcoDestination", connectProperties);
}
//Creating a file of SAP system information
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);
}
}
}
public static void main(String[] args) throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS);
System.out.println("Attributes:");
//SAP system communication
System.out.println(destination.getAttributes());
System.out.println();
}
}
Then execute Java compilation from the command prompt. And execute Java program. Acquires and displays system information by communicating with the SAP system via RFC.
javac ConnectionTest.java
java ConnectionTest
When developing with Eclipse, enable JCo as follows. Right click on the project and select Properties.
Click the "Add External JARs ..." button on the Libraries tab in Java Build Path.
Select sapjco3.jar in Explorer and exit.
Recommended Posts