Hi,
If both tables are identical, especially the Field No.s with the datatype are identical, you can use TRANSFERFIELDS in your code.
For example, let's assume, you have to log an history record from the journal record. On the Gen. Journal Line Table (Table 81), you can right something like in OnModify() / OnInsert() trigger.
GenJournalHistory.SETRANGE(GenJournalHistory."Entry No.", "Entry No.");
IF GenJournalHistory.FIND('-') THEN
BEGIN
GenJournalHistory.TRANSFERFIELDS(Rec);
GenJournalHistory.MODIFY(TRUE);
END
ELSE
BEGIN
GenJournalHistory.INIT;
GenJournalHistory.TRANSFERFIELDS(Rec);
GenJournalHistory.INSERT(TRUE);
END;
If you want to insert/modify block entries from Gen. Journals to Gen. History then, code would look something like,
GenJournals.SETRANGE(GenJournals."Entry No.");
IF GenJournals.FINDSET THEN
BEGIN
REPEAT
GenJournalHistory.SETRANGE(GenJournalHistory."Entry No.", GenJournals."Entry No.")
IF GenJournalHistory.FIND('-') THEN
BEGIN
GenJournalHistory.TRANSFERFIELDS(GenJournals);
GenJournalHistory.MODIFY(TRUE);
END
ELSE
BEGIN
GenJournalHistory.INIT;
GenJournalHistory.TRANSFERFIELDS(GenJournals);
GenJournalHistory.INSERT(TRUE);
END;
UNTIL GenJournals.NEXT = 0
END;
In the second scenario, it's better if you run this code from a codeunit/report.
Here the GenJournalHistory is the record variable of the Gen. History table.
Hope it helps.