QueryRun

New queryRun
New queryRun from query
Example modify range
Run
Sum of a queryRun
Form that open query - Prompt
Selection : query used - Previously used query

New queryRun

//To take a query of a form with the filter we use a queryrun
void clicked()
{
	Query           QueryTotal;
	QueryRun        QueryRunTotal;
	SalesLine       SalesLineLocal;
	LineAmount      totLineAmount;
	SalesLineAmount totDeliveryRemainder;
	QueryBuildDatasource qbds;

	TotalLineAmount.realValue(0);
	TotalDeliveryRemainder.realValue(0);
	super();
	QueryTotal      = new query();
	QueryTotal      = salesTable_ds.queryRun().query();
	qbds = QueryTotal.dataSourceTable(tableNum(SalesTable));
	QueryRunTotal        = new QueryRun(QueryTotal);
	while (QueryRunTotal.next())
	{
		SalesLineLocal          = QueryRunTotal.get(tablenum(SalesLine));
		TotLineAmount           += SalesLineLocal.LineAmount;
		TotDeliveryRemainder    += SalesLineLocal.SPLSalesLineRemainderAmount();
	}
	TotalLineAmount.realValue(TotLineAmount);
	TotalDeliveryRemainder.realValue(TotDeliveryRemainder);
}

New queryRun from query

    QueryRun        = new SysQueryRun(queryStr(SPLSalesRoundPlan2));

Example modify range

//In this job twe modify range in a QueryRun.
//To do it, we need to modify the query of the queryRun and associate again the query to the queryRun.
static void SPL_SBE_Test(Args _args)
{
    Query           Query;
    QueryRun        QueryRun;
    SalesLine       SalesLine;
    SalesTable      SalesTable;
    LogisticsPostalAddress LogisticsPostalAddress;
    QueryBuildDatasource qbds;
    QueryBuildRange qbrDeliveryWeek,qbrDateConfirmed;
    int             DeliveryWeek;
    date            DateConfirmed;
    ;
    QueryRun        = new SysQueryRun(queryStr(SPLSalesRoundPlan2));
    if (QueryRun.prompt())
    {
        Query           = QueryRun.query();
        qbds            = Query.dataSourceTable(tableNum(SalesTable));
        qbrDeliveryWeek = qbds.findRange(fieldNum(SalesTable,SPLDeliveryWeek));
        DeliveryWeek    = str2int(qbrDeliveryWeek.value());
        qbrDeliveryWeek.value("");

        qbrDateConfirmed = qbds.findRange(fieldNum(SalesTable,ShippingDateConfirmed));
        DateConfirmed    = mkDate(11,03,2013) + 1;
        qbrDateConfirmed.value('<' + queryValue(DateConfirmed));
        
        QueryRun         = new SysQueryRun(Query);  //affection of the modify query to the queryRun.

        while (QueryRun.next())
        {
            SalesTable                  = QueryRun.get(tablenum(SalesTable));
            SalesLine                   = QueryRun.get(tablenum(SalesLine));
            LogisticsPostalAddress      = QueryRun.get(tablenum(LogisticsPostalAddress));
            info(SalesTable.SalesId + date2str(SalesTable.ShippingDateConfirmed, 321, 2, -1, 2, -1, 4) + " " + SalesLine.SalesId + " " + SalesLine.itemid + " " + LogisticsPostalAddress.state);
        }
    }
}

Run

void run()
{
	qeuSalesList.query().dataSourceTable(tablenum(CustInvoiceJour)).update(true);
	qeuSalesList.query().dataSourceTable(tablenum(ProjInvoiceJour)).update(true);

	while (qeuSalesList.next())
	{
		if (qeuSalesList.changed(tablenum(CustInvoiceJour)))
		{
			custInvoiceJour = qeuSalesList.get(tablenum(CustInvoiceJour));
			this.loadFromCustInvoiceJour();
		}
		if (qeuSalesList.changed(tablenum(ProjInvoiceJour)))
		{
			projInvoiceJour = qeuSalesList.get(tablenum(ProjInvoiceJour));
			this.loadFromProjInvoiceJour();
		}
	}
}

	FetchLogique : Fetch : 1 - n
	============
	the next() read : 
	- the first line of the Table 1
		- the first  line of the Table 2
		- the second line of the Table 2
		- ...
		- the n ieme line of the Table 2

	- the second line of the Table 1
		- the first  line of the Table 2
		- the second line of the Table 2
		- ...
		- the n ieme line of the Table 2

