MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Difference between dates and Trigger based on Value

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
kseenu
Beginner


Joined: 08 Jun 2004
Posts: 11
Topics: 5

PostPosted: Thu Apr 27, 2006 10:05 am    Post subject: Difference between dates and Trigger based on Value Reply with quote

I have 2 given dates.

If the difference between the dates is <2> 2 years (even 1 day also) then I have the execute another function F2.

I am using Integer-of-date function to get the difference between the dates.

If the days > 730 (365*2) then I am calling the function F2 else i am calling F1.

The problem is that when we have Leap year in between the dates.



How to resolve this issue in COBOL?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Apr 27, 2006 12:59 pm    Post subject: Reply with quote

kseenu,

Try this

Code:

WORKING-STORAGE SECTION.                               
                                                       
01 WS-NEW-DATE                 PIC 9(08).               
01 WS-NEW-DATE-R REDEFINES WS-NEW-DATE.                 
    05  NEW-YYYYMM             PIC 9(6).               
    05  NEW-YYYYMM-R REDEFINES NEW-YYYYMM.             
        10  NEW-YYYY           PIC 9(4).               
        10  NEW-MM             PIC 99.                 
    05  DD                     PIC 99.                 
                                                       
01 WS-OLD-DATE                 PIC 9(08).               
01 WS-OLD-DATE-R REDEFINES WS-OLD-DATE.                 
    05  OLD-YYYYMM             PIC 9(6).               
    05  OLD-YYYYMM-R REDEFINES OLD-YYYYMM.             
        10  OLD-YYYY           PIC 9(4).               
        10  OLD-MM             PIC 99.                 
    05  DD                     PIC 99.                 
                                                       
01 WS-DATE-DIFF                PIC 9(08)  VALUE 0.     
01 WS-SUB                      PIC 9(04)  VALUE 0.     
01 WS-LEAP-YEAR-COUNT          PIC S9(04) COMP VALUE 0.

PROCEDURE DIVISION.                                   
                                                       
     MOVE 20040212                    TO WS-OLD-DATE   
     MOVE 20070212                    TO WS-NEW-DATE   
                                                       
     COMPUTE WS-DATE-DIFF =                           
             FUNCTION INTEGER-OF-DATE(WS-NEW-DATE) -   
             FUNCTION INTEGER-OF-DATE(WS-OLD-DATE)     
                                                       
     
     PERFORM VARYING WS-SUB FROM OLD-YYYY BY 1         
       UNTIL WS-SUB >= NEW-YYYY                       
             PERFORM 1000-FIND-LEAP-YEAR               
     END-PERFORM                                       
                                                       
     IF OLD-MM > 2                                     
        SUBTRACT 1 FROM  WS-LEAP-YEAR-COUNT           
     END-IF                                           
                                                       
     IF WS-LEAP-YEAR-COUNT > 0                         
        IF WS-DATE-DIFF > 731                         
           DISPLAY 'THE DIFF B/W 2 DATES IS >= 2 YEARS'
           DISPLAY 'AND THERE IS A LEAP YEAR'         
        ELSE                                           
           DISPLAY 'THE DIFF B/W 2 DATES IS <2>= 2 YEARS'
           DISPLAY 'AND THERE IS NO LEAP YEAR'         
        ELSE                                           
           DISPLAY 'THE DIFF B/W 2 DATES IS <= 2 YEARS'
           DISPLAY 'AND THERE IS NO LEAP YEAR'         
        END-IF                                         
     END-IF       
     
1000-FIND-LEAP-YEAR.                                 
                                                     
     EVALUATE TRUE                                   
         WHEN FUNCTION MOD (WS-SUB 4)   NOT ZERO     
         WHEN FUNCTION MOD (WS-SUB 100) ZERO         
         AND  FUNCTION MOD (WS-SUB 400) NOT ZERO     
         ADD +0   TO WS-LEAP-YEAR-COUNT               
     WHEN OTHER                                       
         ADD +1   TO WS-LEAP-YEAR-COUNT               
     END-EVALUATE                                     
                                                     
     .                                                                               
                                                       


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Fri Apr 28, 2006 7:29 am    Post subject: Reply with quote

Kolusu,

Are you missing out any IF condition to be checked in the loop and i guess it should be



Code:
1000-FIND-LEAP-YEAR.                                             
     IF WS-LEAP-YEAR-COUNT > 0                                   
        IF WS-DATE-DIFF > 731                                   
           DISPLAY 'THE DIFF B/W 2 DATES IS >= 2 YEARS'         
           DISPLAY 'AND THERE IS A LEAP YEAR'                   
        ELSE                                                     
           DISPLAY 'THE DIFF B/W 2 DATES IS <2>= 2 YEARS'       
           DISPLAY 'AND THERE IS NO LEAP YEAR'                   
           IF CONDITION  REQUIRED --------                       
           ELSE                                                 
               DISPLAY 'THE DIFF B/W 2 DATES IS <= 2 YEARS'     
               DISPLAY 'AND THERE IS NO LEAP YEAR'               
           END-IF                                               
     END-IF.                                                     

