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

Am getting Error in IF Statement


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

New User


Joined: 07 Feb 2007
Posts: 27
Location: chennai

PostPosted: Tue Apr 03, 2012 4:06 pm
Reply with quote

Code:
If ((S-DATE1   =  WS-START-DATE1         AND         
     WS-S-TIME <  WS-START-TIME(IDX))    OR           
    (S-DATE1   =  WS-END-DATE1           AND         
     WS-S-TIME >  WS-END-TIME(IDX))      OR           
    (S-DATE1   <  WS-START-DATE1         OR           
     S-DATE1   >  WS-END-DATE1)          OR           
    (S-DATE1   >  WS-START-DATE1         AND         
     S-DATE1  <> WS-END-DATE1)           OR           
    (S-DATE1  <> WS-START-DATE1         AND           
     S-DATE1   <  WS-END-DATE1))             


A literal or an expression was expected following a relational operator, but '>' was found , th if statement was discarded.

Please help me to get this done
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 03, 2012 4:18 pm
Reply with quote

Please use the Code tags.

Where did you find "<>" in the Enterprise Cobol manual?
Back to top
View user's profile Send private message
arunmozhicholan

New User


Joined: 07 Feb 2007
Posts: 27
Location: chennai

PostPosted: Tue Apr 03, 2012 4:40 pm
Reply with quote

Need to use not equal to ...?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 03, 2012 5:03 pm
Reply with quote

Well, yes.

You have yourself an unreadable IF as well. You need to do some work to improve it.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Tue Apr 03, 2012 5:22 pm
Reply with quote

Are there no other COBOL programs at your company to review?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Apr 03, 2012 6:04 pm
Reply with quote

Years ago, when I did code review, I would hand this back to you and have you redo it.

There were times that in order to understand similar code, I'd have to generate the Assembler expansion, which occasionally ended in multiple right parenthesis. icon_eek.gif

You need to think of the next person who may need to do maintenance on this spaghetti salad. icon_rolleyes.gif

What about EVALUATE or nested IF's?

Software Engineer's shouldn't be writing crap like this....
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue Apr 03, 2012 6:51 pm
Reply with quote

Code:
.
.
.
S-DATE1 <> WS-END-DATE1) OR
.
That's not how you use "NOT EQUAL TO" in COBOL. For COBOL it's
Code:
IF A NOT EQUAL B THEN
.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 03, 2012 6:52 pm
Reply with quote

Code:
           IF (
                (
                    ( S-DATE1   EQUAL TO  WS-START-DATE1 )
                AND ( WS-S-TIME LESS THAN WS-START-TIME ( IDX ) )
                )
           OR   (
                    ( S-DATE1   EQUAL TO     WS-END-DATE1 )
                AND ( WS-S-TIME GREATER THAN WS-END-TIME ( IDX ) )
                )
           OR   (
                    ( S-DATE1   LESS THAN    WS-START-DATE1 )
                OR  ( S-DATE1   GREATER THAN WS-END-DATE1 )
                )
           OR   (
                    ( S-DATE1   GREATER THAN WS-START-DATE1 )
                AND ( S-DATE1   NOT EQUAL TO WS-END-DATE1 )
                )
           OR   (
                     ( S-DATE1  NOT EQUAL TO WS-START-DATE1 )
                AND  ( S-DATE1  LESS THAN    WS-END-DATE1 )
                )
              )


Even after "tarting it up" it is still very clumsy. Take some of Mr Bill's good advice.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue Apr 03, 2012 7:00 pm
Reply with quote

Kept the thread open longer than anticiapted and missed the excellent suggestion from Bill O'Boyle. Read his post and try to implement.
Back to top
View user's profile Send private message
Ed Goodman

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Tue Apr 03, 2012 7:00 pm
Reply with quote

Been coding several decades. My weakest skill is working with date checking statements just like this one. I think they cause more confusion than any other type of condition checking.

I will spend two hours breaking them into nested IFs or Evaluate statements. usually when I'm done, I find that there is a much smaller way to do it. It's like factoring a large equation, then letting things cancel out.
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 Error to read log with rexx CLIST & REXX 11
No new posts Error when install DB2 DB2 2
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts Error while running web tool kit REXX... CLIST & REXX 5
No new posts Getting Error while trying to establi... DB2 3
Search our Forums:

Back to Top