The XML GENERATE statement converts data to XML format.
General Format
when-phrase
generic-suppression-phrase
Syntax Rules
- Identifier-1 must be an alphanumeric or national data item. It must not be described with the JUSTIFIED clause, and cannot be a function identifier.
- Identifier-1 can be subscripted or reference modified.
- Identifier-1 must not overlap identifier-2 or identifier-3.
- Identifier-1 must be a national data item if the generated XML includes data from identifier-2 for:
- Any national data item or DBCS data item
- Any data item with a DBCS name (that is, a data item whose name contains DBCS characters)
- An alphanumeric data item that contains DBCS characters
- Identifier-2 cannot be a function identifier or be reference modified.
- Identifier-2 can be subscripted.
- Identifier-2 must not overlap with identifier-1 or identifier-3.
- Identifier-2 must not specify the RENAMES clause.
- All data items specified by identifier-2 that are not ignored according to
General Rule 5 must satisfy the following conditions:
- Each elementary data item must either have class alphabetic, alphanumeric, numeric, or national, or be an index data item. That is, no elementary data item can be described with the USAGE POINTER, USAGE FUNCTION-POINTER, USAGE PROCEDURE-POINTER, or USAGE OBJECT REFERENCE phrase.
- There must be at least one such elementary data item.
- Each non-FILLER data-name must be unique within any immediately superordinate group data item.
- Identifier-3 must be an integer data item defined without the symbol P in its picture string.
- Identifier-3 must not overlap identifier-1 or identifier-2.
- codepage must be an unsigned integer data item or unsigned integer literal and must represent a valid coded character set identifier (CCSID).
- identifier-4 and identifier-5 must reference data items of category alphanumeric or national.
- identifier-4 and identifier-5 must not overlap identifier-1 or identifier-3.
- literal-4 and literal-5 must be of category alphanumeric or national, and must not be figurative constants.
- identifier-6 must reference identifier-2 or one of its subordinate data items. It cannot be a function identifier and cannot be reference modified or subscripted. It must not specify any data item which is ignored by the XML GENERATE statement. For more information about identifier-2, see the description of identifier-2.
- literal-6 must be an alphanumeric or national literal containing the attribute or element name to be generated in the XML document corresponding to identifier-6.
- If literal-6 is a national literal, identifier-1 must reference a data item of category national.
- identifier-7 and identifier-8 must reference an elementary data item that is subordinate to identifier-2. They must not specify any data item which is ignored by the XML GENERATE statement. They cannot be function identifiers and cannot be reference modified or subscripted. For more information about identifier-2, see the description of identifier-2.
- If ZERO, ZEROES, or ZEROS is specified in the WHEN phrase, identifier-8 or all the data items that are identified by the generic-suppression-phrase must not be of USAGE DISPLAY-1.
- If SPACE or SPACES is specified in the WHEN phrase, identifier-8 or all the data items that are identified by the generic-suppression-phrase must be of USAGE DISPLAY, DISPLAY-1 or NATIONAL.
- If LOW-VALUE, LOW-VALUES, HIGH-VALUE, or HIGH-VALUES is specified in the WHEN phrase, identifier-8 or all the data items that are identified by the generic-suppression-phrase must be of class alphanumeric or national.
General Rules
- Identifier-1 is the receiving area for a generated XML document.
- If identifier-1 is a national data item, the generated XML document is encoded in UTF-16.
- Identifier-1 must be large enough to contain the generated XML document. Typically, it should be from five to eight times the size of identifier-2, depending on the length of the data name or data names within identifier-2. If identifier-1 is not large enough, an error condition occurs at the end of the XML GENERATE statement.
- Identifier-2 is the group or elementary data item to be converted to XML format.
- The following data items specified by identifier-2 are ignored by the XML GENERATE statement:
- Unnamed elementary data items or elementary FILLER data items
- Slack bytes inserted for SYNCHRONIZED items
- Data items subordinate to identifier-2 that are described with the REDEFINES clause or that are subordinate to such a redefining item
- Data items subordinate to identifier-2 that are described with the RENAMES clause
- Group data items all of whose subordinate data items are ignored
- The content of each eligible elementary data item within identifier-2 is converted to character format as described below. The converted content is then inserted as element character content in XML markup. The XML element names are derived from the data names within identifier-2. The names of group items that contain the selected elementary items are retained as parent elements. No extra white space (new lines, indentation, etc.) is inserted to make the generated XML more readable. The exact mixed-case spelling of data names from the data description entry is retained and data names that start with a digit are prefixed by an underscore.
Note: The exact mixed-case spelling of data names from the data description entry is retained only if you specify the PRESERVECASE directive.
- Elementary data items are converted to character format depending on the type of the data item:
- Alphabetic, alphanumeric, alphanumeric-edited, DBCS, external floating-point, national, and numeric-edited items are not converted.
- Fixed-point numeric data items other than COMPUTATIONAL-5 (COMP-5) binary data items are converted as if they were moved to a numeric-edited item that has:
- As many integer positions as the numeric item has, but with at least one integer position
- An explicit decimal point, if the numeric item has at least one decimal position
- The same number of decimal positions as the numeric item
- A leading '-' picture symbol if the data item is signed
- COMPUTATIONAL-5 (COMP-5) binary data items are converted in the same way as the other fixed-point numeric items except for the number of integer positions. The number of integer positions is computed depending on the number of '9' symbols in the picture character string as follows:
- 5 minus the number of decimal places, if the data item has one to four '9' picture symbols
- 10 minus the number of decimal places, if the data item has five to nine '9' picture symbols
- 20 minus the number of decimal places, if the data item has 10 to 18 '9' picture symbols
- Internal floating-point data items are converted as if they were moved to a data item as follows:
- For COMP-1: an external floating-point data item with PICTURE -9.9(8)E+99
- For COMP-2: an external floating-point data item with PICTURE -9.9(17)E+99
- Index data items are converted as if they were declared USAGE COMP-5 PICTURE S9(9).
- If identifier-1 is a national data item, any non-national values are converted to national format.
- After any conversion to character format, leading and trailing spaces and leading zeroes are eliminated as follows:
- For values converted from signed numeric values, the leading space is removed if the value is positive.
- For values converted from numeric items, leading zeroes (after any initial minus sign) up to but not including the digit immediately before the actual or implied decimal point are eliminated. Trailing zeroes after a decimal point are retained. For example:
- -012.340 becomes -12.340
- 0000.45 becomes 0.45
- 0013 becomes 13
- 0000 becomes 0
- Character values from alphabetic, alphanumeric, DBCS, and national data items have either trailing or leading spaces removed, depending on whether the corresponding data items have left (default) or right justification, respectively. That is, trailing spaces are removed from values whose corresponding data items do not specify the JUSTIFIED clause. Leading spaces are removed from values whose data items do specify the JUSTIFIED clause. If a character value consists only of spaces, one space remains as the value after trimming is finished.
- If a data item after any conversion contains any characters that are illegal in XML content, the original data value - the value in the data item before any conversion or trimming - is represented in hexadecimal, and an element tag name with the prefix
hex. is substituted for the regular tag name. For example, if data item
My-Name is found at run time to contain LOW-VALUES, the XML element tag name
hex.My-Name is used instead, and the content is represented as a string of pairs of zero digits.
- If a data item after any conversion contains instances of any of the following the five symbols:
- & (ampersand)
- ' (apostrophe)
- > (greater-than sign)
- < (less-than sign)
- " (quotation mark)
the symbols are converted into the equivalent XML references
&,
',
>,
<, and
", respectively.
- If identifier-1 is longer than the generated XML document, only that part of identifier-1 in which XML is generated is changed. The rest of identifier-1 contains the data that was present before this execution of the XML GENERATE statement. To avoid referring to that data, either initialize identifier-1 to spaces before the XML GENERATE statement or specify the COUNT IN phrase.
- If the COUNT IN phrase is specified, identifier-3 contains (after execution of the XML GENERATE statement) the count of generated XML character positions. If identifier-1 (the receiver) is a national data item, the count is in national character positions (UTF-16 character encoding units). Otherwise, the count is in bytes.
- The ENCODING phrase is documentary only.
- If the XML-DECLARATION phrase is specified, the generated document starts with an XML declaration that includes the XML version information and an encoding declaration. If identifier-1 is of category national, the encoding declaration has the value UTF-16 (encoding="UTF-16" ). If the XML-DECLARATION phrase is omitted, the generated XML document does not include an XML declaration.
- If the ATTRIBUTES phrase is specified, each eligible item in the generated document is expressed as an attribute of the XML element that corresponds to the data item immediately superordinate to that eligible item (and not as a child element of the XML element). To be eligible, a data item must be elementary, must have a name other than FILLER, and must not specify an OCCURS clause in its data description entry.
- The NAMESPACE phrase identifies a namespace for the generated XML document. If the NAMESPACE phrase is not specified, or if identifier-4 has length zero or contains all spaces, the element names of XML documents produced by the XML GENERATE statement are not in any namespace.
- The NAMESPACE-PREFIX phrase identifies a prefix to qualify the start and end tag of each element in the generated XML document.
- If the NAMESPACE-PREFIX phrase is not specified, or if identifier-5 is of length zero or contains all spaces, the NAMESPACE phrase specifies the default namespace for the document. In this case, the namespace declared on the root element applies by default to each element name in the document, including that of the root element.
- If the NAMESPACE-PREFIX phrase is specified, and identifier-5 is not of length zero and does not contain all spaces, then the start and end tag of each element in the generated document is qualified with the specified prefix. When the XML GENERATE statement is executed, the prefix must be a valid XML name, but without the colon (:). The prefix can have trailing spaces, which are removed before use.
-
The NAME phrase allows you to supply element and attribute names. If identifier-6 is specified more than once in the NAME phrase, the last specification is used. literal-6 must be a valid XML local name.
-
The TYPE phrase allows you to control attribute and element generation. If identifier-7 is specified more than once in the TYPE phrase, the last specification is used.
- If the XML GENERATE statement also includes a WITH ATTRIBUTES phrase, the TYPE phrase has precedence for identifier-7.
- When ATTRIBUTE is specified, identifier-7 must be eligible to be an XML attribute. identifier-7 is expressed in the generated XML as an attribute of the XML element immediately superordinate to identifier-7 rather than as a child element.
- When ELEMENT is specified, identifier-7 is expressed in the generated XML as an element. The XML element name is derived from identifier-7 and the element character content is derived from the converted content of identifier-7 as described in Operation of XML GENERATE.
- When CONTENT is specified, identifier-7 is expressed in the generated XML as element character content of the XML element that corresponds to the data item immediately superordinate to identifier-7. The value of the element character content is derived from the converted content of identifier-7 as described in Operation of XML GENERATE. When CONTENT is specified for multiple identifiers all corresponding to the same superordinate identifier, the multiple contributions to the element character content are concatenated.
-
The SUPPRESS phrase allows you to identify items that are subordinate to identifier-2 and must be suppressed when generating the XML if they contain values that are specified in the WHEN clause.
If the SUPPRESS phrase is specified, identifier-1 must be large enough to contain the generated XML document before any suppression.
With the generic-suppression-phrase, elementary items subordinate to identifier-2 that are not otherwise ignored by XML GENERATE operations are identified generically for potential suppression. Either items of class numeric, if the NUMERIC keyword is specified, or items that are not of class numeric, if the NONNUMERIC keyword is specified, or both, may be suppressed. If the ATTRIBUTE keyword is specified, only items that would be expressed in the generated XML document as an XML attribute are identified for potential suppression. If the ELEMENT keyword is specified, only items that would be expressed in the generated XML document as an XML element are identified. If multiple generic-suppression-phrase are specified, the effect is cumulative.
identifier-8 explicitly identifies items for potential suppression. If identifier-8 is specified more than once in the SUPPRESS phrase, the last specification is used. The explicit suppression specification for identifier-8 overrides the suppression specification that is implied by any generic-suppression-phrase, if identifier-8 is also one of the identifiers generically identified.
- An exception condition exists when an error occurs during generation of the XML document, for example if identifier-1 is not large enough to contain the generated XML document. In this case, XML generation stops and the content of the receiver, identifier-1, is undefined. If the COUNT IN phrase is specified, identifier-3 contains the number of character positions that were generated, which can range from 0 to the length of identifier-1. If the ON EXCEPTION phrase is specified, control is transferred to imperative-statement-1. If the ON EXCEPTION phrase is not specified, the NOT ON EXCEPTION phrase, if any, is ignored and control is transferred to the end of the XML GENERATE statement. Special register XML-CODE contains an exception code.
- If an exception condition does not occur during generation of the XML document, control is passed to imperative-statement-2, if specified. Otherwise, it is passed to the end of the XML GENERATE statement. The ON EXCEPTION phrase, if specified, is ignored. Special register XML-CODE contains zero after execution of the XML GENERATE statement.