使用 sapb1 jco 的库存转移出现错误

Stock transfer using sapb1 jco getting error

以下是我在 SAPB1 中执行仓库移动的代码。根据文档,我应该使用对象 67(SBOCOMConstants.BoObjectTypes_oStockTransfer) 来获取 Stock transfer 对象。但是当我使用它时,出现以下错误。它是一个 class 转换异常。我正在尝试将 Dispatch 对象转换为库存转移对象。

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)

终于解决了这个问题。 我获取 Stocktrasnfer 文档的方式是错误的

    IStockTransfer doc = SBOCOMUtil.newStockTransfer(company);
    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().setFromWarehouseCode("RW-QC");
    doc.getLines().setQuantity(1.0);
    doc.getLines().getBatchNumbers().setBatchNumber("BTCH0001");
    doc.getLines().getBatchNumbers().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());
    }