如何使用BAPI创建采购订单:BAPI_PO_CREATE1

时间:2015-08-21 06:43:14

标签: sap jco

我正在尝试使用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);




1 个答案:

答案 0 :(得分:0)

您需要在结束时调用BAPI_TRANSACTION_COMMIT才能完成交易

相关问题