0

I am trying to create a sales order using BAPI_SALESORDER_CREATEFROMDAT2 but I 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");
    }

}
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Naveen Rayappa
  • 119
  • 3
  • 17
  • I doubt that this question can be answered without access to your system and its data and settings... – vwegert Aug 21 '15 at 06:01
  • I am very new to this SAP and JCO . I just wanted to know is this the issue with the JAVA code I have written to create the sales order or is this the issue with the data I am passing . Because I have got the data from an SAP consultant and the person told he can create the sales order with the data He has shared . – Naveen Rayappa Aug 21 '15 at 06:11
  • 1
    If the error message is the one you mentioned above, I doubt that he can create a sales order with that data interactively. Does the customer 99 exist? Or do you need to specify leading zeroes (0000000099)? – vwegert Aug 21 '15 at 06:24

1 Answers1

0

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

Naveen Rayappa
  • 119
  • 3
  • 17