Segment data casts variable—Data extract expressions


In the absence of a named field in a segment, a cast must be used to refer to segment data by specifying its starting position, length in bytes, and optionally its data type.

The cast specification is coded following the segment name. When the segment name is the current segment, it can be omitted.

The syntax of a cast is:

(s:l t)
  • s is the starting position within the segment relative to position one.
  • l is the length of the data in bytes.
    If l is specified as an asterisk (*), the length of the data is taken from the starting location through the last byte of the segment.
    An asterisk can only be used for the length for the character data type.
  • t is the data type
    The data type is optional and defaults to character (C) if not specified.
    The valid data types are:
    • C (character string data)
    • F (fixed point binary numeric data)
    • P (packed decimal numeric data)
    • U (unsigned packed decimal numeric data)
    • X (hexadecimal data)
    • Z (zoned decimal numeric data)

The parentheses enclosing a cast are optional. They are often included to improve readability. Blanks can be used wherever desired within a cast specification.

If the first and last bytes of the segment data as specified bys:l fall outside the bounds of the segment as defined by the DBDGEN, or the actual end of a variable length segment, an error occurs.

If data specified by a cast is to be used in an expression, it is important that the data type agree with the actual type of the data in the segment so that the correct data conversions are performed. Failure to specify the correct data type can result in runtime errors when performing a calculation. For example, if a cast indicates that the data is packed when in fact it is zoned, and you attempt to perform an arithmetic operation on this data, an error will occur.

Example
SEG100(5:4F)
BEGINFO  8:6  P
(1:99C)
6:3Z

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*