You are here: Functions > OFFSET()

OFFSET()

OFFSET() adjusts the starting position of a field within the current record. The OFFSET() function is most commonly used in Analyzer procedures.

Use OFFSET() to process repeating data, such as that defined with a COBOL OCCURS clause.You can also use OFFSET() in very complex record structures (such as IBM SMF files), in which a block of data has a variable starting position or an array has a variable number of values.

Function Format

OFFSET(Field_name,N)

The OFFSET() function temporarily offsets the starting position of a field by N, where N is any valid numeric expression.

Note: If the offset field extends beyond the end of the record, the OFFSET() function returns a blank or zero value as appropriate.

Note: Be careful when using the OFFSET() function with conditional fields, because the fields referred to in the If test will also be offset.

An alternate approach to using the OFFSET() function is to use field arrays. For more information, see Field Arrays.

Examples

Given record “1234567890” and numeric field X starting in position 1 with a length of 3 and no decimals (with a default value of 123):

OFFSET(X,1) = 234

OFFSET(X,6) = 789

If a record contains a variable length field followed by another field X, use OFFSET() to define the field location. Assume field L contains the length of the variable field and that you have already used the Table Layout window to define field X as starting in position 54 if L is zero. To read the contents of field X, define the following field:

OFFSET(X,L)