Error while creating sales order using JCO with BA

2019-09-09 00:58发布

问题:

I am trying to create a sales order using BAPI_SALESORDER_CREATEFROMDAT2 butI am getting error “No customer master record exists for customer 99” when I tried to create a sales order for customer 99(example) with the partner Role ‘AG’,’WE’ where both ‘sold-to-party and ship-to-party’ are mandatory fields. If I send “SP” it will ask me to define ‘sold-to-party and ship-to-party’ ,Please let me know if I have to send some different partner roles to be able to create a sales order.

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

        JCoStructure orderHeaderIn = functionCreateOrder.getImportParameterList().getStructure("ORDER_HEADER_IN");
        orderHeaderIn.setValue("SALES_ORG", "2000");
        orderHeaderIn.setValue("DISTR_CHAN", "20");
        orderHeaderIn.setValue("DIVISION", "20");
        orderHeaderIn.setValue("DOC_TYPE", "ZAR");

        JCoTable orderPartners = functionCreateOrder.getTableParameterList().getTable("ORDER_PARTNERS");
        // WE,AG,SP,PH
        // AG Sold to Party
        // WE Ship to Party
        orderPartners.appendRows(1);
        orderPartners.setValue("PARTN_ROLE", "AG");
        orderPartners.setValue("PARTN_NUMB", "99");
        orderPartners.appendRows(1);
        orderPartners.setValue("PARTN_ROLE", "WE");
        orderPartners.setValue("PARTN_NUMB", "99");
        System.out.println(orderPartners);

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

        JCoTable orderSchedulesIn = functionCreateOrder.getTableParameterList().getTable("ORDER_SCHEDULES_IN");
        orderSchedulesIn.appendRow();
        orderSchedulesIn.setValue("REQ_QTY", "1");
        System.out.println(orderSchedulesIn);

        functionCreateOrder.execute(destination);
        functionTransComit.execute(destination);

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

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

}

回答1:

Issue was with the partner number , adding 000000000 leading the partner number will solve the issue .



标签: sap bapi