1

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

谢谢, 纳维德

4

2 回答 2

1

sold_to_party 和ship_to_party 是必填字段。

请参阅: BAPI_SALESORDER_CREATEFROMDAT1

并且:据我记得,您必须将创建的结构和表格添加到函数中

RfcRepository repo = destination.Repository;
IRfcFunction salesDoc = repo.CreateFunction("BAPI_SALESORDER_CREATEFROMDAT1");
IRfcStructure salesHeader = salesDoc.GetStructure("ORDER_HEADER_IN");
salesHeader.SetValue("DOC_TYPE", "ZDLR");

salesDoc.SetStructure(salesHeader);

salesDoc.Invoke(destination);
于 2013-04-26T07:51:11.037 回答
0

下面的代码将与您一起使用。您所需要做的就是将这些行附加到结构中。

此外,我建议您使用 BAPI_SALESORDER_CREATEFROMDAT2,因为这是最新的,您不需要将订单数量 * 1000 相乘。

我迷失在 salesDoc 的对象结构中,但是感谢 VS,您可以在 salesDoc 上添加一个手表,您将能够弄清楚整个结构。

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


        //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");
        salesItems.Append(salesItemsStruct); // Append to Structure

        // Partner
        salesPartnersStruct.SetValue("PARTN_ROLE", "AG"); //Sold to Party 
        salesPartnersStruct.SetValue("PARTN_NUMB", "102003");
        salesPartners.Append(salesPartnersStruct); // Append to Structure

        salesPartnersStruct.SetValue("PARTN_ROLE", "WE"); //Ship to Party
        salesPartnersStruct.SetValue("PARTN_NUMB", "102003"); 
        salesPartners.Append(salesPartnersStruct); // Append to Structure


        RfcSessionManager.BeginContext(destination);
        salesDoc.Invoke(destination);
        salesDocCommit.Invoke(destination);
        RfcSessionManager.EndContext(destination);
        return "";
于 2013-07-18T09:24:51.190 回答