-1

I am trying to create a Purchase Order using JCo3. I am able to execute my function without any error but I am not sure what's wrong, system is not throwing any error and it's not creating PO also in the SAP system.

JCoDestination destination = JCoDestinationManager.getDestination("ABAP_AS_WITHOUT_POOL");

JCoFunction createPurchaseOrderFunction  = destination.getRepository().getFunction("BAPI_PO_CREATE1");
JCoFunction functionTransactionCommit = destination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT");

// Input Header 
JCoStructure poOrderHeader = createPurchaseOrderFunction.getImportParameterList().getStructure("POHEADER");
System.out.println("Header Structure" + poOrderHeader);

poOrderHeader.setValue("COMP_CODE", "0001");
poOrderHeader.setValue("DOC_TYPE", "NB");

//Date today = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
//String date = dateFormat.format(today);
String dateinString = "20.08.2015";
Date date = dateFormat.parse(dateinString);
System.out.println("Date is: " + date);

poOrderHeader.setValue("CREAT_DATE",date);
poOrderHeader.setValue("VENDOR", "V544100170");
poOrderHeader.setValue("LANGU", "EN");
poOrderHeader.setValue("PURCH_ORG", "0005");
poOrderHeader.setValue("PUR_GROUP", "001");
poOrderHeader.setValue("CURRENCY", "INR");

// PO Items
    JCoTable poItems = createPurchaseOrderFunction.getTableParameterList().getTable("POITEM");
    poItems.appendRow();
    poItems.setValue("PO_ITEM", "1");
    poItems.setValue("MATERIAL", "ZZMT_TEST2");
    poItems.setValue("PLANT", "Z111");
    poItems.setValue("QUANTITY", "100");
    poItems.setValue("NET_PRICE", "150");
    
    try
    {
        JCoContext.begin(destination);
        createPurchaseOrderFunction.execute(destination);
        functionTransactionCommit.execute(destination);
        functionTransactionCommit.getImportParameterList().setValue("WAIT", 10);
        JCoContext.end(destination);
    }
    catch(Exception e)
    {
        throw e;
    }
    
// Print the Return Structure Message
//      JCoStructure returnStructure = createPurchaseOrderFunction.getExportParameterList().getStructure("RETURN");
//      if (! (returnStructure.getString("TYPE").equals("")||returnStructure.getString("TYPE").equals("S"))  )   
//        {
//           throw new RuntimeException(returnStructure.getString("MESSAGE"));
//        }

JCoTable table = createPurchaseOrderFunction.getTableParameterList().getTable("POITEM");

// Iterate over table and print JCOFiled
for(JCoField field : table)
{
    System.out.println("Name: "+field.getName() +  "----" + "Value:" + field.getValue());
    System.out.println("------------------------------------------------------------------");
}
            
System.out.println("---------------------------------------------------------------------------------");
System.out.println("Table" + table);
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Utsav
  • 1,593
  • 4
  • 22
  • 46
  • 1
    I see your display of the `RETURN` table is disabled. When you say "isn't throwing any error" do you mean "isn't throwing an exception" or "isn't returning an error in `RETURN`"? If there is an error you won't get an exception, you'll get an error message in the `RETURN` parameter (it will have a `TYPE` of `E`). **Note:** you should also check for errors in `RETURN` *before* committing. If checking that table still doesn't help, trying calling the BAPI from `SE37` using exactly the same parameters. – mjturner Aug 21 '15 at 07:13
  • after uncommenting return statement line i am getting following error Exception in thread "main" com.sap.conn.jco.JCoRuntimeException: (127) JCO_ERROR_FIELD_NOT_FOUND: Field RETURN is not a member of OUTPUT – Utsav Aug 21 '15 at 07:41
  • 1
    `RETURN` is a table parameter, not an exporting parameter. – mjturner Aug 21 '15 at 07:50
  • thanks now its throwing error , to populate interface parameter POITEMX – Utsav Aug 21 '15 at 08:24
  • Yes, you need to fill the `X` structures with the values you're updating. – mjturner Aug 21 '15 at 10:03

1 Answers1

0

You need to call BAPI_TRANSACTION_COMMIT at the end to complete the transaction

AKS
  • 39
  • 1
  • 8