【问题标题】:Calling BAPI_PO_CREATE using SAP.Net Connector 3.0使用 SAP.Net 连接器 3.0 调用 BAPI_PO_CREATE
【发布时间】:2017-11-12 07:53:39
【问题描述】:

我正在尝试使用 SAP.net 连接器 3.0 从我的 .net 应用程序在 SAP 中创建采购订单 但是我在 RETURN 参数中收到以下错误消息

ME159:功能模块调用顺序错误。

我正在使用以下代码:

// helper method to get destination from destination configuration
var dest = RfcConfigurationHelper.GetDestination(); 

RfcSessionManager.BeginContext(dest);

IRfcFunction rfcFunction = dest.Repository.CreateFunction("BAPI_PO_CREATE");

IRfcFunction transaction = dest.Repository.CreateFunction("BAPI_TRANSACTION_COMMIT");
transaction.SetValue("WAIT","X");

IRfcStructure header = rfcFunction["PO_HEADER"].GetStructure();
header.SetValue("DOC_TYPE", "NB");
header.SetValue("PURCH_ORG", "0001");
header.SetValue("PUR_GROUP", "001");
header.SetValue("DOC_DATE", DateTime.Now.ToString("yyyy-MM-dd"));
header.SetValue("VENDOR", "V544100170");

IRfcTable items = rfcFunction["PO_ITEMS"].GetTable();
IRfcStructure item = items.Metadata.LineType.CreateStructure();
item.SetValue("PO_ITEM", "1");
item.SetValue("PUR_MAT", "TEST_MAT");
item.SetValue("PLANT", "0001");

IRfcTable shedules = rfcFunction["PO_ITEM_SCHEDULES"].GetTable();
IRfcStructure shedule = shedules.Metadata.LineType.CreateStructure();
shedule.SetValue("PO_ITEM", "1");
shedule.SetValue("DELIV_DATE", DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"));
shedule.SetValue("QUANTITY", 10);

rfcFunction.Invoke(dest);

transaction.Invoke(dest);

IRfcTable returns = rfcFunction["RETURN"].GetTable();
RfcSessionManager.EndContext(dest);

请帮忙。谢谢

【问题讨论】:

    标签: c# .net sap bapi


    【解决方案1】:

    我终于弄清楚了我错过了什么。这是一个愚蠢的错误。下面是修改后的代码

    // helper method to get destination from destination configuration
    var dest = RfcConfigurationHelper.GetDestination(); 
    
    RfcSessionManager.BeginContext(dest);
    
    IRfcFunction rfcFunction = dest.Repository.CreateFunction("BAPI_PO_CREATE");
    
    IRfcFunction transaction = dest.Repository.CreateFunction("BAPI_TRANSACTION_COMMIT");
    transaction.SetValue("WAIT","X");
    
    IRfcStructure header = rfcFunction["PO_HEADER"].GetStructure();
    header.SetValue("DOC_TYPE", "NB");
    header.SetValue("PURCH_ORG", "0001");
    header.SetValue("PUR_GROUP", "001");
    header.SetValue("DOC_DATE", DateTime.Now.ToString("yyyy-MM-dd"));
    header.SetValue("VENDOR", "V544100170");
    
    IRfcTable items = rfcFunction["PO_ITEMS"].GetTable();
    IRfcStructure item = items.Metadata.LineType.CreateStructure();
    item.SetValue("PO_ITEM", "1");
    item.SetValue("PUR_MAT", "TEST_MAT");
    item.SetValue("PLANT", "0001");
    
    // this was missing as I haven't added the row to the table
    items.Insert(item);
    
    IRfcTable schedules = rfcFunction["PO_ITEM_SCHEDULES"].GetTable();
    IRfcStructure schedule = shedules.Metadata.LineType.CreateStructure();
    schedule.SetValue("PO_ITEM", "1");
    schedule.SetValue("DELIV_DATE", DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"));
    schedule.SetValue("QUANTITY", 10);
    
    // this was missing as I haven't added the row to the table
    schedules.Insert(schedule);
    
    rfcFunction.Invoke(dest);
    
    transaction.Invoke(dest);
    
    IRfcTable returns = rfcFunction["RETURN"].GetTable();
    RfcSessionManager.EndContext(dest);
    

    【讨论】:

      猜你喜欢
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多