Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Finding the Date of a particlular day for any year?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Hames

New User


Joined: 03 Oct 2005
Posts: 49

PostPosted: Thu Nov 10, 2005 3:23 pm    Post subject: Finding the Date of a particlular day for any year?
Reply with quote

Hi,

This is my friend's Requirement.

He has to find the Date of the last sunday for any given year in COBOL.

Advanced thanks for your views!


*********
THanks,
Hames
*********
Back to top
View user's profile Send private message

Hames

New User


Joined: 03 Oct 2005
Posts: 49

PostPosted: Thu Nov 10, 2005 3:33 pm    Post subject:
Reply with quote

Let me know Whether this is correct!!!

1. First he need to find the day for Oct 31 for the given year.

2. If it falls on Sunday then that is the required answer.
else if it is Monday ==> 30 is Last sunday
else if it is tuesday ==> 29 is Last Sunday
else if it is Wednesday ==> 28 is Last Sunday
else if it is thursday ==> 27 is Last Sunday
else if it is friday ==> 26 is Last Sunday
else ==> 25 is Last Sunday

If there is any other simple logic is there, please let me know
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Thu Nov 10, 2005 7:48 pm    Post subject: Re: Finding the Date of a particlular day for any year?
Reply with quote

Hi Hames,

I worte a very simple cobol code for finding out the last sunday of the year.
There can be made more improvement in this code in terms of performance or programming.
Also leap year functioning needs to be accomodated in the code, that I couldn't at this time.

Check & let me know, the results.

Code:
WORKING-STORAGE SECTION.           
01 WS-DATE PIC 9(5).               
01 WS-DAY  PIC 9(1).               
01 WS-F    PIC 9(3).               
01 K PIC 9(3).                     
01 L PIC 9(5).99.                 
01 X PIC 99.                       
01 SW-DAY PIC 9(1).               
   88 MON VALUE 1.                 
   88 TUE VALUE 2.                 
   88 WED VALUE 3.                 
   88 THU VALUE 4.                 
   88 FRI VALUE 5.                 
   88 SAT VALUE 6.                 
   88 SUN VALUE 7.                 

ACCEPT WS-DATE FROM DAY.           
ACCEPT WS-DAY FROM DAY-OF-WEEK.   
MOVE WS-DAY TO SW-DAY.             
MOVE WS-DATE(3:3) TO WS-F.         
COMPUTE K= 365 - WS-F.             
COMPUTE L=K/7.                     
MOVE L(7:2) TO X.                 
IF X=0                           
   EVALUATE SW-DAY               
     WHEN 7  DISPLAY '31 DEC'   
     WHEN 1  DISPLAY '30 DEC'   
     WHEN 2  DISPLAY '29 DEC'   
     WHEN 3  DISPLAY '28 DEC'   
     WHEN 4  DISPLAY '27 DEC'   
     WHEN 5  DISPLAY '26 DEC'   
     WHEN 6  DISPLAY '25 DEC'   
   END-EVALUATE.                 
IF X=14                         
   EVALUATE SW-DAY               
     WHEN 7    DISPLAY '30 DEC' 
     WHEN 1     DISPLAY '29 DEC'
     WHEN 2     DISPLAY '28 DEC'
     WHEN 3     DISPLAY '27 DEC'
     WHEN 4     DISPLAY '26 DEC'
     WHEN 5     DISPLAY '25 DEC'
     WHEN 6     DISPLAY '31 DEC'
   END-EVALUATE.                 
IF X=28                           
   EVALUATE SW-DAY                 
     WHEN 7   DISPLAY '29 DEC'     
     WHEN 1   DISPLAY '28 DEC'     
     WHEN 2   DISPLAY '27 DEC'     
     WHEN 3    DISPLAY '26 DEC'   
     WHEN 4    DISPLAY '25 DEC'   
     WHEN 5    DISPLAY '31 DEC'   
     WHEN 6    DISPLAY '30 DEC'   
   END-EVALUATE.                   
IF X=43                           
   EVALUATE SW-DAY                 
     WHEN 7     DISPLAY '28 DEC'   
     WHEN 1     DISPLAY '27 DEC'   
     WHEN 2     DISPLAY '26 DEC'   
     WHEN 3     DISPLAY '25 DEC'   
     WHEN 4     DISPLAY '31 DEC'   
     WHEN 5     DISPLAY '30 DEC'   
     WHEN 6     DISPLAY '29 DEC'   
   END-EVALUATE.                   
IF X=57                             
   EVALUATE SW-DAY                 
     WHEN 7     DISPLAY '27 DEC'   
     WHEN 1     DISPLAY '26 DEC'   
     WHEN 2     DISPLAY '25 DEC'   
     WHEN 3     DISPLAY '31 DEC'   
     WHEN 4     DISPLAY '30 DEC'   
     WHEN 5     DISPLAY '29 DEC'   
     WHEN 6     DISPLAY '28 DEC'   
   END-EVALUATE.                   
IF X=71                             
   EVALUATE SW-DAY                 
     WHEN 7   DISPLAY '26 DEC'     
     WHEN 1   DISPLAY '25 DEC'     
     WHEN 2   DISPLAY '31 DEC'     
     WHEN 3   DISPLAY '30 DEC'     
     WHEN 4   DISPLAY '29 DEC'     
     WHEN 5   DISPLAY '28 DEC'     
     WHEN 6   DISPLAY '27 DEC'     
   END-EVALUATE.                   
