Pages

Wednesday, January 6, 2021

Read data in Data Area from SQL - IBM i

Data Area (DTAARA)

Data areas have been very much useful for sharing the data with in the job and across multiple jobs on IBM i. 

There have been many ways for reading the data from Data Area based on the place it is being read (like CL, RPGLE, SQL, Command Line etc...)

In this post, we will see how to read data in Data Area from SQL using function DATA_AREA_INFO. Results returned by this function are similar to the values returned by RTVDTAARA (Retrieve Data Area) CL command and QWCRDTAA (Retrieve Data Area) API.

Let's have a look at how DATA_AREA_INFO works with an example. 

DATA_AREA_INFO

In the above query,
  • 'DATA_AREA_NAME' is the only parameter we are passing and is the only mandatory parameter. Data area passed will be considered from the library list. If not present in library list and error will be thrown. This parameter accepts some special values like,
    • *LDA - Local Data Area
    • *GDA - Group Data Area
    • *PDA - Program Initialization Parameter Data Area
DATA_AREA_INFO

In the above result, 
  • Column 'DATA_AREA_LIBRARY' returns the library in which data area is present in.
  • Column 'DATA_AREA_NAME' returns the name of the data area. 
  • Column 'DATA_AREA_TYPE' returns the type of data stored in the data area (*CHAR, *DEC or *LGL).
  • Column 'LENGTH' returns the length of the data area. 
  • Column 'DECIMAL_POSITIONS' returns the number of decimal positions (this is only valid for Decimal data areas).
  • Column 'DATA_AREA_VALUE' returns the data stored in the data area. 
  • One other column which isn't in the above result is 'DATA_AREA_BINARY_VALUE', this returns the data stored in the data area as a binary value.
In the above query, we are just passing Data Area name and the data area present in the library list would be retuned by default. We can pass the library name explicitly to read the data from the data area in specific library. 

DATA_AREA_INFO

In the above example, we are passing library name and using Decimal data area. This should now return the number of decimal positions.

DATA_AREA_INFO

One other parameter this function accepts is 'IGNORE_ERRORS'. This parameter accepts two values.
  • 'YES' - Error is ignored and the partial data is returned. Only Data Area name (and Library Name if specified) and other columns would be null. 
  • 'NO' - An error is returned. This the default value. 
Above function would only work with one data area, If we need to retrieve the same data for multiple data areas at once from SQL, 'DATA_AREA_INFO' view would be useful. 

DATA_AREA_INFO view

This query would return the data from all the data areas present in the library passed. 

DATA_AREA_INFO view

Columns returned are almost same DATA_AREA_INFO function and below are the only additional columns in this view. 
  • 'SQL_SEQUENCE' - 'YES' if the data area is defined as SQL Sequence and 'NO' if not.
  • 'TEXT_DESCRIPTION' - Description of the data area.

If you have any Suggestions or Feedback, Please leave a comment below or use Contact Form.

No comments:

Post a Comment

Popular Posts