Building an SAP system connection environment using JCo to a PC that even Java beginners can do

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).

Premise

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

Construction procedure

1. JDK installation

1.1. JDK download

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. JDKInstall02.JPG

1.2. JDK installation

I installed it by referring to "[Even beginners can easily understand] How to install JDK for Windows". Run the downloaded installation file. JDKInstall03.JPG JDKInstall04.JPG JDKInstall05.JPG JDKInstall06.JPG

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. JDKInstall11.JPG

Add the new path to the system environment variable Path. JDKInstall12.JPG JDKInstall13.JPG

Enter the path in the installed JDK. Please note that the path differs depending on the installed version. JDKInstall14.JPG

Also create a new system environment variable JAVA_HOME. JDKInstall15.JPG

Add the same path that you added to Path. JDKInstall16.JPG

1.4. Installation confirmation (version display)

Check if it is installed correctly from the command line. Display the installed Java version with the following command.

java -version

JDKInstall20.JPG

1.5. Installation confirmation (compilation and execution)

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.

1.5.1. Creating and coding folders

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!");
  }
}

1.5.2. Compile

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.

1.5.3. Java execution

By executing the following command in this state, "Hello World" is output.

java sample

JDKInstall31.JPG

2. Install Visual Studio 2013 C / C ++ runtime libraries

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.

3. JCo installation

3.1. JCo Download

You can download JCo from SAP Connector Information. Click "64bit x86" in "Microsoft Windows and Windows Server". image.png

3.2. JCo deployment

Create a directory "SAPJCo" on the C drive of your local PC, unzip the downloaded file, and place it. JCOInstall22.JPG

3.3. JCo post-installation processing

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. JDKInstall11.JPG

Add the new path to the system environment variable Path. JDKInstall12.JPG JDKInstall13.JPG

Enter the path where you expanded the JCo file here. JCOInstall31.JPG

Also create a new system environment variable CLASS_PATH. JDKInstall15.JPG

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). JCOInstall32.JPG

3.4. Confirmation after installing JCo

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. JCOInstall41.JPG

3.5. SAP system communication confirmation using JCo

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

JCOInstall51.JPG

For Eclipse

When developing with Eclipse, enable JCo as follows. Right click on the project and select Properties. JCoInstall61.JPG

Click the "Add External JARs ..." button on the Libraries tab in Java Build Path. JCoInstall62.JPG

Select sapjco3.jar in Explorer and exit. JCoInstall63.JPG

Recommended Posts

Building an SAP system connection environment using JCo to a PC that even Java beginners can do
JSP + Eclipse + Jetty development environment construction that even Java beginners can do
[Even beginners can do it! ] How to create Java environment on Windows 10 (JDK14.0.1)
[Even beginners can do it! ] How to install Eclipse on Windows 10 (Java environment construction)
From building an AWS cloud environment to deploying a Spring Boot app (for beginners)
[For beginners] Until building a Web application development environment using Java on Mac OS
[Even beginners can do it! ] How to write Javadoc
Try to build a Java development environment using Docker
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
Docker × Java Building a development environment that is too simple
Introduction to Java that can be understood even with Krillin (Part 1)
I tried learning Java with a series that beginners can understand clearly
How to build a Ruby on Rails environment using Docker (for Docker beginners)