首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SAP连接器用于Microsoft .Net v3 - SAPIDocSender类缺失

SAP连接器用于Microsoft .Net v3 - SAPIDocSender类缺失
EN

Stack Overflow用户
提问于 2016-02-16 15:15:37
回答 3查看 517关注 0票数 0

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

谢谢你的帮忙!

编辑:谢谢!不幸的是,我想创建IDOC,就像在其他线程中描述的那样。

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

代码语言:javascript
复制
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);
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-02-17 09:09:03

据我所知,当前的need 3中现在有idoc助手,但是如果您有一个包含有效idoc的文件,那么您已经有了所需的所有信息。

关于将Idocs发送到SAP系统的基础知识已经被描述为here,所以我不会在这个答案中详细讨论这个问题。要发送idoc文件,您必须手动填写控制记录(idoc的第一行)和数据记录。

控制表需要一些体力劳动。幸运的是,所有idocs上的控制记录都是相同的,因此您不必考虑您发送的idoc类型。

代码语言:javascript
复制
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。如果一个文件中有多个idocs,则需要通过查找控制记录来拆分它们(控制记录行通常以“EDI_DC40”开头)。

票数 2
EN

Stack Overflow用户

发布于 2016-02-17 09:50:29

基于Dirk的回答,我刚刚创建了两个方法来使用可用的元数据来动态填充控件&数据表:

代码语言:javascript
复制
    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));
            }
        }
    }

测试后会发布一些更多的细节。谢谢!

票数 1
EN

Stack Overflow用户

发布于 2018-02-14 13:28:17

我使用了Fabio的代码几分钟,阅读了SAP文档,并提出了一种填充表的方法。(控件和数据表属于同一类)

代码语言:javascript
复制
    private void AppendRecordToTable(IRfcTable idocTable, string textRecord)
    {
        var structure = idocTable.Metadata.LineType.CreateStructure();
        foreach (var field in structure)
        {
            var fieldMeta = field.Metadata;
            var fieldValue = CreateFieldValue(fieldMeta, textRecord);
            structure.SetValue(fieldMeta.Name, fieldValue);
        }
        idocTable.Append(structure);
    }

    private string CreateFieldValue(RfcFieldMetadata fieldMeta, string record)
    {
        if (record.Length < fieldMeta.NucOffset)
            return new string(' ', fieldMeta.NucLength);
        if (record.Length < fieldMeta.NucOffset + fieldMeta.NucLength)
            return record.Substring(fieldMeta.NucOffset).PadRight(fieldMeta.NucLength);
        return record.Substring(fieldMeta.NucOffset, fieldMeta.NucLength);
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35436165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档