SAP .net连接器错误请输入出售给派对或运送到派对

时间:2013-04-26 07:14:20

标签: c# .net sap

我正在尝试使用SAP nco 3 .net连接器将SAP与.net Web应用程序集成。我已成功连接到SAP系统但是当我尝试使用BAPI“BAPI_SALESORDER_CREATEFROMDAT1”在SAP中创建销售订单时,我收到以下错误: “请输入出售给派对或运送到派对”。 以下是我正在使用的代码段:

    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 detalis:

     // Partner
            salesPartnersStruct.SetValue("PARTN_ROLE", "SP");
            salesPartnersStruct.SetValue("PARTN_NUMB", "102003");

谢谢, 函数naveed

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分: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 "";