Title: How do I resolve a compile error on PIC X(2) USAGE COMP-5?

When I compile a program that has PIC X(2) USAGE COMP-5 I get the following compile error:

--S: Invalid clause USAGE; file = test.cbl, line = 5, col 25

Why do I get this error?
How do I resolve this problem? To what should I change the picture or usage?


In accordance with ANSI and IBM standards, isCOBOL does not allow using "X" in the PICTURE of a numeric item (See below). 

In Micro Focus COBOL, the number of "x"s gives the length of the item in bytes for PIC X(n) COMP-5. PIC X(2) COMP-5 is equivalent to PIC 9(4) COMP-5 since they are both 2 byte COMP-5 numeric items

This means that you can fix your compile error by changing "PIC X(2)" to "PIC 9(4)".

Micro Focus COBOL Language Reference / Concepts of the COBOL Language / Class and Category of Data says:


These formats are as for COMPUTATIONAL format except for the differences given below. See the section COMPUTATIONAL, BINARY, or COMPUTATIONAL-4 Format. 

They both differ in the following ways from the COMPUTATIONAL format: 

The PICTURE character-string can consist of all "x"s. If it does, the number of "x"s gives the length of the item in bytes. 

The ANSI standard says:

An elementary data item whose declaration contains, or an elementary data item subordinate to a group item whose declaration contains, a USAGE clause specifying BINARY, COMPUTATIONAL, or PACKED-DECIMAL shall be specified only with a picture character-string that describes a numeric item.


To define an item as numeric, character-string-1
shall include at least one symbol '9', and
may contain a combination of symbols from the set 'P', 'S', and 'V'.

Enterprise COBOL for z/OS says:

For numeric date fields, the PICTURE character-string can contain only the symbols 9 and S. For all other numeric fields, the PICTURE character-string can contain only the symbols 9, P, S, and V.

Alphanumeric items

The PICTURE character-string must consist of either of the following:

One or more occurrences of the symbol X. 

Combinations of the symbols A, X, and 9. (A character-string containing all As or all 9s does not define an alphanumeric item.) 

The item is treated as if the character-string contained only the symbol X.

The contents of the item in standard data format can be any allowable characters from the character set of the computer.

Other clauses
USAGE DISPLAY must be specified or implied.
Authored by: Veryant Support on Mon, Aug 31st, 2009 at 7:00 PM
This question has been viewed 11550 times so far.
Online URL: http://support.veryant.com/support/phpkb/question.php?ID=59

Powered by PHPKB Knowledge Base Software