Skip to main content

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

All about READ in RPGLE & Why we use it with SETLL/SETGT?

READ READ is one of the most used Opcodes in RPGLE. As the name suggests main purpose of this Opcode is to read a record from Database file. What are the different READ Opcodes? To list, Below are the five Opcodes.  READ - Read a Record READC - Read Next Changed Record READE - Read Equal Key Record READP - Read Prior Record READPE - Read Prior Equal Record We will see more about each of these later in this article. Before that, We will see a bit about SETLL/SETGT .  SETLL (Set Lower Limit) SETLL accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Corresponding Record (or Next Record if exact match isn't found).  SETGT (Set Greater Than) SETGT accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Next Record (Greater Than the Key value). Syntax: SETLL SEARCH-ARGUMENTS/KEYFIELDS FILENAME SETGT  SEARCH-ARGUMENTS/KEYFIELDS FILENAME One of the below can be passed as Search Arguments. Key Fiel

What we need to know about CHAIN (RPGLE) & How is it different from READ?

CHAIN READ & CHAIN, These are one of the most used (& useful) Opcodes by any RPG developer. These Opcodes are used to read a record from file. So, What's the difference between CHAIN & READ?   CHAIN operation retrieves a record based on the Key specified. It's more like Retrieving Random record from a Database file based on the Key fields.  READ operation reads the record currently pointed to from a Database file. There are multiple Opcodes that start with READ and all are used to read a record but with slight difference. We will see more about different Opcodes and How they are different from each other (and CHAIN) in another article. Few differences to note.  CHAIN requires Key fields to read a record where as READ would read the record currently pointed to (SETLL or SETGT are used to point a Record).  If there are multiple records with the same Key data, CHAIN would return the same record every time. READE can be used to read all the records with the specified Ke

Extract a portion of a Date/Time/Timestamp in RPGLE - IBM i

%SUBDT Extracting Year, Month, Day, Hour, Minutes, Seconds or Milli seconds of a given Date/Time/Timestamp is required most of the times.  This can be extracted easily by using %SUBDT. BIF name looks more similar to %SUBST which is used to extract a portion of string by passing from and two positions of the original string. Instead, We would need to pass a value (i.e., Date, Time or Timestamp ) and Unit (i.e., *YEARS, *MONTHS, *DAYS, *HOURS, *MINUTES, *SECONDS or *MSECONDS) to %SUBDT.  Valid unit should be passed for the type of the value passed. Below are the valid values for each type. Date - *DAYS, *MONTHS, *YEARS Time - *HOURS, *MINUTES, *SECONDS Timestamp - *DAYS, *MONTHS, *YEARS, *HOURS, *MINUTES, *SECONDS, *MSECONDS Syntax: %SUBDT(value : unit { : digits { : decpos} }) Value and Unit are the mandatory arguments.  Digits and Decimal positions are optional and can only be used with *SECONDS for Timestamp. We can either pass the full form for the unit or use the short form. Below i