Data Inserting in LedgerJournalTrans Table - Error

Dear All

I tried to Bulk Uploading in Vouchers.

1st - i create a temp table & upload the relavent datas

2nd - i create the journal - and click the lines,

3nd - in the lines window - i created the Command button for inserting the data

Command Button - script (clicked event)

Public void clicked()
{

LedgerTable LedgerTable;
CustTable CustTable;
VendTable VendTable;
JournalId JournalNumLoc;
LedgerJournalTable LedgerJournalTableLoc;
VoucherUpload VoucherUploadLoc;

;

While Select VoucherUploadLoc
Where VoucherUploadLoc.JournalNum == LedgerJournalTable.JournalNum
{
ttsBegin;

LedgerJournalTrans.TransDate = VoucherUploadLoc.TransDate;

///////////// Ledger
Select LedgerTable
Where LedgerTable.AccountNum == VoucherUploadLoc.Accountnum;

if (LedgerTable.RecId)
{
LedgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
}

Select LedgerTable
Where LedgerTable.AccountNum == VoucherUploadLoc.OffsetAccount;

if (LedgerTable.RecId)
{
LedgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
}

///////////////Customer
Select CustTable
Where CustTable.AccountNum == VoucherUploadLoc.Accountnum;

if (CustTable.RecId)
{
LedgerJournalTrans.AccountType = LedgerJournalACType::Cust;
}

Select CustTable
Where CustTable.AccountNum == VoucherUploadLoc.OffsetAccount;

if (CustTable.RecId)
{
LedgerJournalTrans.OffsetAccountType = LedgerJournalACType::Cust;
}

////////////// Vendor
Select VendTable
Where VendTable.AccountNum == VoucherUploadLoc.Accountnum;

if (VendTable.RecId)
{
LedgerJournalTrans.AccountType = LedgerJournalACType::Vend;
}

Select VendTable
Where VendTable.AccountNum == VoucherUploadLoc.OffsetAccount;

if (VendTable.RecId)
{
LedgerJournalTrans.OffsetAccountType = LedgerJournalACType::Vend;
}

LedgerJournalTrans.AccountNum = VoucherUploadLoc.Accountnum;
LedgerJournalTrans.Txt = VoucherUploadLoc.Txt;
LedgerJournalTrans.AmountCurDebit = VoucherUploadLoc.AmountCurDebit;
LedgerJournalTrans.AmountCurCredit = VoucherUploadLoc.AmountCurCredit;
LedgerJournalTrans.OffsetAccount = VoucherUploadLoc.OffsetAccount;
LedgerJournalTrans.CurrencyCode = ‘INR’;
if (voucherUploadLoc.AmountCurDebit != 0 )
{
LedgerJournalTrans.AssessableValue_IN = voucherUploadLoc.AmountCurDebit;
}
if (voucherUploadLoc.AmountCurCredit != 0 )
{
LedgerJournalTrans.AssessableValue_IN = voucherUploadLoc.AmountCurCredit;
}
ttsCommit;
LedgerJournalTrans.insert();
LedgerJournalTrans_ds.create();
}

}

When i clicked the button, first record inserted - after that the below mentioned error shown.

Error : A new number cannot be assigned because CR-1112-001157 has not been saved or deleted.

Anyone help to resolve this issue.

Regards

Saravanan.R