Search code examples
cobolmainframe

Compare BINARY INTEGER variable with ALPHANUMERIC variable in COBOL


 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?


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.