我正在尝试使用 SAP .NET 连接器将 SAP 与 .NET Web 应用程序集成。
我已成功连接到 SAP 系统,但是当我尝试在 SAP 中使用创建销售订单时出现BAPI_SALESORDER_CREATEFROMDAT1
以下错误:
请输入已售至方或运送至方。
我使用的代码片段:
public class CreateSalesOrder
{
public string CreateOrder(RfcDestination destination)
{
try
{
RfcRepository repo = destination.Repository;
IRfcFunction salesDoc = repo.CreateFunction("BAPI_SALESORDER_CREATEFROMDAT1");
IRfcFunction salesDocCommit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
IRfcStructure salesHeader = salesDoc.GetStructure("ORDER_HEADER_IN");
IRfcTable salesItems = salesDoc.GetTable("ORDER_ITEMS_IN");
IRfcTable salesPartners = salesDoc.GetTable("ORDER_PARTNERS");
IRfcStructure salesItemsStruct = salesItems.Metadata.LineType.CreateStructure();
IRfcStructure salesPartnersStruct = salesPartners.Metadata.LineType.CreateStructure();
IRfcStructure salesPartnersStructRow2 = salesPartners.Metadata.LineType.CreateStructure();
//Sales Header
salesHeader.SetValue("DOC_TYPE", "ZDLR");
salesHeader.SetValue("SALES_ORG", "1000");
salesHeader.SetValue("DISTR_CHAN", "00");
salesHeader.SetValue("DIVISION", "00");
salesHeader.SetValue("SALES_OFF", "1001");
//Sales Items
salesItemsStruct.SetValue("ITM_NUMBER", "323");
salesItemsStruct.SetValue("PLANT", "1001");
salesItemsStruct.SetValue("MATERIAL", "20000206");
salesItemsStruct.SetValue("TARGET_QTY", "200");
salesItemsStruct.SetValue("REQ_QTY", "200");
// Partner
salesPartnersStruct.SetValue("PARTN_ROLE", "SP");
salesPartnersStruct.SetValue("PARTN_NUMB", "102003");
RfcSessionManager.BeginContext(destination);
salesDoc.Invoke(destination);
salesDocCommit.Invoke(destination);
RfcSessionManager.EndContext(destination);
return "";
}
catch (RfcCommunicationException e)
{
return e.ToString();
}
catch (RfcLogonException e)
{
// user could not logon...
return e.ToString();
}
catch (RfcAbapRuntimeException e)
{
// serious problem on ABAP system side...
return e.ToString();
}
catch (RfcAbapBaseException e)
{
return e.ToString();
// The function module returned an ABAP exception, an ABAP message
// or an ABAP class-based exception...
}
}
}
请建议我在通话中做错了什么。我在以下代码片段中正确传递了合作伙伴详细信息:
// Partner
salesPartnersStruct.SetValue("PARTN_ROLE", "SP");
salesPartnersStruct.SetValue("PARTN_NUMB", "102003");
谢谢, 纳维德