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 

Day of Week Calculation

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


Joined: 07 Dec 2005
Posts: 2
Topics: 1

PostPosted: Wed Dec 07, 2005 9:22 am    Post subject: Day of Week Calculation Reply with quote

I found the code below on a previous posting which is exactly what i am looking for. However the WS-REMAINDER value isnt correct when I am testing.


Code:
IDENTIFICATION DIVISION.                       
PROGRAM-ID.    COBDAY                         
DATE-COMPILED.                                 
ENVIRONMENT DIVISION.                         
DATA DIVISION.                                 
WORKING-STORAGE SECTION.                       
                                               
01 WS-COB-DATE          PIC 9(08).             
01 WS-COB-DATE-R REDEFINES WS-COB-DATE.       
   05 WS-COB-CC         PIC 9(02).             
   05 WS-COB-YY         PIC 9(02).             
   05 WS-COB-MM         PIC 9(02).             
   05 WS-COB-DD         PIC 9(02).             
                                               
01 WS-INP-DATE.                               
   05 WS-INP-DD         PIC 9(02).             
   05 WS-INP-MM         PIC 9(02).             
   05 WS-INP-YY         PIC 9(02).             
                                               
01 WS-DIVIDE-ANSWER     PIC S9(08) COMP.       
01 WS-INTEGER           PIC S9(08) COMP.       
01 WS-REMAINDER         PIC S9(04) COMP.       
01 WS-DAY-OF-WEEK       PIC X(09).             

PROCEDURE DIVISION.                                   
                                                       
                                                       
    MOVE 010504        TO WS-INP-DATE                 
                                                       
    IF WS-INP-YY < 50                                 
       MOVE 20 TO WS-COB-CC                           
    ELSE                                               
       MOVE 19 TO WS-COB-CC                           
    END-IF                                             
                                                       
    MOVE WS-INP-DD     TO WS-COB-YY                   
    MOVE WS-INP-MM     TO WS-COB-MM                   
    MOVE WS-INP-YY     TO WS-COB-DD                   
                                                       
    COMPUTE WS-INTEGER = FUNCTION                     
                         INTEGER-OF-DATE(WS-COB-DATE) 
                                                       
    DIVIDE WS-INTEGER  BY 7 GIVING WS-DIVIDE-ANSWER   
                        REMAINDER WS-REMAINDER         
                                                       
    ADD 1 TO WS-REMAINDER                             
                                                       
    EVALUATE WS-REMAINDER                             
        WHEN 1                                         
             MOVE 'SUNDAY   '     TO WS-DAY-OF-WEEK   
        WHEN 2                                         
             MOVE 'MONDAY   '     TO WS-DAY-OF-WEEK   
        WHEN 3                                         
             MOVE 'TUESDAY  '     TO WS-DAY-OF-WEEK   
        WHEN 4                                         
             MOVE 'WEDNESDAY'     TO WS-DAY-OF-WEEK   
        WHEN 5                                         
             MOVE 'THURSDAY '     TO WS-DAY-OF-WEEK   
        WHEN 6                                         
             MOVE 'FRIDAY   '     TO WS-DAY-OF-WEEK   
        WHEN 7                                         
             MOVE 'SATURDAY '     TO WS-DAY-OF-WEEK   
    END-EVALUATE                                       

     DISPLAY 'IT IS A ' WS-DAY-OF-WEEK ' ON ' WS-INP-DATE     
                                                             
     GOBACK. 


So I changed the EVALUATE WS-REMAINDER to :

Code:
 EVALUATE WS-REMAINDER                             
        WHEN 4                                         
             MOVE 'SUNDAY   '     TO WS-DAY-OF-WEEK   
        WHEN 5                                         
             MOVE 'MONDAY   '     TO WS-DAY-OF-WEEK   
        WHEN 6                                         
             MOVE 'TUESDAY  '     TO WS-DAY-OF-WEEK   
        WHEN 7                                         
             MOVE 'WEDNESDAY'     TO WS-DAY-OF-WEEK   
        WHEN 1                                         
             MOVE 'THURSDAY '     TO WS-DAY-OF-WEEK   
        WHEN 2                                         
             MOVE 'FRIDAY   '     TO WS-DAY-OF-WEEK   
        WHEN 3                                         
             MOVE 'SATURDAY '     TO WS-DAY-OF-WEEK   
    END-EVALUATE.

This way all my testing is correct but im confused.
Has anyone encountered this problem or does anyone have
an explanation.

Thanks
LFC99

P.S. I've just registered with this site today and have already found it a massive help....Thanx !
Back to top
View user's profile Send private message
Grant
Beginner


Joined: 02 Dec 2002
Posts: 45
Topics: 1
Location: Sydney, NSW, Australia

PostPosted: Thu Dec 08, 2005 1:23 am    Post subject: Reply with quote

LFC99,
If you are using compiler option intdate(ansi) , then 01/01/1601 is the base date and "0" remainder represents Sunday

If you are using compiler option intdate(lilian), then 15/10/1582 is the base date and "0" remainder represents thursday


p.s You DO NOT need to specify the WHEN clause in ascending sequence
Back to top
View user's profile Send private message
LFC99
Beginner


Joined: 07 Dec 2005
Posts: 2
Topics: 1

PostPosted: Thu Dec 08, 2005 3:47 am    Post subject: Reply with quote

Fantastic !

Grant - thanks so much for your replies

Love the site !!!
Back to top
View user's profile Send private message
Grant
Beginner


Joined: 02 Dec 2002
Posts: 45
Topics: 1
Location: Sydney, NSW, Australia

PostPosted: Thu Dec 08, 2005 10:19 pm    Post subject: Reply with quote

LFC99,

You can also use the LE service CEEDYWK to determine the day number (or you can divide by 7 as you currently are).

Code:
 

Compute lilian-date = function integer-of-date(Input-date)

call 'ceedywk' using lilian-date day-number feedback-code

Back to top
View user's profile Send private message
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