Share This Post

NAV Updates

Dynamics NAV GJ(General Journal) Post Line

Dynamics NAV GJ

This documentation offers detailed technical insight into the concepts and the principles that are used to redesign the Dynamics NAV GJ posting line features. The redesign creates codeunit 12 simpler and more maintainable. The documentation starts by describing the conceptual overviews of the redesign. Then it explains the technical architecture to display the changes that result from the redesign.

Dynamics NAV GJ

Dynamics NAV GJ

Dynamics NAV GJ Post Line Overview

Codeunit 12, Dynamics NAV GJ Post Line, is the major application object for general ledger posting and is the only place to insert general ledger, VAT, and customer and vendor ledger entries. This codeunit is also used for all Apply, Unapply and Reverse operations.

While the codeunit has been modified in each release over the last 10 years, its architecture remained essentially unchanged. The codeunit became large, with approximately 7,600 code lines. With this release of the Dynamics NAV GJ, the architecture is changed and the codeunit has been made simpler and more maintainable. This documentation introduces the changes and provides information that you will need for an upgrade.

Old Architecture

The old architecture had the following features:

  • There was extensive use of global variables, which increased the possibility of hidden errors due to using variables with the wrong scope.
  • There were many long procedures that also had high cyclomatic complexity (that is, a lot of CASE, REPEAT, IF nested statements), which made the code very difficult to read and maintain.
  • Several procedures that were used locally and were meant to be used locally were not marked as the local.
  • Most of the procedures had no parameters and used global variables. Some used parameters and overrode global variables with the locals.
  • Code patterns for searching the general ledger accounts and making the general ledger and the VAT entries was not standardized and varied from place to place. In addition, there was a lot of code duplication and broken symmetry between the customer and the vendor code.
  • A large part of the code in codeunit 12, approximately 30 percent, related to payment discount and tolerance calculations, although these features are not needed in many countries or regions.
  • Posting, Apply, Unapply, Reverse, Payment Discount and the Tolerance, and the Exchange Rate Adjustment was together in codeunit 12 using the long list of global variables.

New Architecture

In Microsoft Dynamics NAV, codeunit 12 has had the following improvements:

  • Codeunit 12 has been refactored into smaller procedures (all less than 100 code lines).
  • Standardized patterns for the search of the general ledger accounts have been implemented by using supported functions from Posting Group tables.
  • The Posting Engine Framework has been implemented to manage the start and finish of the transactions and isolate the creation to the general ledger and the VAT entries, the collection of VAT adjustment, and the calculation of the additional currency amounts.
  • Code duplication has been eliminated.
  • Many helper functions have been transferred to the corresponding customer and the vendor ledger entry tables.
  • The use of the global variables has been minimized so that each and every procedure uses parameters and encapsulates its own application logic.

Design Details: Posting Interface Structure

Posting interface and some other functions in codeunit 12 use posting engine functions to prepare and insert general ledger entry and VAT entry records. The posting engine is responsible for the general ledger register creation.

The functions in the following table provide a standard framework for designing posting procedures (such as Code, CustPostApplyCustledgEntry, VendPostApplyVendLedgEntry, UnapplyCustLedgEntry, UnapplyVendLedgEntry, and Reverse) and exclusive access to table 17, G/L Entry.

Routine Description
 StartPosting  Initializes posting buffer TempGLEntryBuf, locks G/L Entry and VAT Entry tables, and initializes Accounting Period, G/L Register, and Exchange Rate. Should be called once, then NextEntryNo is 0.
 ContinuePosting  Checks and posts unrealized VAT for previous transaction increment   NextTransactionNo and prepares a post of next line.
 FinishPosting  Completes posting by inserting G/L entries from temporary buffer into a database table.   Always used together with start posting. Checks for inconsistencies.
 InitGLEntry  Used to initialize the new G/L entry for Gen. Jnl Line. Returns GLEntry as the parameter.
 InitGLEntryVAT  Same as the InitGLEntry, but assigns Bal. Account No. and SummarizeVAT.
