In the previous section you learned how to create dynamic versions of visual objects to increase the flexibility of your application’s user interface. You also learned how to use handles to access the attributes and methods of those objects as well as their static counterparts. In this section you learn how to do the same with data management objects such as queries and buffers. The next sections continue with a discussion of temp-tables and the browse. The same principles apply to visual objects, so the concepts should already be familiar to you.

Using a dynamic query, you can postpone until run time the tasks of defining what table or tables a query should use, and what the selection criteria should be for the result set the query manages. Using a dynamic buffer, you can likewise allow the application to identify at run time what table a buffer should store data for.

Putting these dynamic objects together with dynamic temp-tables and browses gives you the ability to define almost any aspect of your application at run time, when this is necessary. Although you should not make all your queries and buffers dynamic, having the ability to do so allows you to build general purpose tools for certain parts of your application that might need to deal with a wide variety of user requirements in a consistent way. Being able to do this from a single procedure with dynamic objects is greatly preferable to writing and compiling many different procedures that do essentially the same job for different tables or fields.

It is important to note that these dynamic features are not meant to replace all the static statements in earlier versions of ABL, or to be the standard way to write code for all new applications. There is a significant performance cost to using dynamic data management statements, which can be well worth the cost when the flexibility is needed but an unnecessary expense and complication, otherwise. If your tables, fields, and queries are known and fixed when you write the procedure, then there is no need to use dynamic statements to manage them. Likewise, if you have a static object, such as a query, on a specific table or tables but need to modify just the WHERE clause at run time or access some of its attributes and methods, you can easily do this through a handle attached to the static object. This keeps your code simpler and more efficient.

This section and the one that follows include straightforward but fairly comprehensive examples that show the power of dynamic data management objects, allowing you to browse data from any database table or temp-table you care to define. By the end of these two sections, you will have a solid understanding of some of the most powerful features in ABL and how best to use them in your applications.