Ledger Settlement is very slow

This problem can be done when you do a migration of data of Ax. Why is it slow ? I don’t know, but you can increase the speed by modifying these piece of code :

Class CustVendPaymNote.buildPaymNote()

[...]
    CustVendTransOpen   custVendTransOpenSelect;
    CustVendTrans       custVentTransSelect;
    ;
[...]

// BEGIN
//    while select crossCompany RecId from specTrans
//        where specTrans.SpecCompany == _specCompany
//           && specTrans.SpecTableId == _specTableId
//           && specTrans.SpecRecId   == _specRecId
//        join RecId from custVendTransOpen
//            where custVendTransOpen.DataAreaId == specTrans.RefCompany
//               && custVendTransOpen.TableId == specTrans.RefTableId
//               && custVendTransOpen.RecId   == specTrans.RefRecId
//        join TransDate, DocumentNum, Invoice, PaymId, Voucher from custVentTrans
//            where custVentTrans.RecId == custVendTransOpen.RefRecId

    while select crossCompany RecId from specTrans
        index   hint SpecIdx
        where specTrans.SpecCompany                     == _specCompany
           && specTrans.SpecTableId                     == _specTableId
           && specTrans.SpecRecId                       == _specRecId
        join RecId from custVendTransOpenSelect
            where custVendTransOpenSelect.DataAreaId    == specTrans.RefCompany
            && custVendTransOpenSelect.TableId          == specTrans.RefTableId
            && custVendTransOpenSelect.RecId            == specTrans.RefRecId
        exists join TransDate, DocumentNum, Invoice, PaymId, Voucher
            from    custVentTransSelect
            where   custVentTransSelect.RecId           == custVendTransOpenSelect.RefRecId
    {
        select  firstonly custVendTransOpen
        where   custVendTransOpen.TableId   == specTrans.RefTableId
        &&      custVendTransOpen.RecId     == specTrans.RefRecId;

        select  firstonly custVendTrans
        index   RecId
        where   custVendTrans.RecId == custVendTransOpen.RefRecId;
// END

Class LedgerJournalTransUpdateVend.checkSettleVoucher()

...
    VendTrans               vendTransSelect;
    VendTable               vendTransVendorSelect;
    ;
...

// BEGIN
//        while select crossCompany specTrans
//            where specTrans.SpecCompany == _ledgerJournalTrans.company() &&
//                specTrans.SpecTableId == _ledgerJournalTrans.TableId &&
//                specTrans.SpecRecId == _ledgerJournalTrans.RecId
//            join vendTransOpen
//                where specTrans.RefCompany == vendTransOpen.DataAreaId &&
//                    specTrans.RefTableId == vendTransOpen.TableId &&
//                    specTrans.RefRecId == vendTransOpen.RecId
//            join vendTrans
//                where vendTransOpen.RefRecId == vendTrans.RecId
//            join vendTransVendor
//                where vendTrans.AccountNum == vendTransVendor.AccountNum
        while select crossCompany specTrans
            where   specTrans.SpecCompany   == _ledgerJournalTrans.company()
            &&      specTrans.SpecTableId   == _ledgerJournalTrans.TableId
            &&      specTrans.SpecRecId     == _ledgerJournalTrans.RecId
        join RefRecId
            from    vendTransOpen
            where   vendTransOpen.DataAreaId    == specTrans.RefCompany
            &&      vendTransOpen.TableId       == specTrans.RefTableId
            &&      vendTransOpen.RecId         == specTrans.RefRecId
        exists join vendTransSelect
            where   vendTransSelect.RecId       == vendTransOpen.RefRecId
        exists join vendTransVendorSelect
            where   vendTransVendorSelect.AccountNum    == vendTrans.AccountNum
// END
        {
// BEGIN
            vendTrans       = VendTrans::find(vendTransOpen.RefRecId);
            vendTransVendor = VendTable::find(vendTrans.AccountNum);
// END

Last class : LedgerJournalTransUpdateCust.checkSettleVoucher

...
    CustTable               CustTransCustomerSelect;
    CustTrans               custTransSelect;
    ;
...

// BEGIN
//        while select crossCompany specTrans
//            where specTrans.SpecCompany == _ledgerJournalTrans.company() &&
//                specTrans.SpecTableId == _ledgerJournalTrans.TableId &&
//                specTrans.SpecRecId == _ledgerJournalTrans.RecId
//            join custTransOpen
//                where specTrans.RefCompany == custTransOpen.DataAreaId &&
//                    specTrans.RefTableId == custTransOpen.TableId &&
//                    specTrans.RefRecId == custTransOpen.RecId
//            join custTrans
//                where custTransOpen.RefRecId == custTrans.RecId
//            join custTransCustomer
//                where custTrans.AccountNum == custTransCustomer.AccountNum
        while select crossCompany specTrans
            where   specTrans.SpecCompany       == _ledgerJournalTrans.company()
            &&      specTrans.SpecTableId       == _ledgerJournalTrans.TableId
            &&      specTrans.SpecRecId         == _ledgerJournalTrans.RecId
        join AmountCur, RefRecId
            from    custTransOpen
            where   specTrans.RefCompany        == custTransOpen.DataAreaId
            &&      specTrans.RefTableId        == custTransOpen.TableId
            &&      specTrans.RefRecId          == custTransOpen.RecId
        exists join custTransSelect
            where   custTransOpen.RefRecId      == custTransSelect.RecId
        exists join custTransCustomerSelect
            where   custTransSelect.AccountNum  == custTransCustomerSelect.AccountNum
// END
        {
// BEGIN
            custTrans           = CustTrans::find(custTransOpen.RefRecId);
            custTransCustomer   = CustTable::find(custTrans.AccountNum);
// END

Show filter in a report

You customer want to show in the report all field which are used in the selection ?

There is a little piece of code for do that.

For increase the process, I say that : “If I found a hole in the fieldId number highter that 10, that’s mean that I have no more field in this layer, and I pass to the next layer”.

display FreeTxt filter()
{
    #define.RETURN          ('\n')
    #define.BEGIN           (1)
    #define.END             (60000)

    int             fieldIdx;
    int             notFind;
    int             maxNotFind  = 10;
    FreeTxt         ret;

    TableId         tableId;

    SysDictField    sysDictField;

    int newFieldIdx(int _fieldIdx)
    {
        if (_fieldIdx < 10000)
        {
            return 10000;
        }
        else if (_fieldIdx < 20000)
        {
            return 20000;
        }
        else if (_fieldIdx < 30000)
        {
            return 30000;
        }
        else if (_fieldIdx < 40000)
        {
            return 40000;
        }
        else if (_fieldIdx < 50000)
        {
            return 50000;
        }

        return 60000;
    }
    ;

    //
    //  Check for PurchLine
    //

    tableId = tableNum(PurchLine);

    for (fieldIdx = #BEGIN; fieldIdx <= #END; fieldIdx++)
    {
        sysDictField    = new SysDictField(tableId, fieldIdx);

        if (sysDictField)
        {
            notFind = 0;

            if (element.query().dataSourceTable(tableNum(PurchLine)).findRange(fieldIdx))
            {
                if (element.query().dataSourceTable(tableNum(PurchLine)).findRange(fieldIdx).value())
                {
                    ret += #RETURN;

                    ret += sysDictField.name()  + ' : ' + element.query().dataSourceTable(tableNum(PurchLine)).findRange(fieldIdx).value();
                }
            }
        }
        else
        {
            notFind ++;

            if (notFind == maxNotFind)
            {
                fieldIdx = newFieldIDx(fieldIdx);
                notFind = 0;
            }
        }
    }
}