Microsoft.Net v3的SAP连接器-缺少SAPIDocSender类

Microsoft.Net v3的SAP连接器-缺少SAPIDocSender类,sap,connector,idoc,Sap,Connector,Idoc,我已使用SAP Connector for Microsoft.Net v2成功地将已格式化的IDoc发送到SAP。 今天我升级到了连接器的最新版本。 不幸的是,这个SAPIDocSender已经不存在了。 我现在应该如何将这些IDoc发送到SAP 谢谢你的帮助 编辑: 谢谢 不幸的是,我想像另一个线程中描述的那样构建IDOC 在v2中,有一个选项可以发送整个IDOC字符串,包括所有段: private static void SendIdoc() { SAP.Connecto

我已使用SAP Connector for Microsoft.Net v2成功地将已格式化的IDoc发送到SAP。 今天我升级到了连接器的最新版本。 不幸的是,这个SAPIDocSender已经不存在了。 我现在应该如何将这些IDoc发送到SAP

谢谢你的帮助

编辑: 谢谢 不幸的是,我想像另一个线程中描述的那样构建IDOC

在v2中,有一个选项可以发送整个IDOC字符串,包括所有段:

private static void SendIdoc()
{     
    SAP.Connector.RfcTID myTid = SAP.Connector.RfcTID.NewTID();  
    string connectionString = "ASHOST=xxxx SYSNR=xx CLIENT=xxx USER=xxx PASSWD=xxx LANG=xx";
    string upperString = connectionString.ToUpper();
    SAP.Connector.SAPIDocSender sapiDocSender = new SAPIDocSender(upperString);
    sapiDocSender.SubmitIDoc(@"C:\Users\xxx\Documents\testidoc.txt", myTid);
    sapiDocSender.ConfirmTID(myTid);
}

据我所知,当前网络连接器3中现在有idoc helper。但是,如果您有一个包含有效idoc的文件,那么您已经拥有了所需的所有信息

关于将Idocs发送到SAP系统的基本知识已经介绍过了,因此在本回答中我将不详细介绍。要发送idoc文件,必须手动填写控制记录(idoc的第一行)和数据记录

控制台需要一些人工。幸运的是,所有IDoc上的控制记录都是相同的,所以您不必考虑IDOC类型的发送。p>
var fileStream = System.IO.File.OpenRead(fullFilepath);
var streamReader = new System.IO.StreamReader(fileStream);
string control = streamReader.ReadLine();

controlTable.Append();
controlTable.CurrentRow.SetValue("TABNAM", control.Substring(0, 10));
controlTable.CurrentRow.SetValue("MANDT", control.Substring(10, 3));
controlTable.CurrentRow.SetValue("DOCNUM", control.Substring(13, 16));
controlTable.CurrentRow.SetValue("DOCREL", control.Substring(29, 4));
controlTable.CurrentRow.SetValue("STATUS", control.Substring(33, 2));
controlTable.CurrentRow.SetValue("DIRECT", control.Substring(35, 1));
controlTable.CurrentRow.SetValue("OUTMOD", control.Substring(36, 1));
controlTable.CurrentRow.SetValue("EXPRSS", control.Substring(37, 1));
controlTable.CurrentRow.SetValue("TEST", control.Substring(38, 1));
controlTable.CurrentRow.SetValue("IDOCTYP", control.Substring(39, 30));
controlTable.CurrentRow.SetValue("CIMTYP", control.Substring(69, 30));
controlTable.CurrentRow.SetValue("MESTYP", control.Substring(99, 30));
controlTable.CurrentRow.SetValue("MESCOD", control.Substring(129, 3));
controlTable.CurrentRow.SetValue("MESFCT", control.Substring(132, 3));
controlTable.CurrentRow.SetValue("STD", control.Substring(135, 1));
controlTable.CurrentRow.SetValue("STDVRS", control.Substring(136, 6));
controlTable.CurrentRow.SetValue("STDMES", control.Substring(142, 6));
controlTable.CurrentRow.SetValue("SNDPOR", control.Substring(148, 10));
controlTable.CurrentRow.SetValue("SNDPRT", control.Substring(158, 2));
controlTable.CurrentRow.SetValue("SNDPFC", control.Substring(160, 2));
controlTable.CurrentRow.SetValue("SNDPRN", control.Substring(162, 10));
controlTable.CurrentRow.SetValue("SNDSAD", control.Substring(172, 21));
controlTable.CurrentRow.SetValue("SNDLAD", control.Substring(193, 70));
controlTable.CurrentRow.SetValue("RCVPOR", control.Substring(263, 10));
controlTable.CurrentRow.SetValue("RCVPRT", control.Substring(273, 2));
controlTable.CurrentRow.SetValue("RCVPFC", control.Substring(275, 2));
controlTable.CurrentRow.SetValue("RCVPRN", control.Substring(277, 10));
controlTable.CurrentRow.SetValue("RCVSAD", control.Substring(287, 21));
controlTable.CurrentRow.SetValue("RCVLAD", control.Substring(308, 70));
controlTable.CurrentRow.SetValue("REFMES", control.Substring(420, 14));

var dataLine = streamReader.ReadLine();
while (dataLine != null) {

    dataTable.Append();
    dataTable.CurrentRow.SetValue("SEGNAM", dataLine.SubString(0, 30));
    dataTable.CurrentRow.SetValue("MANDT", dataLine.SubString(30, 3));
    dataTable.CurrentRow.SetValue("DOCNUM", dataLine.SubString(33, 16));
    dataTable.CurrentRow.SetValue("SEGNUM", dataLine.SubString(49, 6));
    dataTable.CurrentRow.SetValue("PSGNUM", dataLine.SubString(55, 6));
    dataTable.CurrentRow.SetValue("HLEVEL", dataLine.SubString(61, 2));
    dataTable.CurrentRow.SetValue("SDATA", dataLine.SubString(63, dataLine.Length - 63));

    dataLine = streamReader.ReadLine();
}

此代码段要求文件中只有一个idoc。如果一个文件中有多个idoc,则需要通过查找控制记录(控制记录行通常以“EDI_DC40”开头)来拆分它们。

据我所知,当前网络连接器3中现在有idoc helper。但是,如果您有一个包含有效idoc的文件,那么您已经拥有了所需的所有信息

关于将Idocs发送到SAP系统的基本知识已经介绍过了,因此在本回答中我将不详细介绍。要发送idoc文件,必须手动填写控制记录(idoc的第一行)和数据记录

控制台需要一些人工。幸运的是,所有IDoc上的控制记录都是相同的,所以您不必考虑IDOC类型的发送。p>
var fileStream = System.IO.File.OpenRead(fullFilepath);
var streamReader = new System.IO.StreamReader(fileStream);
string control = streamReader.ReadLine();

controlTable.Append();
controlTable.CurrentRow.SetValue("TABNAM", control.Substring(0, 10));
controlTable.CurrentRow.SetValue("MANDT", control.Substring(10, 3));
controlTable.CurrentRow.SetValue("DOCNUM", control.Substring(13, 16));
controlTable.CurrentRow.SetValue("DOCREL", control.Substring(29, 4));
controlTable.CurrentRow.SetValue("STATUS", control.Substring(33, 2));
controlTable.CurrentRow.SetValue("DIRECT", control.Substring(35, 1));
controlTable.CurrentRow.SetValue("OUTMOD", control.Substring(36, 1));
controlTable.CurrentRow.SetValue("EXPRSS", control.Substring(37, 1));
controlTable.CurrentRow.SetValue("TEST", control.Substring(38, 1));
controlTable.CurrentRow.SetValue("IDOCTYP", control.Substring(39, 30));
controlTable.CurrentRow.SetValue("CIMTYP", control.Substring(69, 30));
controlTable.CurrentRow.SetValue("MESTYP", control.Substring(99, 30));
controlTable.CurrentRow.SetValue("MESCOD", control.Substring(129, 3));
controlTable.CurrentRow.SetValue("MESFCT", control.Substring(132, 3));
controlTable.CurrentRow.SetValue("STD", control.Substring(135, 1));
controlTable.CurrentRow.SetValue("STDVRS", control.Substring(136, 6));
controlTable.CurrentRow.SetValue("STDMES", control.Substring(142, 6));
controlTable.CurrentRow.SetValue("SNDPOR", control.Substring(148, 10));
controlTable.CurrentRow.SetValue("SNDPRT", control.Substring(158, 2));
controlTable.CurrentRow.SetValue("SNDPFC", control.Substring(160, 2));
controlTable.CurrentRow.SetValue("SNDPRN", control.Substring(162, 10));
controlTable.CurrentRow.SetValue("SNDSAD", control.Substring(172, 21));
controlTable.CurrentRow.SetValue("SNDLAD", control.Substring(193, 70));
controlTable.CurrentRow.SetValue("RCVPOR", control.Substring(263, 10));
controlTable.CurrentRow.SetValue("RCVPRT", control.Substring(273, 2));
controlTable.CurrentRow.SetValue("RCVPFC", control.Substring(275, 2));
controlTable.CurrentRow.SetValue("RCVPRN", control.Substring(277, 10));
controlTable.CurrentRow.SetValue("RCVSAD", control.Substring(287, 21));
controlTable.CurrentRow.SetValue("RCVLAD", control.Substring(308, 70));
controlTable.CurrentRow.SetValue("REFMES", control.Substring(420, 14));

var dataLine = streamReader.ReadLine();
while (dataLine != null) {

    dataTable.Append();
    dataTable.CurrentRow.SetValue("SEGNAM", dataLine.SubString(0, 30));
    dataTable.CurrentRow.SetValue("MANDT", dataLine.SubString(30, 3));
    dataTable.CurrentRow.SetValue("DOCNUM", dataLine.SubString(33, 16));
    dataTable.CurrentRow.SetValue("SEGNUM", dataLine.SubString(49, 6));
    dataTable.CurrentRow.SetValue("PSGNUM", dataLine.SubString(55, 6));
    dataTable.CurrentRow.SetValue("HLEVEL", dataLine.SubString(61, 2));
    dataTable.CurrentRow.SetValue("SDATA", dataLine.SubString(63, dataLine.Length - 63));

    dataLine = streamReader.ReadLine();
}

此代码段要求文件中只有一个idoc。如果一个文件中有多个IDOC,则需要通过查找控制记录(控制记录行通常以“EDI_DC40”开头)来拆分它们。

根据Dirk的回答,我刚刚创建了两种方法,使用可用的元数据动态填充控制和数据表:

    private static void AddControlToIdocTable(ref IRfcTable control, string controlLine)
    {
        var lineType = control.Metadata.LineType;

        //Append a new Control Row
        control.Append();

        //Creates an empty array with the Count of the different fields the RfcTable consists of
        string[] columns = new string[control.Metadata.LineType.FieldCount];

        for (int i = 0; i < columns.Length; i++)
        {
            //Get the Type containg the structure of the field
            var type = lineType[i];

            //If NucOffset + NucLength is not bigger then the length of the current control line
            //we append the substring of the control line using those values (Offset + Length)
            if(controlLine.Length >= (type.NucOffset + type.NucLength))
                control.CurrentRow.SetValue(type.Name, controlLine.Substring(type.NucOffset, type.NucLength));
        }
    }

    private static void AddDataToIdocTable(ref IRfcTable records, List<string> dataLines)
    {
        var lineType = records.Metadata.LineType;

        //Creates an empty array with the Count of the different fields the RfcTable consists of
        string[] columns = new string[records.Metadata.LineType.FieldCount];

        foreach (string dataLine in dataLines)
        {
            //Append a new Data Row for every data line
            records.Append();
            for (int i = 0; i < columns.Length; i++)
            {
                //Get the Type containg the structure of the field
                var type = lineType[i];

                //If NucOffset + NucLength is not bigger then the length of the current control line
                //we append the substring of the control line using those values (Offset + Length)
                if (dataLine.Length >= (type.NucOffset + type.NucLength))
                    records.CurrentRow.SetValue(type.Name, dataLine.Substring(type.NucOffset, type.NucLength));
            }
        }
    }
private static void addcontroltodoctable(参考IRfcTable控件,字符串控件)
{
var lineType=control.Metadata.lineType;
//追加一个新的控制行
control.Append();
//创建一个空数组,其中包含RfcTable包含的不同字段的计数
string[]columns=新字符串[control.Metadata.LineType.FieldCount];
for(int i=0;i=(type.NucOffset+type.nucleLength))
control.CurrentRow.SetValue(type.Name,controlLine.Substring(type.NucOffset,type.nucleLength));
}
}
私有静态void AddDataToIdocTable(参考IRfcTable记录,列表数据行)
{
var lineType=records.Metadata.lineType;
//创建一个空数组,其中包含RfcTable包含的不同字段的计数
string[]columns=新字符串[records.Metadata.LineType.FieldCount];
foreach(数据线中的字符串数据线)
{
//为每个数据行追加一个新的数据行
Append();
for(int i=0;i=(type.NucOffset+type.nucleLength))
records.CurrentRow.SetValue(type.Name,dataLine.Substring(type.NucOffset,type.nucleLength));
}
}
}

