According to WMO 184.108.40.206:
A code table is a list of choices where only one of the choices can be selected at a given time. The selection is accomplished by coding the number of the desired entry in the appropriate place in the GRIB2 Section. A flag table, on the other hand, is a list of choices where any combination of the choices can be selected at a given time. The combination is accomplished by turning bits of a bit string on or off. Code and Flag tables are also categorised by the Section number in which the code or flag table is referred to.
This applies equally well to GRIB1 and also to BUFR.
For example if you do a
grib_dump -O -t on a GRIB2 file, you will see some keys whose type is Code Table ("codetable") and Flag Table ("codeflag"):
Here the shapeOfTheEarth key has type "codetable" so its values come from the entries in Code Table 3.2. The path of the table file relative to the definitions directory is also shown (grib2/tables/4/3.2.table).
And the other key resolutionAndComponentFlags has the type "codeflag" with Flag Table 3.3. We can see which bits of the integer have been set: the 3rd and 4th bits are set and the rest are zero (reading from left to right; most significant bit to least significant). To see the full meaning of those bits, you will need to use the "-D" option of grib_dump:
The "(3=1)" part means the 3rd bit is set and that means "i direction increments given", similarly the 4th bit is set and that means "j direction increments given" and so on. Note that the other bits (1, 2, 6 and 8) are reserved so there is no meaning associated with them.
Note: The content of Flag Table keys should not be interpreted as a value, for that is meaningless in this case. Rather, the individual bits must be inspected. For this reason ecCodes has other keys which correspond to these bits: in the case of resolutionAndComponentFlags, we have the associated keys:
You can query these keys (to decode the flags) as well as set them (to encode the flags).