Table of contents

 

The constant operator specifies that the field value will always be given value.
This value is never transferred in the message itself, but is suppressed by the encoder and replaced by the decoder.
An example of this might be 8=FIX.4.4, where you would never sent FIX.4.4 over the wire.
If optional, the field will use a PMap bit. If not set, the field will not be present in the output message.
The decoding algorithm of template fields using the Constant operator:

Decoding algorithm of fields with Constant Operator

Picture 3.9 - "Decoding algorithm of fields with Constant Operator"

Here's an example implementation of the above algorithm in java:  

public int decode(byte[] encodedData, int offset,
                  PresenceMap presenceMap, OutputMessage message) {
    if (isMandatory || (isPMapBitExist() && presenceMap.isNextPMapBitSet())) {
        message.addValue(tagId, initialValue);
    }
    return offset;
}   
 
public void reset() {
    // Constant field never use the previous value
}
 
public boolean isPMapBitExist() {
    // If isMandatory true the Constant field do not require a presence map bit.
    // Otherwise it is require the presence map bit.
    return !isMandatory;
}
 
public boolean isFieldNullable() {
    // Constant field is not nullable
    return false;
}