IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Difference bw EQUAL and EQUAL TO in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jithinraghavan

New User


Joined: 15 Apr 2018
Posts: 4
Location: United States

PostPosted: Thu Apr 19, 2018 2:22 am
Reply with quote

I've declared the below 2 fields in my cobol program

Code:
01  CLM-DETAIL1.                                           
  05  LINE-ITEM1                                           
              OCCURS 0050 TIMES                                   
              INDEXED BY LINE-ITEM1X.                     
    10  LINE-ITEM-CODE1                                   
              COMP-3       PIC 9(03).                             
    10  FIRST-DATE-OF-SVC1                             
              COMP-3       PIC S9(5).                             
    10  LAST-DATE-OF-SVC1                               
              COMP-3       PIC S9(5).                             
    10  CLM-PRIOR-AUTH-IND1         
                           PIC X(1).           

01  CLM-DETAIL2.                                           
  05  LINE-ITEM2                                           
              OCCURS 0050 TIMES                                   
              INDEXED BY LINE-ITEM2X.                     
    10  LINE-ITEM-CODE2                                   
              COMP-3       PIC 9(03).                             
    10  FIRST-DATE-OF-SVC2                             
              COMP-3       PIC S9(5).                             
    10  LAST-DATE-OF-SVC2                               
              COMP-3       PIC S9(5).                             
    10  CLM-PRIOR-AUTH-IND2         
                           PIC X(1).


When I do a compare between these fields with the below 2 if statements, I 'm getting different results. It's compiling successfully with both statements but the results are different.
Is there any difference in these statements really?

1. IF CLM-DETAIL1 NOT EQUAL CLM-DETAIL2
DISPLAY 'X'
END-IF

2. IF CLM-DETAIL1 NOT EQUAL TO CLM-DETAIL2
DISPLAY 'X'
END-IF
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Apr 19, 2018 5:58 am
Reply with quote

In the version 5.1 Enterprise COBOL Language Reference manual, on page 260, the syntax diagram for the conditional statement is provided. It explicitly states that NOT EQUAL and NOT EQUAL TO are treated by the compiler as identical conditions. Just as IS NOT EQUAL TO is equivalent to NOT EQUAL -- COBOL allows some words to be inserted for readability.

If you're getting different results, then something is not the same. Are the different results in the same program or different programs? For testing purposes, you should code the two statements one after the other in the same program, compile it (do not use the optimization option!), and show us the results.
Back to top
View user's profile Send private message
jithinraghavan

New User


Joined: 15 Apr 2018
Posts: 4
Location: United States

PostPosted: Thu Apr 19, 2018 10:04 pm
Reply with quote

I've declared 2 fields CLM-DETAIL1 and CLM-DETAIL2 with exactly same data except difference in CLM-PRIOR-AUTH-IND(1) field.

CLM-DETAIL1 -> CLM-PRIOR-AUTH-IND1(1) = 'Y'
CLM-DETAIL2 -> CLM-PRIOR-AUTH-IND2 (1) = SPACES

In my cobol program
Code:
IF CLM-DETAIL1 NOT EQUAL CLM-DETAIL2
    DISPLAY 'X'
END-IF


shows no display in sysout
and when I changed if statement in the same COBOL program as below, I got X in my SYSOUT which is correct and I don't know why it is not showing any sysout while using the first IF statement.
Code:
IF CLM-DETAIL1 NOT EQUAL TO CLM-DETAIL2
    DISPLAY 'X'
END-IF
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Apr 19, 2018 10:11 pm
Reply with quote

You seem to think the TO is making a difference to your program. It is not -- period. The COBOL compiler treats the TO as optional. To show this, look at the pseudo-assembler output generated by the LIST option and you will see the code is the same with or without the TO.

Topic locked as a waste of time; COBOL will not treat NOT EQUAL TO any differently than NOT EQUAL.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top