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
 

 

Addition and subtraction of dates in COBOL

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

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Thu Mar 15, 2012 12:26 pm    Post subject: Addition and subtraction of dates in COBOL
Reply with quote

I wonder if COBOL support the function of addition and subtraction of dates.

for example, given a day, say 20120315, if I add 16 to this date, the result becomes 20120401 (April the 1st)

Help need on this. Thanks for your reply!
Back to top
View user's profile Send private message

krishna_ragav

New User


Joined: 29 Oct 2010
Posts: 10
Location: Chennai

PostPosted: Thu Mar 15, 2012 12:38 pm    Post subject: Reply to: addition and subtraction of dates in COBOL problem
Reply with quote

Hi,

As per my knowledge there are no statement which can calculate and produce proper date by COBOL.

Most of application would have separate date routine to calculate/ adjust the dates.


Regards,
Krishna
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Thu Mar 15, 2012 1:03 pm    Post subject: Reply to: addition and subtraction of dates in COBOL problem
Reply with quote

Have a look at the manuals for the list of Intrinsic Functions.

Language Environment also provides callable services.
Back to top
View user's profile Send private message
Peter cobolskolan

Active User


Joined: 06 Feb 2012
Posts: 104
Location: Sweden

PostPosted: Thu Mar 15, 2012 2:02 pm    Post subject: Reply to: addition and subtraction of dates in COBOL problem
Reply with quote

There is nothing than programming that solves the problem.
I recommend You read about COBOL Intrinsic Functions and date-functions.
Here is a small program example:
Code:

       Identification Division.
       Program-Id. DATENEXT.
       Data Division.

       Working-Storage Section.
       77 TodaysDate     Pic 9(08).
       77 IntTodaysDate  Pic 9(07).
       77 NextDate       Pic 9(08).
       77 IntNextDate    Pic 9(07).
       77 DayInterval    Pic 9(02) Value 15.

       Procedure Division.
           Move  Function CURRENT-DATE(1:8)  to TodaysDate
           Compute IntNextDate =
                   Function INTEGER-OF-DATE(TodaysDate) + DayInterval
           End-Compute

           Compute NextDate =
                   Function DATE-OF-INTEGER(IntNextDate)
           End-Compute

           Display 'The date ' DayInterval
                   ' days from ' TodaysDate
                   ' is ' NextDate
           GoBack
           .
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7912
Location: Bellevue, IA

PostPosted: Thu Mar 15, 2012 2:50 pm    Post subject:
Reply with quote

If dejunzhu means direct manipulaiton of date-type variables in COBOL, then the answer is no, COBOL doesn't support them. If, however, dejunzhu just wants to manipulate dates, then the answer is yes, COBOL supports intrinsic functions that allow conversion of dates into integers, after which addition and subtraction is easy, as is using the intrinsic function to convert the integer back into a date.

Krishna, your answer is SEVERAL years out of date -- the intrinsic functions were added to COBOL quite a while back.
Back to top
View user's profile Send private message
krishna_ragav

New User


Joined: 29 Oct 2010
Posts: 10
Location: Chennai

PostPosted: Thu Mar 15, 2012 2:56 pm    Post subject:
Reply with quote

Thank You Robert.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 743
Location: Germany

PostPosted: Thu Mar 15, 2012 6:18 pm    Post subject:
Reply with quote

@ Peter cobolskolan

Morning Sir, Ursäkta mig !

Seams, that it does not work:

MOVE FUNCTION CURRENT-DATE(1:8) TO TODAYSDATE

COMPUTE INTNEXTDATE =
FUNCTION INTEGER-OF-DATE(TODAYSDATE) + DAYINTERVAL
END-COMPUTE

COMPUTE NEXTDATE =
FUNCTION DATE-OF-INTEGER(INTNEXTDATE)
END-COMPUTE

XPEDITER/TSO - SOURCE :

01 TODAYSDATE > 20120315
01 DAYINTERVAL > 03
01 NEXTDATE > 20120330 -> 15+03=18

Did i made something wrong, just following your instructions ???
Jag förstår inte.

Hjärtligt tack!
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7912
Location: Bellevue, IA

PostPosted: Thu Mar 15, 2012 6:43 pm    Post subject:
Reply with quote

That's odd. My code is
Code:
01  WS-CURRENT-DATE.
    05  WS-CD                   PIC 9(08).
    05                          PIC X(13).
01  WS-INT-DATE                 PIC 9(07).
01  WS-DAYINTERVAL              PIC 9(07) VALUE 3.
01  WS-OUTPUT-DATE              PIC 9(08).

PROCEDURE DIVISION.
S1000-MAIN       SECTION.
    MOVE FUNCTION CURRENT-DATE  TO  WS-CURRENT-DATE.
    DISPLAY 'CURRENT DATE:  ' WS-CURRENT-DATE.
    COMPUTE WS-INT-DATE =
        FUNCTION INTEGER-OF-DATE (WS-CD) .
    DISPLAY 'INTEGER VALUE: ' WS-INT-DATE.
    ADD WS-DAYINTERVAL          TO  WS-INT-DATE.
    DISPLAY 'INTEGER VALUE: ' WS-INT-DATE.
    COMPUTE WS-OUTPUT-DATE =
        FUNCTION DATE-OF-INTEGER (WS-INT-DATE) .
    DISPLAY 'OUTPUT DATE:   ' WS-OUTPUT-DATE.
and it produces output of
Code:
 CURRENT DATE:  2012031509093382-0400
 INTEGER VALUE: 0150189
 INTEGER VALUE: 0150192
 OUTPUT DATE:   20120318
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 743
Location: Germany

PostPosted: Thu Mar 15, 2012 7:03 pm    Post subject:
Reply with quote

@Peter cobolskolan
@Robert Sample

I just found out, that only playing with the interval-field during XPEDITER-session seams to be the problem. The first time, the calculation is done, everything's correct. Now, when i go back to re-run the calculation after chanching the value of the interval-field nothing is realy recalculated.

Only a new program-generation (compile/link) with a new value in the interval-field, will give a new correct result in the nextdate-field?

Holy smoke, seams to be very misterious. I wonder if the iluminati have a finger in the pie.
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
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm


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