public string SAVE_MAIL_DATA(MAIL_DATA_BE mail_data, List <Attachment_BE> attachs, List <Relacionados> relacionados, SharedSettings.Settings settings) { byte[] pdf; try { //Establecemos conexion con SAP RfcConfigParameters rfc = SAP_Connection.GetParameters(settings); RfcDestination rfcDest = null; rfcDest = RfcDestinationManager.GetDestination(rfc); //Creamos repositorio para la funciĆ³n RfcRepository repo = rfcDest.Repository; IRfcFunction save_mail = repo.CreateFunction("Z_MAIL_SAVE"); IRfcStructure p_maildata = save_mail.GetStructure("P_MAILDATA"); IRfcTable p_attachments = save_mail.GetTable("P_ATTACHMENTS"); IRfcTable p_relacionados = save_mail.GetTable("P_RELACIONADOS"); get_maildata_sapstr(mail_data, ref p_maildata); get_mailattach_saptab(attachs, ref p_attachments); get_relacionados_saptab(relacionados, ref p_relacionados); //Ejecutamos la consulta save_mail.Invoke(rfcDest); pdf = save_mail.GetByteArray("FILEPDFGEN"); IRfcStructure bapiret = save_mail.GetStructure("BAPIRET"); //string res = save_mail.GetString("MSG"); //Revisamos que la consulta haya sido exitosa if (pdf.Length > 0 && String.IsNullOrEmpty(attachs[0].PATHFILEPDF) == false) { if (System.IO.File.Exists(attachs[0].PATHFILEPDF) == false) { System.IO.File.WriteAllBytes(attachs[0].PATHFILEPDF, pdf); } } if (bapiret.GetString("TYPE") == "E") { string mensajeError = bapiret.GetString("MESSAGE"); return(mensajeError); //Hubo un error } else { return(""); //Guardado exitoso } } catch (RfcCommunicationException e) { throw e; } catch (RfcLogonException e) { // user could not logon... throw e; } catch (RfcAbapRuntimeException e) { // serious problem on ABAP system side... throw e; } catch (RfcAbapBaseException e) { // The function module returned an ABAP exception, an ABAP message // or an ABAP class-based exception... throw e; } catch (Exception e) { throw e; } }