Data Area, Flat File (PF) & The Difference

Data Area and Flat File (Physical File) are two different types of objects which has their own advantages. Before we go about comparing these two, Let us see what is data area and flat file. 

Data Area (DTAARA):

A Data area is an object used to hold data for access by any job running on the system. A Data area can be used store the information of limited size. 

We can create the data area using CRTDTAARA (Create Data Area) command.

CRTDTAARA DTAARA(QTEMP/TEMPDTAARA) TYPE(*CHAR) LEN(2000) TEXT('Temporary Data Area')

Above command is used to create a data area of type character with length of '2000' digits. Maximum allowed length for Character data area is '2000' digits (Default is 32 digits).

CRTDTAARA DTAARA(QTEMP/TEMPDTAARA) TYPE(*DEC) LEN(24 9) TEXT('Temporary Data Area')

Above command is used to create data area of type decimal with length 24 digits, 9 decimal positions. Maximum allowed length for Decimal data area is 24 digits, 9 decimal positions (Default is 15 digits, 5 decimal positions).

There are some system defined data areas created automatically. 

  • Local Data Area, usually referred as '*LDA' is created for each job in the system. Length of LDA is 1024 digits.
  • Group Data Area, usually referred as '*GDA' is created by system when an interactive job becomes group job in the system (using the CHGGRPA - Change Group Attributes). Length of GDA is 512 digits.
  • Program Initialization Data Area, usually referred as '*PDA' is created for each pre-start job. Length of PDA is 2000 digits. 
  • Remote Data Area is data area on the remote system.
Below are the useful commands to work with data areas. 

Display Data Area (DSPDTAARA) is used to display the data in the data area along with attributes of data area (like Name, Length, Type and Description).

DSPDTAARA DTAARA(QTEMP/TEMPDTAARA)

Change Data Area (CHGDTAARA) is used to change the data in the data area. Data can be changed either for full data area or part of data area. Substring starting position and length to be defined if data in part of data area is to be changed. Substring starting position default value '*ALL' would change the data in the data area from starting position. 

CHGDTAARA DTAARA(QTEMP/TEMPDTAARA *ALL) VALUE('CHANGE DATA IN DATA ARAEA')

CHGDTAARA DTAARA(QTEMP/TEMPDTAARA (20 10)) VALUE('SUBSTRING')

Retrieve Data Area (RTVDTAARA) is used to retrieve the data in data area and store it in a CL variable. This command can only be used inside CL program. Similar to CHGDTAARA data can either be retrieved in full or substring. 

RTVDTAARA DTAARA(QTEMP/TEMPDTAARA *ALL) RTNVAR(&CLVARIABLE)

RTVDTAARA DTAARA(QTEMP/TEMPDTAARA (20 10)) RTNVAR(&CLVARIABLE)

Below are the some of the areas where Data areas are mostly used (not limited to) on IBM i.
  • To pass the information within a job. This could either be done using '*LDA' or by creating data area in QTEMP.
  • To provide a field that is frequently changes within a Job. 
  • To provide a constant field to be able to access from different Jobs. 
  • To prevent a process from being run by multiple users. Locking the data area to one user and checking if the data area is allocatable or not to determine if a process is running. 
Flat File (Physical File):

Flat file is actually a physical file (PF) with just one field (character). There is no need to define DDS to create flat file. Flat file can be created by using CRTPF and mentioning Record Length (RCDLEN).

CRTPF FILE(QTEMP/FLATFILE) RCDLEN(32766) TEXT('Flat File with Maximum Length')

Maximum allowed Record Length for Flat file is '32766' digits. 

Flat file can be used in the Programs similar to any other Physical files (to read, write, update and delete the data). File Name, Field Name and Record Format Name all are same.

Flat files are mostly used as Output file to copy the data to Stream file on IFS. 

Data Area vs Flat File:

So, What is the difference between Data Area and Flat File? These are two different object types and their usage is also different. It may not be appropriate to differentiate between Data Area and Flat File based on their usage. 

Here are some differences based on the attributes of Data Area and Flat File. 
  • Data Area can only store the data up to 2000 digits maximum. Flat file can store the data up to 32,766 digits maximum.
  • Data Area can only store one set of data. Flat file can hold more than one set of data as different records.
  • Flat file can only be created with default character field. Data Area can be created as Character, Decimal or Logical. 
  • Flat file created in QTEMP cannot be carried forward to the Submitted Job. Data in LDA would be carried to Submitted Job's LDA automatically.

Comments

Popular posts from this blog

What is the importance of User Open (USROPN) in RPGLE - IBM i

What is Deep Learning? Beyond the Basics of AI

What is Artificial Intelligence?