Sign in

docs RPG Reference

Free-form DTAARA keyword for a field or subfield

Free-form DTAARA keyword for a field or subfield

The optional parameter of the DTAARA keyword for a free-form field or subfield definition is the external name of the data area. If the parameter is not specified, the name of the field or subfield is used as the external name.

The external name of the data area can be in one of the following forms:

  • ‘MYLIB/MYDTAARA’
  • ‘*LIBL/MYDTAARA’
  • ‘MYDTAARA’

It can be

  • A character literal
  • A named constant representing a character literal
  • A character variable. If the data area has an OUT operation or UNLOCK operation, the value of the character variable for the IN *LOCK operation that locked the data area is used.

For information about how unquoted names are handled different for the DTAARA keyword in fixed-form and free-form definitions, see Unquoted names for the DTAARA keyword.

Examples

In the following example, the data area is defined without a parameter, so the field name is used as the external name. Data area *LIBL/MYDTAARA is used at runtime.

   DCL-S mydtaara CHAR(100) DTAARA;

In the following example, the DTAARA keyword is specified without a parameter, so the subfield name is used as the external name. Data area *LIBL/DTAARA2 is used at runtime.

   DCL-DS data_struct;
      dtaara2 CHAR(100) DTAARA;
   END-DS;

In the following example, a character literal is specified for the DTAARA keyword. Data area MYLIB/DTAARA3 is used at runtime.

   DCL-S mydtaara CHAR(100) DTAARA('MYLIB/DTAARA3');

In the following example, a named constant is specified for the DTAARA keyword. Data area *LIBL/DTA4 is used at runtime.

   DCL-C DTAARA_NAME 'DTA4';
   DCL-S dtaara4 CHAR(100) DTAARA(DTAARA_NAME);

In the following example, character variable dtaara_name is specified for the DTAARA keyword.

  1. The variable is set to “MYLIB/DTA5”.
  2. Data area MYLIB/DTA5 is used at runtime for the IN operation.
  3. The variable is set to “MYLIB/DTA5_B”.
  4. Data area MYLIB/DTA5 is used at runtime for the OUT operation. The current value of the variable is not used for the OUT operation. The same data area must be used for both the IN *LOCK operation and the OUT operation that changes the locked data area.
  5. Data area MYLIB/DTA5_B is used at runtime for the new IN operation.
   DCL-S dtaara_name varchar(21);
   DCL-S dtaara5 CHAR(100) DTAARA(dtaara_name);

   dtaara_name = 'MYLIB/DTA5';  //  1 
   IN *LOCK dtaara5;            //  2 

   dtaara_name = 'MYLIB/DTA5B'; //  3 
   OUT dtaara5;                 //  4 

   IN *LOCK dtaara5;            //  5