InitGLEntryVATCopy  Similar to InitGLEntryVAT, but also copies posting groups data from VAT Entry before   SummarizeVAT.
 InsertGLEntry  The function that inserts G/L entry into the global TempGLEntryBuf table. Always use this function for an insert.
 CreateGLEntry  Performs an InitGLEntry, assigns Additional Currency Amount, and then performs   InsertGLEntry. Replaces the several lines of code with the single function call.
 CreateGLEntryBalAcc  Same as CreateGLEntry, but also assigns Bal. Account Type and Bal. Account No.
 CreateGLEntryVAT  Same as CreateGLEntry, but with additional processing for posting groups and   saving to temporary VAT buffer:

 GLEntry.CopyPostingGroupsFromDtldCVBuf(DtldCVLedgEntryBuf,GenJnlLine."Gen.   Posting Type");


 CreateGLEntryVATCollectAdj  Same as CreateGLEntry, but with an additional collection of adjustments and saving to   temporary VAT buffer:

 CollectAdjustment(AdjAmount,GLEntry.Amount,GLEntry."Additional-Currency   Amount",OriginalDateSet);


 CreateGLEntryFromVATEntry  Same as CreateGLEntry, but also copies posting groups from VAT entry.


Codeunit 12 Changes: Mapping Global Variables for Dynamics NAV GJ Post Line

