Hi,

In my previous post, I provided code which use SysDa framework to implement while select loop and in this post will provide the code where it can be used to implement Find method.

Note: CG_SysDaQueryFind is a runnable class.

class CG_SysDaQueryFind

{       

    /// <summary>
    /// SysDaQueryObject - Implementing Find method
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        /*
            Effective X++ Statement -
            static SalesTable find(SalesId  _salesId,
                                   boolean  _forUpdate = false)
            {
                SalesTable  salesTable;
                if (salesId)
                {
                    if (_forUpdate)
                    {
                        salesTable.selectForUpdate (_forUpdate);
                    }
 
                    select firstonly salesTable
                        where salesTable.SalesId == salesId;
                }
 
                return salesTable;
        }
        */
 
        SalesTable salesTable = CG_SysDaQueryFind::find("002");
 
        if (salesTable.RecId != 0)
        {
            info(strFmt("SalesId is %1", salesTable.SalesId));
        }               
    }
 
    static SalesTable find(SalesId  _salesId,
                               boolean  _forUpdate = false)
    {
        SalesTable          salesTable;
        SysDaQueryObject    sysDaQuery = new SysDaQueryObject(SalesTable);
 
        if (_salesId)
        {
            if (_forUpdate)
            {
                // Select for update
                sysDaQuery.forUpdateHint = true;
            }
 
            // Imposes optimistic lock
            sysDaQuery.optimisticLockHint = true;
 
            // Select firstonly
            sysDaQuery.firstOnlyHint = true;
            sysDaQuery.whereClause(new SysDaEqualsExpression
                                (new SysDaFieldExpression(SalesTable, fieldStr(SalesTable, SalesId)),
                                 new SysDaValueExpression(_salesId)));           
            SysDaFindObject findObject = new SysDaFindObject(sysDaQuery);
            new SysDaFindStatement().execute(findObject);
        }
 
        return salesTable;
    }
 
}

Output: https://drive.google.com/open?id=1-hxRYWEdmN9gJSfje7C8Zg5b-IzDX3l9

Regards,

Chaitanya