Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

java调用BAPI_GOODSMVT_CREATE进行采购订单收货

0 Kudos

我用java调用BAPI_GOODSMVT_CREATE进行采购订单收货,程序如下:

JCoFunction function1=destination.getRepository().getFunction("BAPI_GOODSMVT_CREATE");
JCoFunction function2 =destination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT");
JCoFunction function3 =destination.getRepository().getFunction("BAPI_TRANSACTION_ROLLBACK");//事务撤回

function2.getImportParameterList().setValue("WAIT", "X");

JCoStructure importStructure1=function1.getImportParameterList().getStructure("GOODSMVT_CODE");
importStructure1.setValue("GM_CODE", "01");

Date date=new Date();
date.setTime(date.getTime());
SimpleDateFormat sdf =new SimpleDateFormat("yyyyMMdd");
String nowDate1=sdf.format(date);
date.setTime(date.getTime());
String nowDate2=sdf.format(date);
JCoStructure importStructure2=function1.getImportParameterList().getStructure("GOODSMVT_HEADER");
importStructure2.setValue("PSTNG_DATE", nowDate2); //过帐时间应迟于凭证时间
importStructure2.setValue("DOC_DATE", nowDate1); //凭证时间

JCoTable importTable1 = function1.getTableParameterList().getTable("GOODSMVT_ITEM");
importTable1.appendRow();
importTable1.setValue("MATERIAL", "S109990587W");
importTable1.setValue("PLANT", "WTY1");
importTable1.setValue("PO_NUMBER", "4504804017");
importTable1.setValue("PO_ITEM","00070");
importTable1.setValue("ENTRY_QNT", "1");
importTable1.setValue("ENTRY_UOM", "EA");
importTable1.setValue("MOVE_TYPE", "101");
//importTable1.setValue("MVT_IND","B");
importTable1.setValue("STGE_LOC", "0023");

String result="";
try{
function1.execute(destination);
function1.getTableParameterList().getTable("RETURN").firstRow();

importTable1.firstRow();
System.out.println( importTable1);
if(!function1.getExportParameterList().getString("MATERIALDOCUMENT").equals("")){
function2.execute(destination);//在数据库中按凭证号进行过帐
if(!function2.getExportParameterList().getStructure("RETURN").getString("TYPE").equalsIgnoreCase("E")){
result="过帐成功,凭证号为:"+function1.getExportParameterList().getString("MATERIALDOCUMENT");
}else {
function3.execute(destination);//出错回滚
result="在数据库中按凭证号进行过帐时出错,未过帐,生成的凭证号在数据库中为空行";
}
}else{
function3.execute(destination);//出错回滚
function1.getTableParameterList().getTable("RETURN").firstRow();
result="未能生成凭证,原因为:"+function1.getTableParameterList().getTable("RETURN").getString("MESSAGE");
}
}catch(AbapException e){
System.out.println(e.toString());
result=e.toString();
}finally{
try{
JCoContext.end(destination);
}catch(JCoException e){
e.printStackTrace();
result=e.toString();
}
}
System.out.println(result);

运行后输出:

未能生成凭证,原因为:Update control of movement type is incorrect (entry 101 X X)

如果增加 如下设置

importTable1.setValue("MVT_IND","B");

程序运行出错:

Exception in thread "main" com.sap.conn.jco.JCoException: (104) JCO_ERROR_SYSTEM_FAILURE: Exception condition "AUTH_MISSSING" triggered (raised by system PRB|VPRBAP01) Message 310 of class 06 type E, Par[1]: 5301045265, Par[2]: WTY1, Par[3]: WTY1, Par[4]: 0

请各位大师指导

0 REPLIES 0