将在测试后发布更多详细信息。谢谢

根据Dirk的回答,我刚刚创建了两种方法,通过使用可用的元数据动态填充控件和数据表:

    private static void AddControlToIdocTable(ref IRfcTable control, string controlLine)
    {
        var lineType = control.Metadata.LineType;

        //Append a new Control Row
        control.Append();

        //Creates an empty array with the Count of the different fields the RfcTable consists of
        string[] columns = new string[control.Metadata.LineType.FieldCount];

        for (int i = 0; i < columns.Length; i++)
        {
            //Get the Type containg the structure of the field
            var type = lineType[i];

            //If NucOffset + NucLength is not bigger then the length of the current control line
            //we append the substring of the control line using those values (Offset + Length)
            if(controlLine.Length >= (type.NucOffset + type.NucLength))
                control.CurrentRow.SetValue(type.Name, controlLine.Substring(type.NucOffset, type.NucLength));
        }
    }

    private static void AddDataToIdocTable(ref IRfcTable records, List<string> dataLines)
    {
        var lineType = records.Metadata.LineType;

        //Creates an empty array with the Count of the different fields the RfcTable consists of
        string[] columns = new string[records.Metadata.LineType.FieldCount];

        foreach (string dataLine in dataLines)
        {
            //Append a new Data Row for every data line
            records.Append();
            for (int i = 0; i < columns.Length; i++)
            {
                //Get the Type containg the structure of the field
                var type = lineType[i];

                //If NucOffset + NucLength is not bigger then the length of the current control line
                //we append the substring of the control line using those values (Offset + Length)
                if (dataLine.Length >= (type.NucOffset + type.NucLength))
                    records.CurrentRow.SetValue(type.Name, dataLine.Substring(type.NucOffset, type.NucLength));
            }
        }
    }
private static void addcontroltodoctable(参考IRfcTable控件,字符串控件)
{
var lineType=control.Metadata.lineType;
//追加一个新的控制行
control.Append();
//创建一个空数组,其中包含RfcTable包含的不同字段的计数
string[]columns=新字符串[control.Metadata.LineType.FieldCount];
for(int i=0;i=(type.NucOffset+type.nucleLength))
control.CurrentRow.SetValue(type.Name,controlLine.Substring(type.NucOffset,type.nucleLength));
}
}
私有静态void AddDataToIdocTable(参考IRfcTable记录,列表数据行)
{
var lineType=records.Metadata.lineType;
//创建一个空数组,其中包含RfcTable包含的不同字段的计数
string[]columns=新字符串[records.Metadata.LineType.FieldCount];
foreach(数据线中的字符串数据线)
{
//为每个数据行追加一个新的数据行
Append();
for(int i=0;i