BLVCKFX
1/28/2020 - 1:26 PM

Merging two Table Records

some times we need to merge two records within one line of the table, so to do this you can use the following code, here, for example, I am using VendTabel and try to merge two vendors whose a/c no is 5001 and 5002 within 5001.

we will explore how to correct such a situation by merging two records including all their related transactions. For the demonstration, we will merge two vendor accounts 5001 and 5002 into a single one, that is, 5001.

static void VendAccountMerge(Args _args)
{
     VendTable vendTable;
     VendTable vendTableDelete;
     PurchJournalAutoSummary jourSummary;
     #define.vend('5001')
     #define.vendDelete('5002')

     ;

     ttsbegin;
     delete_from jourSummary
      where jourSummary.VendAccount == #vendDelete;
      
     select firstonly forupdate vendTableDelete
      where vendTableDelete.AccountNum == #vendDelete;
      
     select firstonly forupdate vendTable
      where vendTable.AccountNum == #vend;
      
     vendTableDelete.merge(vendTable);
     vendTable.doUpdate();
     vendTableDelete.doDelete();
     ttscommit;

}