%DATA (document {:options})

%DATA is used as the second operand of the DATA-INTO and DATA-GEN operations. %DATA does not return a value, and it cannot be specified anywhere other than for the DATA-INTO and DATA-GEN operation codes.

The first operand of %DATA identifies the document. It can be a constant or variable character or UCS-2 expression.

The second operand of %DATA specifies options that control the operation. It can be a constant or variable character expression. See Specifying the options for %DATA.

For the DATA-INTO operation
  • %DATA specifies the document to be parsed, and the options to control how the information from the document is placed in the target RPG variable.
  • The first operand can be a constant or variable character or UCS-2 expression. containing either an document or the name of a file containing a document.
  • The second operand of %DATA specifies options that control how the document is to be interpreted, and how the data from the document is to be placed in the RPG variable.

    See %DATA options for the DATA-INTO operation code for a complete list of valid options and values.

For the DATA-GEN operation
  • %DATA specifies the location for the document to be placed, and the options to control how the document is generated from the RPG variable in the first operand of DATA-GEN.
  • The first operand can be a constant or variable character or UCS-2 expression. If the "doc=file" option is specified, it is the name of the file to receive the generated document. If the "doc=file" option is not specified, the generated document is placed in the variable.
  • The second operand of %DATA specifies options that control how the document is to be generated, and how the data from the RPG variable is to be passed to the generator.

    See %DATA options for the DATA-GEN operation code for a complete list of valid options and values.

Specifying the options for %DATA

The value of the character expression is a list of zero or more options specified in the form
optionname1=value1 optionname2=value2
No spaces are allowed between the option name and the equal sign or between the equal sign and the value. However, any number of spaces can appear before, between or following the options. The options can be specified in any case. The following are all valid ways to specify the "doc=file" and "allowextra=yes" options for DATA-INTO:
   'doc=file allowextra=yes'
   '        doc=file     allowextra=yes     '
   'ALLOWEXTRA=YES DOC=FILE     '
   'AllowExtra=Yes Doc=File     '
The following are not valid option strings:
Option string The problem with the option string
'doc = file' Spaces around the equal sign are not allowed
'allowextra' Each option must have an equal sign and a value
'badopt=yes' Only valid options are allowed
'allowextra=ok' The 'allowextra' value can only be 'yes' or 'no'
When an option is specified more than once, the last value specified is the value that is used. For example, if the "options" operand has the value
   'doc=file doc=string'
then the parser will use the value "string" for the "doc" option.

If the parser discovers an invalid option or invalid value, the operation will fail with status code 00352.

Examples of %DATA

The "options" operand is omitted. Default values are used for all options. Since the default value for the "doc" option is always "string", the parser will correctly assume that the first operand contains the text of a document. The example assumes an imaginary language in the form "itemName=itemValue".

document = 'city=Toronto';
DATA-INTO city %DATA(document) %PARSER(p);
The "options" operand is specified as a literal with two options.

DATA-INTO myds %DATA(document : 'allowmissing=yes allowextra=yes')
          %PARSER(p);
The "options" operand is specified as a variable expression with two options.

ccsidOpt = 'ccsid=ucs2';
DATA-INTO %HANDLER(mySaxHandler : myCommArea)
          %DATA('mydoc.txt' : 'doc=file ' + ccsidOpt)
          %PARSER(p);

For more examples of %DATA, and more information about the DATA-INTO and DATA-GEN operations, see DATA-INTO (Parse a Document into a Variable) and DATA-GEN (Generate a Document from a Variable).