Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
The iQuery.dtaara() UDTF returns a one row result that contains the data area content, along with some of the data area attributes, such as length and type.
UDF | Return Type | Description |
dtaara | TABLE | Returns the content and attributes of a data area. |
Form 1:
iquery.DTAARA( library, data area name, starting-position, length );
Form 2:
iquery.DTAARA( data area name, starting-position, length );
Note: This function uses our polymorphic qualified name syntax.
The first form allows users to specify a library (schema) and data area object name in two separate parameters. The second form allows users to specify the data area name and optional library as one parameter using CL-style qualified syntax. If the data area is not qualified, the library list is searched for the data area.
The library parameter is the IBM i libary (schema) that contains the data area. It can be a valid library name, *LIBL or *CURLIB.
The data area parameter is the name of the data area whose content is returned. In form 1 it is a simple object name (upper/lower case is ignored). In form 2 it can be a simple object name or a qualified object name (e.g., qgpl/mystuff).
The Starting Position parameter is optional and identifies the first byte to retrieve from the data area. If unspecified, then position 1 is used. This parameter is only used for *CHAR data areas.
The Length parameter is optional and identifies the number of bytes to retrieve from the data area. If unspecified, then the number of bytes is calculated through the end of the data area data being returned. This parameter is only used for *CHAR data areas.
Column | Type | Description |
DTAARA | varchar(10) | The name of the data area whose data is being returned. |
DTAARALIB | varchar(10) | The library where the data area is located. |
DTAARATYPE | varchar(5) | The type of data area (*CHAR, *DEC, *LGL). |
LENGTH | int | The declared length of the data area. |
DECPOS | int | If DTAARATYPE is *DEC, then this column contains the decimal positions. Otherwise it is null. |
VALUE | varchar(2000) | The data area data returned begins at the Starting-position parameter for the number of bytes specified on the LENGTH parameter, but never exceeds the length of the data area definition itself. |
select value INTO :LDA from table (iQuery.dtaara('*LDA')) da;
The local data area is read and its content copied to the LDA host variable.
Remember, using SQL, you can cast the resulting value to any length you need. For example, if you store several pieces of information in the data area, you can extract the indivudal parts using the SQL SUBSTR function and also convert the result from a VARCHAR(2000) into some other data-type and length. For example:
select Dec(substr(value, 1, 5),5,0) as compDiv, char(substr(value, 11,20),30) as compName INTO :compDivision, :companyName FROM table(iQuery.dtaara('datalib/compinfo')) da;