Page History: Thunder Special Fields
Compare Page Revisions
Page Revision: 2016/05/24 17:21
Thunder makes use of “Special Fields” to:
- Provide additional information found by Readers when parsing and
- Allow for greater control of JSON/XML output by Writers.
Thunder provides 5 special fields.
1. Optional Field Flag – to indicate if an optional field is populated (for Readers), or if it should be output (for Writers)
2. Counter Field for repeating structures – to indicate how many occurrences were found (Readers) or how many should be output (Writers)
3. Length field 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)
4. Track Pointer fields – to indicate the start and end position of an element or attribute (for Readers)
5. Floating Point fields - for control of decimal precision for decimal fields
Special fields can be controlled at the Default level, Handler level or node level.
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 JSON/XML structure. Below is an IDS containing the 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:
• 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.Optional Flag Field
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 by a 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 the initialized value.
• Passed to a Writer 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.Length Field
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 written out for the node. Track Pointers
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. Extended Precision
The extended precision special field is used 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.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”
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.