2016-02-16 7 views
-1

J'ai utilisé SAP Connector pour Microsoft .Net v2 pour envoyer avec succès l'IDOCS déjà formaté à SAP. Aujourd'hui, j'ai mis à niveau vers la dernière version du connecteur. Malheureusement, ce SAPIDocSender n'est plus là. Comment envoyer maintenant ces IDOCS à SAP?SAP Connector pour Microsoft .Net v3 - Classe SAPIDocSender manquante

Merci pour votre aide!

EDIT: Merci! Malheureusement je veux construire l'IDOC comme il est décrit dans l'autre Thread.

Dans v2 il y avait une option pour envoyer toute la chaîne de IDOC, y compris tous les segments:

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); 
} 
+0

double possible de [Comment créer et envoyer Idocs à SAP en utilisant .Net SAP Connector 3] (http://stackoverflow.com/questions/34896202/ comment-créer-et-envoyer-idocs-à-sap-using-sap-net-connecteur-3) –

+0

Voir ci-dessus éditer. Merci encore! –

+0

ce n'est pas plus difficile. Vous avez déjà toutes les données dans le fichier pour l'enregistrement de contrôle (première ligne de votre fichier) et les enregistrements de données. La longueur est fixe et vous n'avez qu'à remplir manuellement les premiers champs pour les enregistrements de données et les champs pour l'enregistrement de contrôle. Afaik il n'y a plus d'assistant idoc dédié dans la bibliothèque NCo. –

Répondre

1

pour autant que je sais qu'il est maintenant aide IDOC dans le connecteur net courant 3. Mais si vous avez un fichier contenant un idoc valide, vous avez déjà toutes les informations dont vous avez besoin.

Les bases sur l'envoi d'Idocs au système SAP sont déjà décrites here, donc je ne vais pas entrer dans les détails à ce sujet dans cette réponse. Pour envoyer votre fichier idoc, vous devez remplir manuellement l'enregistrement de contrôle (première ligne de votre idoc) et les enregistrements de données.

La table de contrôle nécessite un travail manuel. Heureusement l'enregistrement de contrôle est le même sur tous les idocs, donc vous n'avez pas à considérer le type d'idoc votre envoi.

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

Cet extrait attend un seul IDoc dans le fichier. Si vous avez plusieurs idocs dans un fichier, vous devez les séparer en recherchant l'enregistrement de contrôle (la ligne d'enregistrement de contrôle commence généralement par "EDI_DC40").

+0

Salut Dirk! En attendant, j'ai juste essayé presque la même chose. Ça semble fonctionner correctement. Merci encore! Publiera un extrait contenant le code pour obtenir les métadonnées dynamiquement à partir de la table. –

0

Sur la base de la réponse de Dirk Je viens de créer 2 méthodes pour remplir les tableaux de données de contrôle & dynamiquement en utilisant les métadonnées disponibles:

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

afficherons quelques détails supplémentaires après les essais. Merci!

0

J'ai travaillé avec le code de Fabio pendant quelques minutes, j'ai lu la documentation SAP et j'ai trouvé cette méthode de remplissage des tables. (Les tableaux de commande et de données sont de la même classe)

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