on 2017 Mar 21 10:55 PM
Hello everyone
I'm trying to upload an xml file from Ojournalvoucher with 5000 lines and it takes me over 2 hours to upload to sap. Someone knows how I can optimize my code so that this time decreases.
below the code.
using SAPbobsCOM;
using ConectoresBO.Conectores;
using System.Data.SqlClient;
using System;
namespace SAPBOConector.JournalVouchers
{
public class oJournalVouchers
{
public oJournalVouchers(SAPbobsCOM.JournalVouchers oJournalVouchers, SAPbobsCOM.Company sapCompany, ConectoresBO.Conectores.Company company, int key, int index)
{
SQLAdapter sqlAdapter = company.Conector.SQLAdapter;
SAPbobsCOM.JournalVouchers JournalVouchers = (SAPbobsCOM.JournalVouchers)sapCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalVouchers);
int COUNT = 0;
SqlDataReader reader = sqlAdapter.ejecutarConsulta("SELECT COUNT('A') FROM ["
+ sapCompany.CompanyDB + "].dbo.OBTF WHERE U_BKV_UID='"
+ oJournalVouchers.JournalEntries.UserFields.Fields.Item("U_BKV_UID").Value + "'");
if (reader.Read())
{
COUNT = reader.GetInt32(0);
}
sqlAdapter.cerrarConexion();
if (COUNT == 0)
{
//Cabecera
try
{
JournalVouchers.JournalEntries.TransactionCode = oJournalVouchers.JournalEntries.TransactionCode;
JournalVouchers.JournalEntries.Memo = oJournalVouchers.JournalEntries.Memo;
JournalVouchers.JournalEntries.UserFields.Fields.Item("U_BKV_UID").Value = oJournalVouchers.JournalEntries.UserFields.Fields.Item("U_BKV_UID").Value;
//JournalVouchers.JournalEntries.Series = oJournalVouchers.JournalEntries.Series;
JournalVouchers.JournalEntries.TaxDate = oJournalVouchers.JournalEntries.TaxDate;
JournalVouchers.JournalEntries.DueDate = oJournalVouchers.JournalEntries.DueDate;
JournalVouchers.JournalEntries.ReferenceDate = oJournalVouchers.JournalEntries.ReferenceDate;
//JournalVouchers.JournalEntries.Series = oJournalVouchers.JournalEntries.Series;
//JournalVouchers.JournalEntries.DocumentType = oJournalVouchers.JournalEntries.DocumentType;
sqlAdapter.cerrarConexion();
}
catch (Exception ErrorCapt) {
string error = "Ocurrio un Error, posible causa: " + ErrorCapt.Message;
}
//Lineas
sqlAdapter.cerrarConexion();
for (int i = 0; i < oJournalVouchers.JournalEntries.Lines.Count; i++)
{
if (i != 0) JournalVouchers.JournalEntries.Lines.Add();
oJournalVouchers.JournalEntries.Lines.SetCurrentLine(i);
JournalVouchers.JournalEntries.Lines.SetCurrentLine(i);
char[] delimiterChars = { '.' };
JournalVouchers.JournalEntries.Lines.AccountCode = oJournalVouchers.JournalEntries.Lines.AccountCode;
JournalVouchers.JournalEntries.Lines.Credit = oJournalVouchers.JournalEntries.Lines.Credit;
JournalVouchers.JournalEntries.Lines.Debit = oJournalVouchers.JournalEntries.Lines.Debit;
//JournalVouchers.JournalEntries.Lines.ReferenceDate1 = oJournalVouchers.JournalEntries.Lines.ReferenceDate1;
JournalVouchers.JournalEntries.Lines.UserFields.Fields.Item("U_HBT_Tercero").Value = oJournalVouchers.JournalEntries.Lines.UserFields.Fields.Item("U_HBT_Tercero").Value;
JournalVouchers.JournalEntries.Lines.CostingCode = oJournalVouchers.JournalEntries.Lines.CostingCode;
JournalVouchers.JournalEntries.Lines.CostingCode2 = oJournalVouchers.JournalEntries.Lines.CostingCode2;
JournalVouchers.JournalEntries.Lines.CostingCode3 = oJournalVouchers.JournalEntries.Lines.CostingCode3;
JournalVouchers.JournalEntries.Lines.CostingCode4 = oJournalVouchers.JournalEntries.Lines.CostingCode4;
JournalVouchers.JournalEntries.Lines.LineMemo = oJournalVouchers.JournalEntries.Lines.LineMemo;
//JournalVouchers.JournalEntries.Lines.ShortName = oJournalVouchers.JournalEntries.Lines.ShortName;
sqlAdapter.cerrarConexion();
JournalVouchers.JournalEntries.Lines.Add();
}
JournalVouchers.Add();
String Status = "";
if (sapCompany.GetLastErrorCode() != 0)
{
Status = "Error :" + sapCompany.GetLastErrorDescription().ToString();
}
else
{
Status = "Done";
}
//sqlAdapter.ejecutarSentencia("INSERT INTO [" + sapCompany.CompanyDB + "_CONS].dbo.LOG([Key],[index],resultado,u_bkv_uid) VALUES ('" + key + "'," + index + ",'" + Status.Replace("'", "") + "','" + JournalVouchers.JournalVouchers.UserFields.Fields.Item("U_BKV_UID").Value + "')");
sqlAdapter.ejecutarSentencia("INSERT INTO " + sapCompany.CompanyDB + "_CONS.dbo.LOG([Key],[index],resultado,u_bkv_uid) VALUES ('" + key + "'," + index + ",'" + Status.Replace("'", "") + "','" + oJournalVouchers.JournalEntries.UserFields.Fields.Item("U_BKV_UID").Value + "')");
}
else
{
//sqlAdapter.ejecutarSentencia("INSERT INTO [" + sapCompany.CompanyDB + "_CONS].dbo.LOG([Key],[index],resultado,u_bkv_uid) VALUES ('" + key + "'," + index + ",'" + "Error, ya existe el documento." + "','" + JournalVouchers.JournalVouchers.UserFields.Fields.Item("U_BKV_UID").Value + "')");
sqlAdapter.ejecutarSentencia("INSERT INTO " + sapCompany.CompanyDB + "_CONS.dbo.LOG([Key],[index],resultado,u_bkv_uid) VALUES ('" + key + "'," + index + ",'" + "Error, ya existe el documento." + "','" + oJournalVouchers.JournalEntries.UserFields.Fields.Item("U_BKV_UID").Value + "')");
}
}
}
}
Regards.
Alvaro
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
Hi Alvaro,
When you debug it, can you point out which line is taking the most time ?
If it was the JournalVouchers.Add(), I am afraid there is not much we can do aside from trying to reindex the database.
Otherwise you can try to create an XML file and then load this XML file rather than feeding each line into the object.
Regards
Edy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.