The ALPHA XFD directive allows you to treat a data item as alphanumeric text in the database, when it is declared as numeric in the COBOL program.
This is especially useful when you have numeric keys in which you occasionally store non-numeric data, such as LOW-VALUES or special codes. In this situation, treating the field as alphanumeric allows you to move any kind of data to it.
Suppose you have specified KEY IS code-key. Then assume the following record definition:
01 code-record. 03 code-key. 05 code-num pic 9(5).
In the database, group items are disregarded, so CODE-NUM is the actual key field. Suppose you needed to move a non-numeric value to the key:
MOVE "C0531" TO CODE-KEY. WRITE CODE-RECORD.
In this case the results are not well-defined because a non-numeric value has been moved into a numeric field. The database might very well reject the record.
One way to solve this problem is to use the ALPHA XFD directive. This causes the corresponding database field to accept alphanumeric data:
01 code-record. 03 code-key. $XFD ALPHA 05 code-num pic 9(5).
As an alternative, you could specify the USE GROUP XFD directive on the line before code-key. The USE GROUP XFD directive implies that the field is alphanumeric.