Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Date Calculation

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

New User


Joined: 12 Nov 2007
Posts: 38
Location: Texas, USA

PostPosted: Tue Dec 11, 2007 5:00 am    Post subject: Date Calculation
Reply with quote

Hi,

I need to write a COBOL code to print a weekly report. This report will be printed on every Sunday. Please help to find date on previous Sunday and yesterday. So if today is sunday, 16th Dec 2007, the data will be pulled between last sunday, 9th dec 2007 and yesterday(that is saturday), 15th dec 2007.

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

shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Tue Dec 11, 2007 2:55 pm    Post subject:
Reply with quote

Satish5,

Please check with the following code for your requirement.
The following cobol code will display the yesterday's date and last sunday's date provided if the current day is sunday.
Code:
       IDENTIFICATION DIVISION.                               
       PROGRAM-ID. DATESUN.                                   
       DATA DIVISION.                                         
       WORKING-STORAGE SECTION.                               
       77 WS-CURRENT-DATE PIC 9(8) VALUE ZERO.                 
       77 WS-INTEGER-OF-DATE PIC 9(7) VALUE ZERO.             
       77 WS-QUOTIENT PIC 9(7) VALUE ZERO.                     
       77 SUNDAY PIC 9 VALUE ZERO.                             
        88 SUNDAY-YES VALUE ZERO.                             
        88 SUNDAY-NO VALUE 1 THRU 6.                           
       77 WS-YESTERDAY-INTEGER-OF-DATE PIC 9(7) VALUE ZERO.   
       77 WS-YESTERDAY-DATE PIC 9(8) VALUE ZERO.               
       77 WS-LAST-SUNDAY-INTEGER-OF-DATE PIC 9(7) VALUE ZERO. 
       77 WS-LAST-SUNDAY-DATE PIC 9(8) VALUE ZERO.             
       PROCEDURE DIVISION.                                     
           ACCEPT WS-CURRENT-DATE FROM DATE YYYYMMDD           
           COMPUTE WS-INTEGER-OF-DATE =                       
           FUNCTION INTEGER-OF-DATE(WS-CURRENT-DATE)           
           END-COMPUTE                                             
           DIVIDE WS-INTEGER-OF-DATE                               
           BY 7                                                   
           GIVING WS-QUOTIENT                                     
           REMAINDER SUNDAY                                       
           END-DIVIDE                                             
           IF SUNDAY-YES                                           
            SUBTRACT +1                                           
            FROM WS-INTEGER-OF-DATE                               
            GIVING WS-YESTERDAY-INTEGER-OF-DATE                   
            END-SUBTRACT                                           
            COMPUTE WS-YESTERDAY-DATE =                           
            FUNCTION DATE-OF-INTEGER(WS-YESTERDAY-INTEGER-OF-DATE)
            END-COMPUTE                                           
            DISPLAY 'YESTERDAY DATE IS ' WS-YESTERDAY-DATE         
            SUBTRACT +7                                           
            FROM WS-INTEGER-OF-DATE                               
            GIVING WS-LAST-SUNDAY-INTEGER-OF-DATE                 
            END-SUBTRACT                                             
            COMPUTE WS-LAST-SUNDAY-DATE =                           
            FUNCTION DATE-OF-INTEGER(WS-LAST-SUNDAY-INTEGER-OF-DATE)
            END-COMPUTE                                             
            DISPLAY 'LAST SUNDAY DATE IS ' WS-LAST-SUNDAY-DATE       
           ELSE                                                     
            DISPLAY 'TODAY IS NOT SUNDAY'                           
           END-IF                                                   
           GOBACK.                                                   
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Dec 11, 2007 6:32 pm    Post subject:
Reply with quote

You could take a service oriented approach and use DB2. I am assuming you will be having the job scheduled to run during the day on Sunday so you don't need to check that today is indeed Sunday.

SELECT CURRENT_TIMESTAMP - 7 DAYS INTO :WS-LAST-SUNDAY;
and
SELECT CURRENT_TIMESTAMP - 1 DAYS INTO :WS-YESTERDAY;
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Dec 11, 2007 7:13 pm    Post subject:
Reply with quote

