IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Date Calculation


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Need help to append a date&tsp at... DFSORT/ICETOOL 9
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts Fetch data from programs execute (dat... DB2 3
Search our Forums:

Back to Top