JAVA connects SAP example via JCO __java

Source: Internet
Author: User

1. Put the Librfc32.dll,sapjcorfc.dll on the server's system C:\Windows\System32

(Otherwise it will be an error: SAP Field it_tablnot a member of TABLES) 2. Download Sap.jar;sapjco.jar;sappool.jar Add to Java application.
3. The following class of code can check the material data

Import com.sap.mw.jco.*;
Import com.sap.mw.jco.JCO.Function;
Class Sapserver extends JCO. Server
{

Public Sapserver (JCO. Repository repo)
{
Super ("10.10.10.50", "sapgw00", "ABC", repo);
}
}
Class Saplogon
{
Public JCO. Client mconnection;
Public JCO. Repository mrepository;
Public Saplogon (String client, string userid, string password, string language,
String IP, String system_number)
{
try {

Mconnection = jco.createclient (client,
Userid
Password
Language
Ip
System_number);
Mconnection.connect ();
Mrepository = new JCO. Repository ("Lee", mconnection);
SYSTEM.OUT.PRINTLN ("SAP connection succeeded");
Calling the RFC function
Ifunctiontemplate ft = mrepository.getfunctiontemplate ("Bapi_material_get_detail");
JCO. Function f = ft.getfunction ();

1. Incoming parameter is field
F.getimportparameterlist (). SetValue ("931029BA", "MATERIAL");
F.getimportparameterlist (). SetValue ("1000", "Plant");
Mconnection.execute (f);
1. return parameter to Field
JCO. Structure struct = F.getexportparameterlist (). Getstructure ("Material_general_data");
String name = struct.getstring ("Matl_desc");
System.out.println ("Item Name:" +name);
String Matl_type = struct.getstring ("Matl_type");
System.out.println ("Type of item:" +matl_type);


Mrepository = new JCO. Repository ("My_repository", mconnection);
Mconnection.disconnect ();
catch (Exception ex) {
Ex.printstacktrace ();
System.exit (1);

}

}

}
public class Main {

public static void Main (string[] args) {
Saplogon MySAP = new Saplogon ("A", "userid", "passwork", "en", "21.4.13.2", "00");
Sapserver myServer = new Sapserver (mysap.mrepository);
Myserver.start ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.