据我所知,当前的 Net Connector 3 中现在有 idoc 帮助程序。但是,如果您有一个包含有效 idoc 的文件,那么您已经拥有了所需的所有信息。
此处已经描述了有关将 Idocs 发送到 SAP 系统的基础知识,因此我不会在此答案中对此进行详细介绍。要发送您的 idoc 文件,您必须手动填写控制记录(您的 idoc 的第一行)和数据记录。
控制表需要一些手工劳动。幸运的是,所有 idocs 上的控制记录都是相同的,因此您不必考虑发送的 idoc 类型。
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”开头)。