Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Hi people!

Just these days I involved in web application manteniance as web consultant and hit some "rocky-code" to send multiple attached documents, searching in CN I find sections of code but no fit with my code style, no counts error on run...

With patience and research found a suitable solution and then presented:


// objSAP is Company interface connected
objSAP.StartTransaction();
Documents req = (Documents)objSAP.GetBusinessObject(BoObjectTypes.oPurchaseRequest);
req.DocType = BoDocumentTypes.dDocument_Items;
req... // set more properties and lines
string errMsj;
int errCode;
Attachments2 att = (Attachments2)objSAP.GetBusinessObject(BoObjectTypes.oAttachments2);
i = 0;
foreach (AdjuntoEntity a in adjs) // adjs is of type List<> with some properties listed below
{
   string filePath = ConfigurationManager.AppSettings["adjuntos"] + a.NombreInterno;
   FileInfo fi = new FileInfo(filePath);
   if (!fi.Exists)
      continue;
   i++;
   if (i > 1)
      att.Lines.Add();
   att.Lines.FileName = fi.Name.Replace(fi.Extension, "");
   att.Lines.FileExtension = fi.Extension.Substring(1);
   att.Lines.SourcePath = fi.DirectoryName;
   att.Lines.Override = BoYesNoEnum.tYES;
}
errCode = att.Add();
int y1 = int.Parse(objSAP.GetNewObjectKey());
if (errCode != 0)
{
   objSAP.GetLastError(out errCode, out errMsj);
   throw new SapException(errMsj) { ErrorCode = errCode };
}
if (!att.GetByKey(y1))
{
   throw new SapException("error");
}
req.AttachmentEntry = y1;
errCode = req.Add();
if (errCode != 0)
{
   objSAP.GetLastError(out errCode, out errMsj);
   throw new SapException(errMsj) { ErrorCode = errCode };
}
objSAP.EndTransaction(BoWfTransOpt.wf_Commit);

this code can be applied on any other SAP document.

Cheers

Labels in this area