XML and JSON Thunder make use of “special fields” to:
- Provide additional information found by XML Readers when parsing, and
- Allow for greater control of XML/JSON output by Writers.
Thunder provides 5 special fields.
- Optional Flag – to indicate if an optional field is populated (for Readers), or if it should be output (for Writers).
- Counter - for repeating structures – to indicate how many occurrences were found (Readers) or how many should be output (Writers).
- Length - for variable length fields – to indicate the length of a field found (for Readers) or how many characters of the field to output (for Writers).
- Track Pointer – to indicate the start and end position of an element or attribute (for Readers).
- Floating Point - for control of decimal precision for decimal fields.
A special field exists in the program data fields (IDS) that make up the API into the Handler, but they do not exist in the XML structure. Below is an IDS containing all 5 special field types.
The counter special field is used to control repeating structures. A counter field is automatically inserted into the IDS for each repeating structure in the Handler Design. The counter field is:
Optional Flag Field
- Returned by a Reader to indicate the number of occurrences found in the JSON/XML instance being parsed. For a document-level handler, the counter field will contain the total number of occurrences found. For a node-level handler, the counter field will indicate if the Handler is returning the last occurrence of a repeating structure (count = 1) or if there are still more to be returned(count > 1).
- Passed to a Writer to indicate how many occurrences of a repeating structure should be written out. For a document-level handler, the counter field will contain the total number of occurrences to write out. For a node-level handler, the counter field will indicate if the Handler is receiving the last occurrence of a repeating structure or if there are still more to write out.
When the Optional Flag Field property is set to “true” for a node, then the generated IDS will contain an additional “flag field” that is associated with the node.
This property can only be set for non-repeating optional nodes.
For an optional repeating node, the count special field can be used. An optional flag field is:
- Returned bya Reader to indicate if a node was found in the JSON/XML instance. If the flag value is set to 1, the node was found and the content returned in the IDS field is the content found in the document. If the flag value is 0, then the node was not found and the content returned in the IDS field is theinitialized value.
- Passed to aWriter to indicate if an optional node should be suppressed or not. If the flag value is set to 1, then the node will be written out. If the flag is set to 0, the node will not be written out.
The length field is used to control the length of a variable length field. If the variable length property is set to “true” for a node, then a length field is automatically inserted into the IDS for the corresponding program data field. The length field is:
- Returned by a Reader to indicate the length of the field read.
- Passed into a Writer to indicate how many characters of the content should be writtenout for the node.
Track Pointers are used to indicate the start position of the open tag and the end position of a closing tag for a node. If the Track Pointers property is set to “true”, then 2 fields (one for the starting position and one for the end) will be automatically inserted in the IDS for the corresponding program data field.
Track pointers are only used by Readers.
The Reader will return the start and end position of the particular JSON/XML node.
The extended precision special field is used by a Writer to control the decimal precision for a numeric field containing decimals. When the property is set to “true”, an extended precision field is automatically inserted into the IDS and the original field is converted to an integer definition (with no decimal places). For example, a field with a COBOL declaration of PIC 9(11)V9(2) will convert to two fields:
- One with a declaration of PIC 9(13) to hold all digits in the content (integer and decimal).
- One with a declaration of PIC S9(3) to hold how many decimal positions the value contains (e.g. -3 indicates that there are 3 decimal positions.
The extended precision field is returned by a Reader to indicate how many decimal positions were found in the document.
Turning Special Field Settings On
Special fields can be controlled at the Toolset level, Handler level and node level. The Count special field is always added to a Handler for repeating structures. All other special fields can be turned on or off. Toolset Level
Toolset level settings apply to all new handlers that are created. Changing a toolset setting does not affect Handlers that have already been created. There are two special fields that can be set as toolset defaults – Optional Field Flags and Extended Precision fields. These can be set by going to Tools -> Default Properties - > Code Generation -> General.Handler Level
Handler level settings apply to the currently opened handler. Changing a Handler setting changes the default settings for the Handler. The special field settings that can be changed are extended precision and Optional Flags. This is done by going to XML Handler -> Properties -> Code Generation -> GeneralNode Level
Node level settings apply only to the selected XML/JSON node. The Variable Length, Optional Flag and Track Pointer special fields can be selected at the node level. This is done by selecting a node and changing the setting under Generation Settings.
Generating Special Fields to a Separate Area in the IDS
Thunder allows you to control how the special fields are generated into the IDS. By default, they are generated directly above their associated field as shown below.
If desired, Thunder provides a setting to generate the special fields to a separate area in the IDS. This can be set at the Toolset or Handler level.
To generate special fields to a separate area at the Handler level, go to Handler -> Properties -> Code Generation and choose “More Options”
You can also do this from the Code Generation panel (you need to check “copybook” to enable “More Options”)
Change the Special field setting to “Generate as a separate structure”.
The result will be that that the special fields will be generated to their own separate 01 level in the IDS.
Thunder Special Fields can be used for greater program control over XML / JSON messages. For more information about Thunder Special Fields, please contact us at firstname.lastname@example.org