The below changes have been implemented in this release of Dynamics NAV.

 Microsoft Dynamics NAV 2009 R2 Microsoft Dynamics NAV 2013 R2 Comment
 GLSetup@1009 : Record 98;  GLSetup@1009 : Record 98;  Unchanged
 SalesSetup@1010 : Record 311;  Changed   to Local
 PurchSetup@1011 : Record 312;  Changed     to Local
 AccountingPeriod@1012 : Record 50;  Changed   to Local
 GLAcc@1013 : Record 15;  Changed   to Local
 GLEntry@1014 : Record 17;  GlobalGLEntry@1014 : Record 17;  Renamed
 GLEntryTmp@1015 : TEMPORARY Record 17;  TempGLEntryBuf@1010 : TEMPORARY Record   17;  Renamed
 TempGLEntryVAT@1016 : TEMPORARY   Record 17;  TempGLEntryVAT@1016 : TEMPORARY   Record   17;  Unchanged
 OrigGLEntry@1017 : Record 17;  Deleted
 VATPostingSetup@1019 : Record 325;  Changed   to Local
 Cust@1020 : Record 18;  Changed   to Local
 Vend@1021 : Record 23;  Changed   to Local
 GenJnlLine@1022 : Record 81;  Changed   to  Local
 GLReg@1029 : Record 45;  GLReg@1029 : Record 45;  Unchanged
 CustPostingGr@1030 : Record 92;  Changed   to Local
 VendPostingGr@1031 : Record 93; Changed to Local
 Currency@1032 : Record 4; Changed to Local
 AddCurrency@1033 : Record 4;  AddCurrency@1033 : Record 4;  Unchanged
 ApplnCurrency@1034 : Record 4;  Changed     to Local
 CurrExchRate@1035 : Record 330;  CurrExchRate@1035 : Record 330;  Unchanged
 VATEntry@1038 : Record 254;  VATEntry@1038 : Record 254;  Unchanged
 BankAcc@1039 : Record 270;  Changed   to Local
 BankAccLedgEntry@1040 : Record 271;  Changed   to Local
 CheckLedgEntry@1041 : Record 272;  Changed   to Local
 CheckLedgEntry2@1042 : Record 272;  Changed   to Local
 BankAccPostingGr@1043 : Record 277;  Changed   to Local
 GenJnlTemplate@1044 : Record 80; Changed to   Local
 TaxJurisdiction@1045 : Record 320;  Changed   to Local
 TaxDetail@1046 : Record 322;  TaxDetail@1046 : Record 322;  Unchanged
 FAGLPostBuf@1047 : TEMPORARY Record   5637;  Changed   to Local
 UnrealizedCustLedgEntry@1084 : Record 21;  UnrealizedCustLedgEntry@1084 : Record 21;  Unchanged
 UnrealizedVendLedgEntry@1085 : Record 25;  UnrealizedVendLedgEntry@1085 : Record 25;  Unchanged
 GLEntryVATEntryLink@1087 : Record 253;  GLEntryVATEntryLink@1087 : Record 253;  Unchanged
 TempVATEntry@1088 : TEMPORARY Record   254;  TempVATEntry@1088 : TEMPORARY Record   254;  Unchanged
 ReversedGLEntryTemp@1089 : TEMPORARY   Record 17;  Moved to   Codeunit17
 CostAccSetup@1092 : Record 1108;  Changed   to Local
 GenJnlCheckLine@1048 : Codeunit 11;  GenJnlCheckLine@1001 : Codeunit 11;  Unchanged
 ExchAccGLJnlLine@1049 : Codeunit 366;  Changed   to Local
 FAJnlPostLine@1050 : Codeunit 5632;  Changed   to Local
 SalesTaxCalculate@1051 : Codeunit 398;  Changed   to  Local
 GenJnlApply@1052 : Codeunit 225;  Changed   to Local
 DimMgt@1053 : Codeunit 408;  Changed   to Local
 JobPostLine@1028 : Codeunit 1001;  Changed   to  Local
 TransferGlEntriesToCA@1091 : Codeunit 1105;  Changed   to Local
 PaymentToleranceMgt@1002 : Codeunit 426;  Added
 AddCurrencyCode@1117 : Code[10];  Added
 FiscalYearStartDate@1054 : Date;  FiscalYearStartDate@1011 : Date;  Unchanged
 NextEntryNo@1055 : Integer;  NextEntryNo@1022 : Integer;  Unchanged
 BalanceCheckAmount@1056 : Decimal;  BalanceCheckAmount@1056 : Decimal;  Unchanged
 BalanceCheckAmount2@1057 : Decimal;  BalanceCheckAmount2@1057 : Decimal;  Unchanged
 BalanceCheckAddCurrAmount@1058 : Decimal;  BalanceCheckAddCurrAmount@1058 : Decimal;  Unchanged
 BalanceCheckAddCurrAmount2@1059 :   Decimal;  BalanceCheckAddCurrAmount2@1059 :   Decimal;  Unchanged
 CurrentBalance@1060 : Decimal;  CurrentBalance@1060 : Decimal;  Unchanged
 SalesTaxBaseAmount@1061 : Decimal;  Changed   to Local
 TotalAddCurrAmount@1062 : Decimal;  TotalAddCurrAmount@1062 : Decimal;  Unchanged
 TotalAmount@1063 : Decimal;  TotalAmount@1063 : Decimal;  Unchanged
 UnrealizedRemainingAmountCust@1086 :   Decimal;  UnrealizedRemainingAmountCust@1086 :   Decimal;  Unchanged
 UnrealizedRemainingAmountVend@1074 :   Decimal;  UnrealizedRemainingAmountVend@1074 :   Decimal;  Unchanged
 NextVATEntryNo@1064 : Integer;  NextVATEntryNo@1064 : Integer;  Unchanged
 FirstNewVATEntryNo@1065 : Integer;  FirstNewVATEntryNo@1065 : Integer;  Unchanged
 NextTransactionNo@1066 : Integer;  NextTransactionNo@1066 : Integer;  Unchanged
 NextConnectionNo@1067 : Integer;  NextConnectionNo@1067 : Integer;  Unchanged
 InsertedTempGLEntryVAT@1068 : Integer;  InsertedTempGLEntryVAT@1027 : Integer;  Unchanged
 LastDocNo@1069 : Code[20];  LastDocNo@1023 : Code[20];  Unchanged
 LastLineNo@1070 : Integer;  Deleted
 LastDate@1071 : Date;  LastDate@1021 : Date;  Unchanged
 LastDocType@1072 : ‘ ,Payment,Invoice,Credit   Memo,Finance Charge Memo,Reminder’;  LastDocType@1025 : ‘ ,Payment,Invoice,Credit   Memo,Finance Charge Memo,Reminder’;  Unchanged
 NextCheckEntryNo@1073 : Integer;  NextCheckEntryNo@1028 : Integer;  Unchanged
 AddCurrGLEntryVATAmt@1075 : Decimal;  AddCurrGLEntryVATAmt@1017 : Decimal;  Unchanged
 CurrencyDate@1076 : Date;  CurrencyDate@1020 : Date;  Unchanged
 CurrencyFactor@1077 : Decimal;  CurrencyFactor@1019 : Decimal;  Unchanged
 UseCurrFactorOnly@1078 : Boolean;  UseCurrFactorOnly@1078 : Boolean;  Unchanged
 NonAddCurrCodeOccured@1079 : Boolean;  NonAddCurrCodeOccured@1079 : Boolean;  Unchanged
 FADimAlreadyChecked@1080 : Boolean;  FADimAlreadyChecked@1080 : Boolean;  Unchanged
 AllApplied@1081 : Boolean;  Changed   to Local
 OverrideDimErr@1018 : Boolean;  OverrideDimErr@1018 : Boolean;  Unchanged
 JobLine@1036 : Boolean;  JobLine@1036 : Boolean;  Unchanged
 Prepayment@1037 : Boolean;  Deleted
 CheckUnrealizedCust@1082 : Boolean;  CheckUnrealizedCust@1082 : Boolean;  Unchanged
 CheckUnrealizedVend@1083 : Boolean;  CheckUnrealizedVend@1083 : Boolean;  Unchanged
 GLEntryNo@1090 : Integer;  GLEntryNo@1026 : Integer;  Unchanged
 GLSetupRead@1015 : Boolean;  Added
 AmountRoundingPrecision@1012 : Decimal;  Added
 CrCardTransactionEntryNo@1013 : Integer;  Added

