Understanding Relationship between Ledgertrans query and LedgerPeriod Table

Hi there,

I’m currently in the process of understanding how a report within AX has been developed within the USR layer. I understand everything apart from a method written within the main method section. The method described is documented directly below.

Data Source


Ledgertrans_1(ledgertrans) - one table

Method Class Declaration


public class ReportRun extends ObjectRun
{
str PeriodNo;
}

Method


void period()
{
ledgerperiod lperiod;

while select lperiod
where ledgertrans_1.TransDate >= lperiod.PeriodStart
&& ledgertrans_1.TransDate <= lperiod.PeriodEnd
&& lperiod.PeriodCode == 1
{
PeriodNo = lperiod.Commentaries;
break;
}
}

The report itslf is based on an AutoDesignSpec. There is a Body section and within this section there is a display method:

display str GetPeriod()
{
element.period();
return PeriodNo;
}

I can then see that a string has been added to be displayed on the report and the Data Method property has been set to GetPeriod.

When I run the report, the output displays the financial period (Commentaries field i.e. Period 7) which is great but I do not understand how the period method can recognise what period the ledgertrans.transdate is in. How is it picking the correct line within the ledgerperiod table? This is what I would like to understand.

When I add a break point to the Period method (documented below), when I step trough the WHILE STATEMENT I can see that AX understands exactly what ledgerperiod record is linked to the ledgertrans query.

void period()
{
ledgerperiod lperiod;

while select lperiod
where ledgertrans_1.TransDate >= lperiod.PeriodStart
&& ledgertrans_1.TransDate <= lperiod.PeriodEnd
&& lperiod.PeriodCode == 1
{
PeriodNo = lperiod.Commentaries;
break;
}
}

Can anyone please explain to me how AX works this the period out. Is there more code being executed somewhere. I’ve explored both tables and cannot see any relationships between these 2 tables.

Would appreciated any feedback.

Thanks and kind regards,
Tom

Please confirm if I’ ve not made myself clear regaridng this question. IS there any other information you require. Regards. Tom

Hi Tom,

there is no physical relation between ledgerPeriod and ledgerTrans as ledger period is the setup table but there is always been a relation between the ledgerperiod and transaction tables on dates and periodCode column.

PeriodStart,PeriodEnd,PeriodCode columns in the ledgerPeriod is used to identify the correct record. you also needs to know that Ledger periods are recorded in the set of date ranges like

PeriodStart= March 1 … PeriodEnd = March 30 …PeriodCode= Normal, … Commentaries = Period 3 (name of period for example )

Now if your transaction “LedgerTrans” recorded in the range of March1 to March 30, then LedgerPeriod will always give you “period 3”. it just simply matches the date of transaction in the ledgerPeriod record

ax far as report is concerned, the report have the ledgerTrans as report datasource and GetPeriod is a display method that will execute for each record in your LedgerTrans, it simply passes the each record of LedgerTrans to GetPeriod method which matches the date of LedgerTrans in LedgerPeriod date range and return you the Commentaries

Thanks
Amir
https://msdax.wordpress.com

Thanks for the reply Amir. I appreciate your feedback and comments in relation to my original post.

In your 4th paragraph you mention that “it just simply matches the date of transaction in the ledgerPeriod record”.

I would like to understand how AX knows this. Do you know?

How does AX recognise that Period 3 should be returned?

Many thanks,
Tom