【问题标题】:how to create a purchase order using BAPI : BAPI_PO_CREATE1如何使用 BAPI 创建采购订单:BAPI_PO_CREATE1
【发布时间】:2023-03-05 10:24:01
【问题描述】:

我正在尝试使用 JCO3 创建采购订单。我能够在没有任何错误的情况下执行我的函数,但我不确定什么是错误的系统没有抛出任何错误并且它也没有在 SAP 系统中创建 PO。

		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);

【问题讨论】:

  • 我看到您对 RETURN 表的显示已禁用。当你说“没有抛出任何错误”时,你的意思是“没有抛出异常”还是“没有在RETURN 中返回错误”?如果出现错误,您不会收到异常,您将在RETURN 参数中收到错误消息(它将有TYPEE)。 注意:您还应该在提交之前检查RETURN 中的错误。如果检查该表仍然没有帮助,请尝试使用完全相同的参数从 SE37 调用 BAPI。
  • 取消注释返回语句行后,我收到以下错误线程“main”中的异常 com.sap.conn.jco.JCoRuntimeException: (127) JCO_ERROR_FIELD_NOT_FOUND: Field RETURN is not a member of OUTPUT
  • RETURN 是表参数,不是导出参数。
  • 现在感谢它的抛出错误,填充接口参数 POITEMX
  • 是的,您需要用您正在更新的值填充X 结构。

标签: sap jco


【解决方案1】:

最后需要调用 BAPI_TRANSACTION_COMMIT 来完成交易

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 2017-05-31
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-08
    相关资源
    最近更新 更多