Codeunit 12 Changes: Changes in Dynamics NAV GJ Post Procedures

The below changes have been implemented in this release of Dynamics NAV.

Microsoft Dynamics NAV 2009  R2 Microsoft Dynamics NAV 2013 R2 Comment
 GetGLReg  GetGLReg  Updated
 RunWithCheck  RunWithCheck  Updated
 RunWithoutCheck  RunWithoutCheck  Updated
 Code  Code  Updated
 PostGenJnlLine  Added
 InitAmounts  Added
 InitLastDocDate  Added
 InitVAT  InitVAT  Updated
 PostVAT  PostVAT  Updated
 InsertVAT  InsertVAT  Updated
 SummarizeVAT  SummarizeVAT  Updated
 InsertSummarizedVAT  InsertSummarizedVAT  Updated
 PostGLAcc  PostGLAcc  Updated
 PostCust  PostCust  Updated
 PostVend  PostVend  Updated
 PostBankAcc  PostBankAcc  Updated
 PostFixedAsset  PostFixedAsset  Updated
 PostICPartner  PostICPartner  Updated
 InitCodeUnit  StartPosting  Updated
 ContinuePosting  Added
 FinishCodeunit  FinishPosting  Updated
 PostUnrealizedVAT  Added
 CheckPostUnrealizedVAT  Added
 ExchangeAccounts  Added
 InitGLEntry  InitGLEntry  Updated
 InitGLEntryVAT  Added
 InitGLEntryVATCopy  Added
 InsertGLEntry  InsertGLEntry  Updated
 CreateGLEntry  Added
 CreateGLEntryBalAcc  Added
 CreateGLEntryVAT  Added
 CreateGLEntryVATCollectAdj  Added
 CreateGLEntryFromVATEntry  Added
 UpdateCheckAmounts  Added
 ApplyCustLedgEntry  ApplyCustLedgEntry  Updated
 CalcPmtDiscPossible  Added
 CalcPmtTolerancePossible  Added
 CalcPmtTolerance  CalcPmtTolerance  Updated
 CalcPmtDisc  CalcPmtDisc  Updated
 CalcPmtDiscIfAdjVAT  CalcPmtDiscIfAdjVAT  Updated
 CalcPmtDiscTolerance  CalcPmtDiscTolerance  Updated
 CalcPmtDiscVATBases  Added
 CalcPmtDiscVATAmounts  Added
 InsertPmtDiscVATForVATEntry  Added
 InsertPmtDiscVATForGLEntry  Added
 CalcCurrencyApplnRounding  CalcCurrencyApplnRounding  Updated
 FindAmtForAppln  FindAmtForAppln  Updated
 CalcCurrencyUnrealizedGainLoss  CalcCurrencyUnrealizedGainLoss  Updated
 CalcCurrencyRealizedGainLoss  CalcCurrencyRealizedGainLoss  Updated
 CalcApplication  CalcApplication  Updated
 CalcRemainingPmtDisc  CalcRemainingPmtDisc  Moved to Codeunit 426 Payment   Tolerance  Management
 CalcAmtLCYAdjustment  CalcAmtLCYAdjustment  Added
 InitNewCVLedgEntry  InitFromGenJnlLine  Moved to Table 383 Detailed CV Ledg.   Entry Buffer
 InitOldCVLedgEntry  CopyFromCVLedgEntryBuf  Moved to Table 383 Detailed CV Ledg.   Entry Buffer
 InsertDtldCVLedgEntry  InsertDtldCVLedgEntry  Moved to Table 383 Detailed CV Ledg.
 InitBankAccLedgEntry  Added
 InitCheckLedgEntry  Added
 InitCustLedgEntry  Added
 InitVendLedgEntry  Added
 InsertDtldCustLedgEntry  Added
 InsertDtldVendLedgEntry  Added
 CustUnrealizedVAT  CustUnrealizedVAT  Updated
 CustPostApplyCustLedgEntry  CustPostApplyCustLedgEntry  Updated
 PrepareTempCustLedgEntry  Added
 UnapplyCustLedgEntry  UnapplyCustLedgEntry  Updated
 TransferCustLedgEntry  CopyFromGenJnlLine  Moved to Table 21 Cust. Ledger Entry
 PostDtldCustLedgEntries  PostDtldCustLedgEntries  Updated
 PostDtldCustLedgEntry  Added
 PostDtldCustLedgEntryUnapply  Added
 GetDtldCustLedgEntryAccNo  Added
 ZeroTransNoDtldCustLedgEntries  SetZeroTransNo  Moved to Table 379 Detailed Cust. Ledg.   Entry
 AutoEntrForDtldCustLedgEntries  Refactored to   PostDtldCustLedgEntryUnapply
 CustUpdateDebitCredit  UpdateDebitCredit  Moved to Table 379 Detailed Cust. Ledg.   Entry
 ApplyVendLedgEntry  ApplyVendLedgEntry  Updated
 PrepareTempVendLedgEntry  Added
 VendPostApplyVendLedgEntry  VendPostApplyVendLedgEntry  Updated
 UnapplyVendLedgEntry  UnapplyVendLedgEntry  Updated
 TransferVendLedgEntry  CopyFromGenJnlLine  Moved to Table 25 Vendor Ledger Entry
 PostDtldVendLedgEntries  PostDtldVendLedgEntries  Updated
 PostDtldVendLedgEntry  Added
 PostDtldVendLedgEntryUnapply  Added
 GetDtldVendLedgEntryAccNo  Added
 PostDtldCVLedgEntry  Added
 PostDtldCustVATAdjustment  Added
 PostDtldVendVATAdjustment  Added
 ZeroTransNoDtldVendLedgEntries  SetZeroTransNo  Moved to Table 380 Detailed Vend. Ledg.   Entry
 AutoEntrForDtldVendLedgEntries  Refactored to   PostDtldVendLedgEntryUnapply
 VendUpdateDebitCredit  UpdateDebitCredit  Moved to Table 380 Detailed Vend. Ledg.   Entry
 VendUnrealizedVAT  VendUnrealizedVAT  Updated
 PostUnrealVATEntry  Added
 PostApply  Added
 PostUnrealVATByUnapply  PostUnrealVATByUnapply  Updated
 PostUnapply  Added
 InsertDtldCustLedgEntryUnapply  Added
 InsertDtldVendLedgEntryUnapply  Added
 InsertTempVATEntry  Added
 ProcessTempVATEntry  Added
 UpdateCustLedgEntry  Added
 UpdateVendLedgEntry  Added
 UpdateCalcInterest  UpdateCalcInterest  Updated
 UpdateCalcInterest2  UpdateCalcInterest2  Updated
 GLCalcAddCurrency  GLCalcAddCurrency  Updated
 HandleAddCurrResidualGLEntry  HandleAddCurrResidualGLEntry  Updated

Share This Post

Leave a Reply

Notify of
Skip to toolbar