Skip to main content

SAP - Java Application Development with Jco3 Connection

This is the post to explain the way of achieve the connection between non SAP Web application interacting with SAP backend RFC's through Jco3 connector.

Mandatory Files:

* sapjco3.jar (place in lib folder)
* sapjco3.dll(required only windows based machine ,need to place under "C:\Windows\System32" folder.)

Required to download it from SAP market place with valid credentials,consider the version 32/64 bits depends on your work environment)


Steps to connect SAP Backend:

1. Create a Stand alone/web application using any development tool.
2. Include jar and dll files in above specified folder
3. Create a connection class to connect backend with valid credentials
4. Create a service or consumer class with RFC call code to utilise the connection
5. Close the connection

Make sure you have access and no firewall blocks for the SAP backend connection.


Example Connection Code:


sapConnect.java

import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoTable;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.ext.DestinationDataProvider;
import java.io.IOException;
import java.util.List;

public class sapConnect {

    static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";

    static {

        Properties connectProperties = new Properties();
        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "198.10.01.108");
        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "03");
        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "500");
        connectProperties.setProperty(DestinationDataProvider.JCO_USER, "solmanadmin");
        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "solmanpassword");
        connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
        createDestinationDataFile(DESTINATION_NAME1, connectProperties);
        connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "10");
        connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "100");

    }

    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 !");
            }
        } catch (IOException e) {
            throw new RuntimeException("Unable to create the destination files", e);
        }

    }

    public static void jcovalue(String ibase) throws JCoException {

        JCoTable tables = null;

        JCoDestination destination = CoDestinationManager.getDestination(DESTINATION_NAME1);

        JCoFunction jf = destination.getRepository().getFunction("ZSOLMAN_STATUS_COUNT");

        jf.getImportParameterList().setValue("PNO", ibase);

        jf.execute(destination);
        tables = jf.getTableParameterList().getTable("RESULT");
        System.out.println(tables.toString());
        
    }

    public static void main(String[] args) throws JCoException {
       jcovalue("349");
    }

}




Comments

Post a Comment

Popular posts from this blog

Maven vs Gradle

What is Gradle? Gradle Build Tool is a fast, dependable, and adaptable open-source build automation tool with an elegant and extensible declarative build language. Gradle is a widely used and mature tool with an active community and a strong developer ecosystem. •            Gradle is the most popular build system for the JVM and is the default system for Android and Kotlin Multi-Platform projects. It has a rich community plugin ecosystem. •            Gradle can automate a wide range of software build scenarios using either its built-in functionality, third-party plugins, or custom build logic. •            Gradle provides a high-level, declarative, and expressive build language that makes it easy to read and write build logic. •            Gradle is fast, scalable, and can bui...

JSF2 with Mysql CRUD Web Application Demo

Java based CRUD demo application development with the combination of JSF2 framework ,Mysql database using Netbean IDE. Beginners can  understand initial configuration steps in JSF2  application development. Steps Followed: *  Install MySql Server with proper configuration and create some table with set of records or restore from your backup ,If you have anything. *  Download mySql Connector Drivers from official site. *  Install Netbean IDE with Server either Tomcat or Glassfish *  Create New Web Application and select the server and Framework (JSF2 used for this demo with Primefaces ). * Select the JPA framework to create a datasource connection and it will generate the the DAO and service classes based on Facade Design pattern. * Create JSF managed beans and Xhtml pages from the Pojo's (It's an automated process when you follow the video). * This video will help to understand the basic connection between frontend DAO's and business log...