IF X=86                               
   EVALUATE SW-DAY                   
     WHEN 7     DISPLAY '25 DEC'     
     WHEN 1     DISPLAY '31 DEC'     
     WHEN 2     DISPLAY '30 DEC'     
     WHEN 3     DISPLAY '29 DEC'     
     WHEN 4   DISPLAY '28 DEC'       
     WHEN 5   DISPLAY '27 DEC'       
     WHEN 6   DISPLAY '26 DEC'       
   END-EVALUATE.                     


Regards,

Priyesh.
Back to top
View user's profile Send private message
Hames

New User


Joined: 03 Oct 2005
Posts: 49

PostPosted: Sat Nov 12, 2005 8:34 pm    Post subject: Re: Finding the Date of a particlular day for any year?
Reply with quote

Hi Priyesh,

Thank you!

I checked this code and its working fine.

________

Thanks,
Hames
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Nov 15, 2005 6:42 am    Post subject:
Reply with quote

A little late to the party, but....

You can try the code below if you use a COBOLII or better compiler. It?s tested and seems to work OK. It will accept dates between 1601 and 9999 inclusive.
Code:


WS

05  DISP-DT.
    10  DISP-YYYY    PIC  X(004).
    10  DISP-MM      PIC  X(002).
    10  DISP-DD      PIC  9(002).
05  DISP-DT-NUM      REDEFINES
    DISP-DT          PIC  9(008).
05  DAYS-FROM-SUN    PIC  9(001).
05  WS-IOD           PIC  9(010) COMP.


P.D.

MOVE    '19001231' TO DISP-DT
COMPUTE WS-IOD      =
        FUNCTION      INTEGER-OF-DATE (DISP-DT-NUM)
DIVIDE  WS-IOD     BY 7
        GIVING        WS-IOD
        REMAINDER     DAYS-FROM-SUN
END-DIVIDE
COMPUTE DISP-DD     = DISP-DD - DAYS-FROM-SUN
DISPLAY DISP-MM '/'   DISP-DD ' IS THE LAST SUNDAY IN '
        DISP-YYYY
GOBACK
.


********************************* TOP OF DATA ***
12/30 IS THE LAST SUNDAY IN 1900
******************************** BOTTOM OF DATA *.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Tue Nov 15, 2005 3:19 pm    Post subject: Re: Finding the Date of a particlular day for any year?
Reply with quote

Thats what I was looking for when I said ..for my code...
Quote:
There can be made more improvement in this code in terms of performance or programming.


Thanks Jack... That is how, we get something to learn/improve.

Regards,

Priyesh.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Nov 16, 2005 6:42 am    Post subject:
Reply with quote

Hi Priyesh,

Thanx for the kind words, but performance-wise, I think your solution would beat the pants off of mine. icon_lol.gif
Back to top
View user's profile Send private message
Hames

New User


Joined: 03 Oct 2005
Posts: 49

PostPosted: Mon Nov 21, 2005 12:06 pm    Post subject:
Reply with quote

Hi Jack,


I have tested your code also. Its working fine.

Thanks a lot.

_________________
Regards,
Hames
_________________

"Dream bigger things - Dream is the seed for extraordinary things"
Back to top
View user's profile Send private message
hncs

New User


Joined: 01 Mar 2006
Posts: 11

PostPosted: Mon Mar 06, 2006 4:08 pm    Post subject:
Reply with quote

WITHOUT USING FUNCTIONS YOU CAN CODE LIKE BELOW.

WORKING-STORAGE SECTION.

01 WS-YEAR PIC 9(04) VALUE ZEROES.
01 I PIC 9(04) VALUE ZEROES.
01 J PIC 9(04) VALUE ZEROES.
01 K PIC 9(04) VALUE ZEROES.


PROCEDURE DIVISION.

MOVE WS-YEAR TO K
ADD -1 TO WS-YEAR.

DIVIDE WS-YEAR BY 400 GIVING I REMAINDER WS-YEAR.
DIVIDE WS-YEAR BY 100 GIVING J REMAINDER WS-YEAR.

COMPUTE WS-YEAR = WS-YEAR + (WS-YEAR/4) + 1
COMPUTE WS-YEAR = WS-YEAR + (J*5)

DIVIDE WS-YEAR BY 7 GIVING I REMAINDER WS-YEAR.

SUBTRACT WS-YEAR FROM 6 GIVING WS-YEAR.
SUBTRACT WS-YEAR FROM 31 GIVING WS-YEAR.

DISPLAY "DATE IS : " K " DECEMBER " WS-YEAR.

STOP RUN.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Compare yesterday's date to the one o... migusd SYNCSORT 8 Fri Sep 22, 2017 11:35 pm
No new posts Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts LMINIT problem - not finding DDNAME Danielle.Filteau CLIST & REXX 7 Tue Sep 19, 2017 9:57 pm
No new posts Validate the Date girishb2 DFSORT/ICETOOL 9 Tue Sep 19, 2017 1:12 am
No new posts Julian Date to CICS ABSTTIME blayek CICS 3 Wed Aug 30, 2017 11:15 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us