无法从JCO创建销售订单

时间:2015-08-26 10:18:10

标签: sap jco bapi

我使用以下代码调用BAPI BAPI_SALESORDER_CREATEFROMDAT2来创建销售订单。 SAP机器正在生成SO号并作为响应发送,但是当我用va03检查我收到的SO号时,销售订单没有创建。 如果我手动使用具有相同数据的va01,我可以成功创建销售订单。请大家帮忙。

public static void createSalesOrder() {
    try {
        JCoDestination destination = JCoDestinationManager.getDestination("ABAP_AS_WITH_POOL");
        JCoFunction functionCreateOrder = destination.getRepository().getFunction("BAPI_SALESORDER_CREATEFROMDAT2");
        //this is the bapi 
        JCoFunction functionTransComit = destination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT");

        JCoStructure orderHeaderIn = functionCreateOrder.getImportParameterList().getStructure("ORDER_HEADER_IN");
        orderHeaderIn.setValue("SALES_ORG", "2000");//sales organisation
        orderHeaderIn.setValue("DISTR_CHAN", "20");//distribution channel
        orderHeaderIn.setValue("DIVISION", "20");// sales division 
        orderHeaderIn.setValue("DOC_TYPE", "ZAR");// document type 
        orderHeaderIn.setValue("PURCH_NO_C", "TEST123");


        JCoTable orderPartners = functionCreateOrder.getTableParameterList().getTable("ORDER_PARTNERS");
        // WE,AG,SP,PH
        // AG Sold to Party
        // WE Ship to Partyx
        orderPartners.appendRow();
        orderPartners.setValue("PARTN_ROLE", "AG");//partner role ag is sold to party 
        orderPartners.setValue("PARTN_NUMB", "0000000035");// partner number 
        orderPartners.appendRow();
        orderPartners.setValue("PARTN_ROLE", "WE");//we is ship tp party 
        orderPartners.setValue("PARTN_NUMB", "0000000035");// partner number 
        System.out.println(orderPartners);

        JCoTable orderItemsIn = functionCreateOrder.getTableParameterList().getTable("ORDER_ITEMS_IN");
        orderItemsIn.appendRow();
        orderItemsIn.setValue("MATERIAL", "PEN_ARN");// material 
        System.out.println(orderItemsIn);

        JCoTable orderSchedulesIn = functionCreateOrder.getTableParameterList().getTable("ORDER_SCHEDULES_IN");
        orderSchedulesIn.appendRow();
        orderSchedulesIn.setValue("REQ_QTY", "10");// required quantity 
        System.out.println(orderSchedulesIn);

        functionCreateOrder.execute(destination);


        // System.out.println(functionCreateOrder);
        JCoTable returnTable = functionCreateOrder.getTableParameterList().getTable("RETURN");
        System.out.println(returnTable);
        System.out.println(returnTable.getString("MESSAGE"));
        System.out.println("sales order number is : "
                + functionCreateOrder.getExportParameterList().getValue("SALESDOCUMENT"));
        functionTransComit.execute(destination);

    } catch (JCoException ex) {
        System.out.println(ex.getMessage());
    } finally {
        System.out.println("Creating sales order ends");
    }

}

1 个答案:

答案 0 :(得分:0)

这取决于您的JCo版本,但至少使用 JCo 3 ,您需要在与BAPI_TRANSACTION_COMMIT的函数调用相同的上下文中执行对BAPI_SALESORDER_CREATEFROMDAT2的调用。目前,两个调用都是在各个上下文中执行的,因此对BAPI_TRANSACTION_COMMIT的第二次调用并没有真正提交任何内容。您必须先创建一个上下文:

JCoContext.begin(destination);

// execute both function calls to 
// BAPI_SALESORDER_CREATEFROMDAT2 and
// BAPI_TRANSACTION_COMMIT

JCoContext.end(destination);