how to compare 3 variables



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

how to compare 3 variables

Postby rick5952 » Fri Jun 29, 2012 11:15 pm

I have a req. to compare three variables(dates) and do some processing on the oldest date.

VAR 1       VAR2          VAR3      OCCURRENCE

102011    092011     102011            1
022012    102011     112011            2
               112011     122011            3


It would almost be like a 3 file match?

How would I do this?
rick5952
 
Posts: 4
Joined: Fri Jun 29, 2012 7:07 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to compare 3 variables

Postby Robert Sample » Fri Jun 29, 2012 11:32 pm

EVALUATE or IF -- either can do the task. Depending upon the complexity of what you're needing to do in each case, you can code up a flag to let you know which is earliest, or put the code in the IF / EVALUATE directly.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: how to compare 3 variables

Postby rick5952 » Fri Jun 29, 2012 11:40 pm

Thanks. Maybe I'm trying to make it too difficult.
rick5952
 
Posts: 4
Joined: Fri Jun 29, 2012 7:07 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to compare 3 variables

Postby dick scherrer » Fri Jun 29, 2012 11:49 pm

Hello and welcome to the forum,

Is all of the comparing to be done within the same record?

It would almost be like a 3 file match?
Not really, because in a 3-file match there is the need to keep all 3 files in sync.

Maybe I'm trying to make it too difficult.
Quite possibly . . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: how to compare 3 variables

Postby zatlas1 » Sat Jun 30, 2012 12:27 am

       MOVE 1 TO X
       MOVE VAR1 TO WS-VAR
       IF VAR2 > WS-VAR
          MOVE 2 TO X
          MOVE VAR2 TO WS-VAR
       END-IF
       IF VAR3 > WS-VAR
          MOVE 3 TO X
          MOVE VAR3 TO WS-VAR
       END-IF
      * ETC.
zatlas1
 
Posts: 61
Joined: Mon Mar 15, 2010 9:19 am
Has thanked: 0 time
Been thanked: 0 time

Re: how to compare 3 variables

Postby steve-myers » Sat Jun 30, 2012 6:37 am

I'm not a Cobol person, but I do have a couple of generic comments.
  • The dates you show are not Y2K compliant. This will cause endless problems especially if you have dates from the 1900s.
  • While the chances this program and the underlying dates will still be in use in 2100 are essentially 0, it's hard to believe that after the Y2K trauma, the policies that led to the Y2K trauma are still being used. Let me be the first to predict the Y21K trauma will be worse than the Y2K trauma if this thoughtless cr** persists.
  • The year portion of the date should be compared before the mmdd portion of the date.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: how to compare 3 variables

Postby rick5952 » Tue Jul 03, 2012 2:48 am

thanks for your concern but the dates are a non issue
rick5952
 
Posts: 4
Joined: Fri Jun 29, 2012 7:07 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to compare 3 variables

Postby steve-myers » Tue Jul 03, 2012 5:00 am

rick5952 wrote:thanks for your concern but the dates are a non issue
Please explain.
  • The alleged data clearly appears to be dates.
  • There are correct and incorrect ways to store dates in storage to facilitate date comparison.
  • There are correct and incorrect ways to compare dates based on the way the date is stored in storage.
  • The way a date appears in output is not the issue here, but that can be confusing, too.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: how to compare 3 variables

Postby dick scherrer » Tue Jul 03, 2012 8:43 am

Hello,

thanks for your concern but the dates are a non issue
How can this be as the Only data you posted is dates. . . :?

As posted, the dates CanNot be compared as dates. . .

Possibly your question had nothing to do with dates in which case you should have posted data reflecting what you really wanted to learn how to accomplish.

Playing guessing games just wastes everyone's time. . . Yours and ours.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: how to compare 3 variables

Postby rick5952 » Wed Jul 04, 2012 1:58 am

thanks for wasting mine
rick5952
 
Posts: 4
Joined: Fri Jun 29, 2012 7:07 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post