Please correct me if i am wrong
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Apr 28, 2006 7:33 am    Post subject: Reply with quote

Quote:

Kolusu,

Are you missing out any IF condition to be checked in the loop and i guess it should be



Huh ? I don't understand what you meant. Can you elaborate?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Fri Apr 28, 2006 7:52 am    Post subject: Reply with quote

Kolusu,

You are checking for the first condition in the block.In the first check,u are checking

Code:
               IF WS-DATE-DIFF > 731                                   
                  DISPLAY 'THE DIFF B/W 2 DATES IS >= 2 YEARS'         
                  DISPLAY 'AND THERE IS A LEAP YEAR'                   
               ELSE                                                     
                  DISPLAY 'THE DIFF B/W 2 DATES IS <2>= 2 YEARS'       
                  DISPLAY 'AND THERE IS NO LEAP YEAR'                   

And again u are having an else statement without an IF statement
Code:
               ELSE                                                     
                      DISPLAY 'THE DIFF B/W 2 DATES IS <= 2 YEARS'     
                      DISPLAY 'AND THERE IS NO LEAP YEAR'               

Because when i compile u code i am getting error
Code:
The explicit scope terminator "END-IF" was found without a matching verb.

Please correct me if i am wrong in my understanding.
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Apr 28, 2006 8:20 am    Post subject: Reply with quote

shekar123,

I just noticed that. For some reason IF statement got messed up. Let me repost the else loop here and see if it works.

Code:

             IF WS-LEAP-YEAR-COUNT > 0
                IF WS-DATE-DIFF > 731
                   DISPLAY 'THE DIFF B/W 2 DATES IS >= 2 YEARS'
                   DISPLAY 'AND THERE IS A LEAP YEAR'
                ELSE
                   DISPLAY 'THE DIFF B/W 2 DATES IS <2>= 2 YEARS'
                   DISPLAY 'AND THERE IS NO LEAP YEAR'
                ELSE
                   DISPLAY 'THE DIFF B/W 2 DATES IS <2> 0
                IF WS-DATE-DIFF > 731
                   DISPLAY 'THE DIFF B/W 2 DATES IS >= 2 YEARS'
                   DISPLAY 'AND THERE IS A LEAP YEAR'
                ELSE
                   DISPLAY 'THE DIFF B/W 2 DATES IS <2>= 2 YEARS'
                   DISPLAY 'AND THERE IS NO LEAP YEAR'
                ELSE
                   DISPLAY 'THE DIFF B/W 2 DATES IS <= 2 YEARS'
                   DISPLAY 'AND THERE IS NO LEAP YEAR'
                END-IF
             END-IF



Can't get this to work
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Apr 28, 2006 8:24 am    Post subject: Reply with quote

attempting to code with evaluate


Code:

EVALUATE TRUE
    WHEN WS-LEAP-YEAR-COUNT > 0
         IF WS-DATE-DIFF > 731
            DISPLAY 'THE DIFF B/W 2 DATES IS >= 2 YEARS'
            DISPLAY 'AND THERE IS A LEAP YEAR'
         ELSE
            DISPLAY 'THE DIFF B/W 2 DATES IS <2>= 2 YEARS'
            DISPLAY 'AND THERE IS NO LEAP YEAR'
         ELSE
            DISPLAY 'THE DIFF B/W 2 DATES IS <= 2 YEARS'
            DISPLAY 'AND THERE IS NO LEAP YEAR'
         END-IF
END-EVALUATE

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Apr 28, 2006 8:24 am    Post subject: Reply with quote

darn even this does not work Evil or Very Mad
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Apr 28, 2006 8:54 pm    Post subject: Reply with quote

Finally got it to work . Sad

Code:

    IF WS-LEAP-YEAR-COUNT > 0                         
        IF WS-DATE-DIFF > 731                         
           DISPLAY 'THE DIFF B/W 2 DATES IS >= 2 YEARS'
           DISPLAY 'AND THERE IS A LEAP YEAR'         
        ELSE                                           
           DISPLAY 'THE DIFF B/W 2 DATES IS <2>= 2 YEARS'
           DISPLAY 'AND THERE IS NO LEAP YEAR'
        END-IF
    ELSE
        IF WS-DATE-DIFF > 730
           DISPLAY 'THE DIFF B/W 2 DATES IS >= 2 YEARS'
           DISPLAY 'AND THERE IS A LEAP YEAR'         
        ELSE                                           
           DISPLAY 'THE DIFF B/W 2 DATES IS <= 2 YEARS'
           DISPLAY 'AND THERE IS NO LEAP YEAR'         
        END-IF                                         
     END-IF       
     

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group