Question

 IF AWA-REQ-DATE < WS-JULIAN-DATE
    MOVE VAR1 to VAR2

The AWA-REQ-DATE is a binary integer i.e. PIC S9(09) COMP, whereas Julian date is PIC X(10) VALUE SPACES.

Both have Julian date inside them like 2013031 & 2013099.

This gives:

ERROR:REQ-DATE (BINARY INTEGER)" was compared with "WS-JULIAN-date (ALPHANUMERIC)". Discarded

Can I compare then with converting one of them to other format right here in code?

Was it helpful?

Solution

All your four-digit-year Julian dates will contain seven digits. They are dates, so naturally are positive.

It is unclear why you have a nine-digit, signed, binary to hold such or date. Nor a 10-byte alphanumeric. It is also unclear why this should have an initial value of SPACE.

01  WS-JULIAN-DATE                          VALUE SPACE.
    05  WS-JULIAN-DATE-NUM                  PIC 9(7).
    05  FILLER                              PIC XXX.

This assumes all your WS-JULIAN-DATE values are left-aligned.

IF AWA-REQ-DATE < WS-JULIAN-DATE
    MOVE VAR1 to VAR2
END-IF

Hopefully VAR1 and VAR2 are just sample names for the question. If not, please make them meaningful, as it will make it much easier for the next person reading the program to understand. And that might be you.

If the values of WS-... are not guaranteed to be NUMERIC, test them for NUMERIC and take appropriate action (according to your spec) if they are not.

The nine-digit binary will potentially generate extra code beyond what is needed.

Another possibility is:

01  WS-AWA-REQ-JULIAN-DATE                  VALUE SPACE.
    05  WS-AWA-REQ-JULIAN-DATE-NUM          PIC 9(7).
    05  FILLER                              PIC XXX.

MOVE AWA-REQ-DATE                           TO WS-AWA-REQ-JULIAN-DATE-NUM


IF WS-AWA-REQ-JULIAN DATE < WS-JULIAN-DATE
    MOVE VAR1 to VAR2
END-IF

Which you choose can depend on what else you are doing with the fields.

Also, if one is "invariant", convert that to the same format as the variable one, once only.

OTHER TIPS

In the various ISO/ANSI COBOL standards, comparing alphanumeric (PIC X) and numeric (PIC 9) is like comparing apples and oranges. There are defined rules. Of course, each compiler has different ways of interpreting the standard. Therefore, you are best off converting one of the fields to the other format and comparing those. Bill Woodger has some good comments about which field to convert, and how.

In summary, you should always compare like data types. For numeric items, it's best if you can compare the same COMP format, but sometimes this can't be done. If that is the case, you need to read your compiler documentation to see how comparisons are performed between different computational types, and any gotchas (such as COMP-4 and COMP-5 in IBM's Enterprise COBOL).

The answer probably depends on which compiler you are using. On GNU Cobol, the comparison works after applying FUNCTION NUMVAL to the Julian (text) date.

As the error message is describing: a numeric value PIC S9(9) COMP cannot be compared to a string PIC X(10).

A COMP variable is a system dependent, numeric representation of the value. There are variations to the internal representation (binary, BCD,...) used for COMPutation. The value of your date is,depending on the machine though, internally represented as: 0011110 10110111 01100111

Display variables are storing each position of your variable according to an encoding standard (ASCII, EBCDIC, UNICODE). Again depending on your machine and the encoding table, the representation of your variable might be: 00110010 00110000 00110001 00110011 00110000 00111001 00111001

I do some guessing here in order to address the underlying problem

First guess: The alpha definition PIC X(10) looks like the date is in printing format and should contain separators in order to make it 10 characters long

21.02.2014
123456789A

Such a variable shouldn't hold a julian date after all and you probably need a date comparing function.

Second guess: for some displaying reason, you want to have a variable of 10 characters long, holding the julian date in the first 7 characters. In this case, I'd define a structure and you can keep your comparison as is:

01  WS-JULIAN-DATE-PRINT                    VALUE SPACE.
    05  WS-JULIAN-DATE                 PIC 9(7).
    05  FILLER                         PIC X(3).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top