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 ();
}
}