2011年6月14日 星期二

Programming dynamic selections

You require two things before you can implement a dynamic selection in a logical database. One is a special statement in the database program's selection include (DBxxxSEL). This special statement ensures that the user can enter the corresponding selection criterion. You enter the selection criterion for a dynamic selection in a different way from simply parameters or selection tables, and the program also evaluates it in a different way. Therefore, the selection statement must be tailored to the paritcular table so that the table can evalutate this selection criterion. This section will introduce you to the statements you require in more detail.
In the DBxxxSEL section include, the following statement defines the database table for which a dynamic selection is to be implemented:
SELECTION-SCREEN DYNAMIC SELECTIONS
   FOR TABLE table
   [ID ident].
If dynamic selections are to be supported for several tables, a statement is required for each table. If the report uses a table that is intended for a DYNAMIC SELECTION, the Dynamic selections pushbutton appears in the selection screen. Any entries made when the application is running for any dynamic selections are stored in a complex data object called DYN_SEL. This data object contains an internal table called CLAUSES. Each data record in this table contains another internal table called WHERE_TAB. The selection criteria for all the dtabase tables are stored in this internal table. You must use this special variant of the SELECT statement to evaluate these selection criteria.
SELECT * FROM table
   WHERE (itab).
This variant of the SELECT statement reads the selection criteria from an internal table. You can also enter other conditions in the WHERE clause. Before you do this, the internal table used in the WHERE clause must be filled with data from the DYN_SEL dataset.
The DYN_SEL data object has a very complex structure. The definition is stored in the RSDS type pool. Its most elementary component is the dype definition for an internal RSDS_WHERE_TAB table. This internal table is derived from a structure stored in the Data Dictionary. It merely consists of a CHAR-type field with a length of 72 characters.
TYPES: RSDS_WHERE_TAB LIKE RSDSWHERE OCCURS 5.
This definition flows into the definition of the RSDS_WHERE structure. This structure has a TABLENAME field, in which you enter a table name, and a WHERE_TAB internal table. The selection criteria for the table defined in the TABLENAME field are stored in the WHERE_TAB internal table.
TYPES:
   BEGIN OF RSDS_WHERE,
      TABLENAME LIKE RSDSTABS-PRIM_TAB,
      WHERE_TAB WHERE_TAB TYPE RSDS_WHERE_TAB,
   END OF RSDS_WHERE.
You use this type of structure to define another internal table. This second internal table stores the selection criteria for several Data Dictionary tables.
TYPES: RSDS_TWHERE TYPE RSDS_WHERE OCCURS 5.
Finally, the table definition shown above is incorporated into the RSDS_WHERE type description. This type now contains the CLAUSES field, which contains an RSDS_TWHERE-type table.
TYPES:
   BEGIN OF RSDS_TYPE,
      CLAUSES TYPE RSDS_TWHERE,
      TEXPR TYPE RSDS_TEXPR,
      TRANGE TYPE RSDS_TRANGE,
   END OF RSDS_TYPE.
This data type has two additional fields that also contain very complex objects. The TEXPR field ocntains the selection criteria in a form that can be stored, whereas the TRANGE field saves tehse criteria in some of the RANGES tables. If necessary, the CHECK statement can use these RANGES tables. Finally, you use data type RSDS_TYPE to generate a real data object. You sue the following statement to do this:
DATA DYN_SEL TYPE RSDS_TYPE.
You will find more details about the structure of the other components in DYN_SEL in the type pool we mentioned above.
From the data types discussed above, you can see that DYN_SEL always stores data in all tables where dynamic selections have been used to enter selection criteria. Therefore, you usually access values in DYN_SEL by using the name of the database table as a limiting criterion.

沒有留言:

張貼留言