Sum of a queryRun


	//===copy of a query to do sum===//
	querySumPrice = new Query(qr.pack());
	queryRunSumPrice = new queryRun(querySumPrice);
	queryRunSumPrice.interactive(false);
	while (queryRunSumPrice.next())
	{
		if (queryRunSumPrice.changed(tablenum(CustInvoiceTrans)))
        	{
        		custInvoiceTransLocal = queryRunSumPrice.get(tablenum(CustInvoiceTrans));
                	lineAmountRes += custInvoiceTransLocal.LineAmountMST;
        	}
	}

	//=== EXAMPLE 
	//=== Sum from a a query of a query Run.
	//We use pack to copy and query and change the object.
	//We can do a sum without change the original object

	querySumPrice = new Query(qr.pack());
	queryRunSumPrice = new queryRun(querySumPrice);
	queryRunSumPrice.interactive(false);
	while (queryRunSumPrice.next())
	{
		if (queryRunSumPrice.changed(tablenum(CustInvoiceTrans)))
		{
			custInvoiceTransLocal = queryRunSumPrice.get(tablenum(CustInvoiceTrans));
			lineAmountMSTTotal += custInvoiceTransLocal.LineAmountMST;
		}
	}
	repQuery = qr.query();
	repQuery.clearOrderBy();

Form that open query - Prompt

Example 1 :
===========
// SalesReleaseOrderPicking : creation of temporary table with query prompt.
In Inventory and warehouse management/Periodic.
Example 2 :
===========
// Form LedgerTransVoucher : GL>Inquiries>Voucher Transaction -> open the prompt on the open of the form

//Init of the form
void init()
{
    Query                   query;
    QueryBuildDataSource    ds;
    super();

    query = generalJournalEntry_ds.query();

    ds = query.dataSourceTable(tableNum(MainAccount));

    // set the DimensionAttributeValueCombination-->MainAccount relation because the wrong one is the default
    ds.clearLinks();
    ds.addLink(fieldNum(DimensionAttributeValueCombination, MainAccount), fieldNum(MainAccount, RecId));

    // manually add the natural key query field
    ds.addRange(fieldNum(MainAccount, MainAccountId));
    
	element.updateQueryForMenu(query);
}
private void updateQueryForMenu(Query _query)
{
    QueryBuildDataSource ds;
    TableId sourceTable;

    if (element.args().parm() == formStr(VendTrans) && isConfigurationkeyEnabled(configurationKeyNum(LedgerBasicWithholdingTax)))
    {
        ds = _query.dataSourceTable(tableNum(GeneralJournalAccountEntry));

        ds.addRange(fieldNum(GeneralJournalAccountEntry, Text));
    }

    // verify a GeneralJournalEntry buffer is not passed in the
    // menu case because if the assert fails, we should add a
    // ReferenceNumber range instead of prompting the user
    sourceTable = element.args().dataset();
    Debug::assert(sourceTable != tableNum(GeneralJournalEntry));

    element.promptUser(_query);
}
private void promptUser(Query _query)
{
    QueryBuildDataSource ds;

    // manually add the natural key query fields
    ds = _query.dataSourceTable(tableNum(GeneralJournalEntry));
    ds.addRange(fieldNum(GeneralJournalEntry, JournalNumber));
    ds.addRange(fieldNum(GeneralJournalEntry, SubledgerVoucher));
    ds.addRange(fieldNum(GeneralJournalEntry, AccountingDate));

    queryRun = new QueryRun(_query);

    if (!queryRun.prompt())
    {
        element.close();
    }

    generalJournalEntry_ds.query(queryRun.query());
}


// To prompt a queryRun. Form AifDocumentFilter
public void editDocumentQueryFilter()
{
    AifDocumentQueryFilter documentQueryFilter;
    container packedQuery, updatedPackedQuery;
    Query documentQuery;


    documentQueryFilter = aifDocumentQueryFilter;
    packedQuery = documentQueryFilter.Query;

    if (packedQuery == conNull())
    {
        documentQuery = this.getDocumentQuery(aifPortServiceView.ServiceClassId);
        packedQuery = documentQuery.pack();
    }

    updatedPackedQuery = element.editQuery(packedQuery);

    if (updatedPackedQuery != conNull())
    {
        documentQueryFilter.Query = updatedPackedQuery;
    }
}
container editQuery(container packedQuery)
{
    SysQueryRun sysQueryRun;
    container updatedQueryContainer = conNull();

    sysQueryRun = new SysQueryRun(packedQuery) ;
    sysQueryRun.promptShowQuerySelect(false) ;
    sysQueryRun.promptShowSorting(false);
    sysQueryRun.promptAllowSave(false);
    sysQueryRun.promptLoadLastUsedQuery(false) ;
    sysQueryRun.promptSaveQueryPrUser(false) ;
    sysQueryRun.promptAllowAddDataSource(false) ;
    sysQueryRun.promptShowReset(false) ;
    sysQueryRun.promptAllowQueryFilters(false);

    if (sysQueryRun.prompt())
    {
        updatedQueryContainer = sysQueryRun.query().pack();
    }
    return updatedQueryContainer;
}

Selection : query used - Previously used query

protected void initDefaults(Args _args)
{
    this.getLast();
    this.parmArgs(_args);

    this.queryBuild();

    queryrun.saveUserSetup(false);
}