下面是我在SAPB1中进行仓库移动的代码。根据文档,我应该使用对象67(SBOCOMConstants.booobjecttypes\u oStockTransfer文件)获取转库对象。但是当我使用它时,我得到了以下错误。这是类强制转换异常。我试图将Dispatch对象强制转换为stock transfer对象。
Reference Link1
Reference Link 2
编辑
:
好像com.sap.smb公司.sbo.wrapper.com.Dispatch是返回的默认对象。并且需要找到一种方法从中获取StockTransfer对象。
public void transfer(ICompany company) throws Exception {
System.out.println("---------->");
Object obj = company.getBusinessObject(SBOCOMConstants.BoObjectTypes_oStockTransfer);
System.out.println("class ------------> " + obj.getClass());
StockTransfer doc = (StockTransfer) obj;
doc.setFromWarehouse("RW-QC");
doc.setComments("Just trasfered let see!!!");
doc.setDocDate(new Date());
doc.setDocObjectCode(SBOCOMConstants.BoObjectTypes_oStockTransfer);
doc.getLines().setItemCode("M100001");
doc.getLines().setWarehouseCode("RW");
doc.getLines().setQuantity(1.0);
doc.getLines().add();
int ii = doc.add();
if (ii != 0){
SBOErrorMessage error = company.getLastError();
System.out.println(error.getErrorCode());
System.out.println(error.getErrorMessage());
} else {
SBOErrorMessage error = company.getLastError();
System.out.println(error.getErrorCode());
System.out.println(error.getErrorMessage());
}
}
---------->
class ------------> class com.sap.smb.sbo.wrapper.com.Dispatch
java.lang.ClassCastException: com.sap.smb.sbo.wrapper.com.Dispatch cannot be cast to com.sap.smb.sbo.api.StockTransfer
at tets.StockTransferLocal.transfer(StockTransferLocal.java:16)
at tets.SAPBusinessOneTutorialWH.main(SAPBusinessOneTutorialWH.java:72)