I forgot the FROM clause on the select statements
Back to top
View user's profile Send private message
Satish5

New User


Joined: 12 Nov 2007
Posts: 38
Location: Texas, USA

PostPosted: Tue Dec 11, 2007 9:46 pm    Post subject:
Reply with quote

Thanks Shankar !! It worked fine.
Thanks to all for their suggestions.

Regards,
Satish

shankar.v wrote:
Satish5,

Please check with the following code for your requirement.
The following cobol code will display the yesterday's date and last sunday's date provided if the current day is sunday.
Code:
       IDENTIFICATION DIVISION.                               
       PROGRAM-ID. DATESUN.                                   
       DATA DIVISION.                                         
       WORKING-STORAGE SECTION.                               
       77 WS-CURRENT-DATE PIC 9(8) VALUE ZERO.                 
       77 WS-INTEGER-OF-DATE PIC 9(7) VALUE ZERO.             
       77 WS-QUOTIENT PIC 9(7) VALUE ZERO.                     
       77 SUNDAY PIC 9 VALUE ZERO.                             
        88 SUNDAY-YES VALUE ZERO.                             
        88 SUNDAY-NO VALUE 1 THRU 6.                           
       77 WS-YESTERDAY-INTEGER-OF-DATE PIC 9(7) VALUE ZERO.   
       77 WS-YESTERDAY-DATE PIC 9(8) VALUE ZERO.               
       77 WS-LAST-SUNDAY-INTEGER-OF-DATE PIC 9(7) VALUE ZERO. 
       77 WS-LAST-SUNDAY-DATE PIC 9(8) VALUE ZERO.             
       PROCEDURE DIVISION.                                     
           ACCEPT WS-CURRENT-DATE FROM DATE YYYYMMDD           
           COMPUTE WS-INTEGER-OF-DATE =                       
           FUNCTION INTEGER-OF-DATE(WS-CURRENT-DATE)           
           END-COMPUTE                                             
           DIVIDE WS-INTEGER-OF-DATE                               
           BY 7                                                   
           GIVING WS-QUOTIENT                                     
           REMAINDER SUNDAY                                       
           END-DIVIDE                                             
           IF SUNDAY-YES                                           
            SUBTRACT +1                                           
            FROM WS-INTEGER-OF-DATE                               
            GIVING WS-YESTERDAY-INTEGER-OF-DATE                   
            END-SUBTRACT                                           
            COMPUTE WS-YESTERDAY-DATE =                           
            FUNCTION DATE-OF-INTEGER(WS-YESTERDAY-INTEGER-OF-DATE)
            END-COMPUTE                                           
            DISPLAY 'YESTERDAY DATE IS ' WS-YESTERDAY-DATE         
            SUBTRACT +7                                           
            FROM WS-INTEGER-OF-DATE                               
            GIVING WS-LAST-SUNDAY-INTEGER-OF-DATE                 
            END-SUBTRACT                                             
            COMPUTE WS-LAST-SUNDAY-DATE =                           
            FUNCTION DATE-OF-INTEGER(WS-LAST-SUNDAY-INTEGER-OF-DATE)
            END-COMPUTE                                             
            DISPLAY 'LAST SUNDAY DATE IS ' WS-LAST-SUNDAY-DATE       
           ELSE                                                     
            DISPLAY 'TODAY IS NOT SUNDAY'                           
           END-IF                                                   
           GOBACK.                                                   
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 Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts LISTIDR compiled date/time jerryte IBM Tools 3 Thu Apr 20, 2017 7:37 pm
No new posts SUBSTR for Date functions Shaheen Shaik DB2 4 Thu Apr 06, 2017 2:14 pm
No new posts Date and time format in CICS Chandru3183 CICS 2 Sat Mar 18, 2017 12:46 pm
No new posts How to get current date -1 and curren... murali.andaluri DFSORT/ICETOOL 3 Wed Mar 08, 2017 2:09 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us