在java项目创建之后,把sapjco.jar导入项目.
package javaapplication1;
import com.sap.mw.jco.*;
class SAP
{
private JCO.Client mConnection;
private JCO.Repository mRepository;
private JCO.Structure stru;
private JCO.Function function;
private JCO.Table info_tab;
private IFunctionTemplate ft;
public SAP(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连接成功");
mRepository = new JCO.Repository("my_repository", mConnection);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
public void Print_Info(String pernr, String begda, String endda)
{
stru = null;
function = null;
info_tab = null;
ft = null;
try
{
ft = mRepository.getFunctionTemplate("Z_BAPI_GET_PERSONNEL_ACTION");
function = ft.getFunction();
if (function == null)
{
System.out.println(
"Can not found" + "Z_BAPI_GET_PERSONNEL_ACTION");
System.exit(1);
}
else
{
System.out.println("Found Z_BAPI_GET_PERSONNEL_ACTION\n");
}
info_tab = function.getTableParameterList().getTable("PER_INFO");
function.getImportParameterList().getStructure("PERNR").setValue(pernr,"PERNR");
function.getImportParameterList().getStructure("TIME").setValue(begda,"BEGDA");
function.getImportParameterList().getStructure("TIME").setValue(endda,"ENDDA");
mConnection.execute(function);
for (int i = 0; i < info_tab.getNumRows();i++)
{
info_tab.setRow(i);
System.out.println(info_tab.getString("PERNR"));
System.out.println(info_tab.getString("BEGDA"));
System.out.println(info_tab.getString("ENDDA"));
System.out.println(info_tab.getString("ACTION"));
System.out.println("***************");
}
}
catch (Exception ex)
{
ex.printStackTrace();
System.exit(1);
}
}
}
class MainClass
{
public static void main (String str[])
{
SAP app = new SAP("800", "DEV0008", "123456", "E", "10.60.203.100", "01");
app.Print_Info("1000", "19110101", "20100101");
}
}
阅读(1967) | 评论(0) | 转发(0) |