Procedures for setting up JCo and checking Logs

JCo is a middleware library used to connect SAP systems with Java applications. It helps Java applications retrieve data from SAP systems.

Introduction

This post explains how to set up a JCo (Java Connector) connection to SAP and how to check the connection logs.

It also shows the property values used to configure JCo, including details like client, user, password, and function name.

Procedures

How to Set Up JCo

  1. You can download the SAP Java Connector at the following link: https://support.sap.com/en/product/connectors/jco.html?anchorId=section_2129803369
  2. If you extract the downloaded folder, you will find Java library files such as sapjco3.jar and sapjco3.dll. These files need to be placed in the same directory.
    • sapjco3.jar (Java Library file)
    • sapjco3.dll (Windows native library)
  3. Make sure JDK is installed on your system to compile Java source files. If not, follow this link: https://www.oracle.com/kr/java/technologies/downloads/#jdk25-windows

Create and compile a Java source file.

Use Windows Notepad to create a Java source file, for example, SAPTest.java. Make sure to place this file in the same directory as the previously mentioned one.

When the source file has been compiled, the class file and the JCoDestination file are created.

Copy the Java Source file.
import com.sap.conn.jco.*;
import java.io.*;
import java.util.Properties;

public class SAPTest {
    public static void main(String[] args) {
        try {
            
            Properties props = new Properties();
            props.setProperty("jco.client.ashost", "172.XX.XX.XX");     
            props.setProperty("jco.client.sysnr",  "00");                
            props.setProperty("jco.client.client", "100");               
            props.setProperty("jco.client.user",   "JCOUSER");           
            props.setProperty("jco.client.passwd", "JCOPASSWORD");           
            props.setProperty("jco.client.lang",   "EN");                

            
            String DEST = "MY_SAP_DEST";
            File destFile = new File(DEST + ".jcoDestination");
            try (FileOutputStream fos = new FileOutputStream(destFile)) {
                props.store(fos, "SAP Connection");
            }

            
            JCoDestination destination = JCoDestinationManager.getDestination(DEST);
            System.out.println("SAP 연결 성공!");

            
            JCoFunction function = destination.getRepository().getFunction("RFC_READ_TABLE");
            function.getImportParameterList().setValue("QUERY_TABLE", "SCARR"); 
	function.getImportParameterList().setValue("ROWCOUNT", 5);


            function.execute(destination);

            JCoTable data = function.getTableParameterList().getTable("DATA");

            
            for (int i = 0; i < data.getNumRows(); i++) {
                data.setRow(i);
                System.out.println(data.getString("WA"));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Compile Source file “SAPTest.java”
javac -cp "sapjco3.jar" SAPTest.java
Run the Java class file
java -cp ".;sapjco3.jar" SAPTest

Result of calling a function from JCo

If you execute the Java class file, you will see the results, which are received from the SAP system.

Verify the table in your source SAP system which you queried.

Check the connection log file.

1. Check with STAD. You will see the IP address, port and function name that were executed via JCo.

2. Verify with SMGW(dev_rd). If there are no logs related to JCo, increase the gateway trace level.

You can see the IPs and ports as shown below. JCo uses port 33XX (e.g., 3300 for instance number 00), which is the SAP Gateway port used to establish the connection.

3. Trace the JCo connection user with ST05 or ST01

It also shows IPs, ports and JCo programs.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top