Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
dejunzhu

Active User

Joined: 08 May 2008
Posts: 390
Location: China

 Posted: Thu Mar 15, 2012 12:26 pm    Post subject: Addition and subtraction of dates in COBOL 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!

krishna_ragav

New User

Joined: 29 Oct 2010
Posts: 10
Location: Chennai

 Posted: Thu Mar 15, 2012 12:38 pm    Post subject: Reply to: addition and subtraction of dates in COBOL problem 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
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7315

 Posted: Thu Mar 15, 2012 1:03 pm    Post subject: Reply to: addition and subtraction of dates in COBOL problem Have a look at the manuals for the list of Intrinsic Functions. Language Environment also provides callable services.
Peter cobolskolan

Active User

Joined: 06 Feb 2012
Posts: 104
Location: Sweden

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

There is nothing than programming that solves the problem.
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            .
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8165
Location: East Dubuque, Illinois, USA

 Posted: Thu Mar 15, 2012 2:50 pm    Post subject: 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.
krishna_ragav

New User

Joined: 29 Oct 2010
Posts: 10
Location: Chennai

 Posted: Thu Mar 15, 2012 2:56 pm    Post subject: Thank You Robert.
UmeySan

Active Member

Joined: 22 Aug 2006
Posts: 757
Location: Germany

 Posted: Thu Mar 15, 2012 6:18 pm    Post subject: @ 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!
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8165
Location: East Dubuque, Illinois, USA

Posted: Thu Mar 15, 2012 6:43 pm    Post subject:

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
UmeySan

Active Member

Joined: 22 Aug 2006
Posts: 757
Location: Germany

 Posted: Thu Mar 15, 2012 7:03 pm    Post subject: @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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm Addition of two records on 2 fields amar143 SYNCSORT 8 Tue Oct 03, 2017 11:14 am Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us