Reuse query results in AL and reports
An AL consumer can reuse a query's links, filters, and aggregation instead of rebuilding the projection with nested record loops. A report can use the same query as a dataset source while keeping report request fields and rendering layouts in the report object.
Read results from AL
Declare a query variable, set its filters, call Open, and read rows with Read. Access each output through the corresponding query column. Call Close when iteration ends. Keep the query read-only and use another API for updates.
The result is a projection from the data at execution time, not a guaranteed dynamic view. Rerun the query when a consumer needs fresh data. For a comparison of query and record-variable patterns, see Using Queries Instead of Record Variables.
Feed a report dataset
A report can use an Integer data item to iterate while it reads a query. Open the query in OnPreDataItem, call Read in OnAfterGetRecord, and call CurrReport.Break when Read returns false. Close the query in OnPostDataItem. Set request filters before opening the query.
An Excel rendering layout is a separate report artifact. When report layout generation is enabled, AL: Package can generate the Excel layout from the report dataset. Validate the dataset with a data-only Excel export as well as checking the rendered layout. See Report dataset and Query object.