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

Cobol - date calculations


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
arraiyan.parveen
Warnings : 1

New User


Joined: 10 Feb 2010
Posts: 5
Location: chennai

PostPosted: Wed Oct 27, 2010 2:51 pm
Reply with quote

I have a requirement like ROW-C-DT should be one day less than that of ROW-DT

e.g:

ROW-DT = 10/10/21

ROW-C-DT = (one day less than row_dt) i.e 10/10/20

So can anyone help me out in achieving this. Is there any date routine or standard code that helps to achieve this
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Oct 27, 2010 3:27 pm
Reply with quote

Usually, shops make use of Standard site-specific Date-subroutine for COBOL programs. Suggest you get in cotact with someone at your shop to know about them or search your base-line COBOL-program library to understand how they are doing date-related-calculations at your shop.

You can also search "Mainframe COBOL" part of the Forum on key-word "date", to get an idea of how others are doing this.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 27, 2010 5:13 pm
Reply with quote

Using your site standard date routine would be the best way -- but you have to actually talk to someone at your site to find out about it, since they are site-specific. Or, as Anuj suggested, you could search this forum for the topic -- it's only discussed about once every week or two.

Alternatively, click on the Manuals link at the top of the page and find the COBOL Language Reference manual. There are functions available in COBOL that will help achieve your goal.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Oct 27, 2010 5:19 pm
Reply with quote

What is the version/release of COBOL that you're using?

It's printed at the top of every page of your compile listing.

If you're not sure how to interpret it, then cut/paste/post.

Bill
Back to top
View user's profile Send private message
HectorSam101

New User


Joined: 04 Nov 2010
Posts: 3
Location: IN

PostPosted: Sat Nov 06, 2010 6:17 pm
Reply with quote

I dont think there are any one line statements to do date arithmatic in cobol.

A simple logic to accomplish ur task:

I am assuming that the i/p date will be a valid date and will be of the format yy/mm/dd.

In your case Special handling scenario is required only if dd = 01.

We need to create an array to store the last day of every month (for the time being Feb will hav only 28 days, we will handle leap year later)

WS-LAST-DAYS OCCURS 12 TIMES PIC 9(02) VALUE
31 28 31 30 31 30 31 31 30 31 30 31.


Move the year, month & date to separate numeric variables namely WS-YY, WS-MM, WS-DD.

COMPUTE WS-DATE = WS-DD - 1.

IF WS-DATE > = 1
<we are done....... icon_smile.gif >
Move WS-DATE to DD field of resultant output format yy/mm/dd

ELSE
<we need to get the last day of the month WS-MM minus 1... >
COMPUTE WS-MM = WS-MM - 1
IF WS-MM <= 0
MOVE 12 TO WS-MM
COMPUTE WS-YY = WS-YY - 1
END-IF
MOVE WS-LAST-DAYS(WS-MM) TO WS-DD
<leap year handling...>
IF WS-MM = 2
<use the famous leap-year logic to find if the year is a leap year>
IF LEAP-YEAR
ADD 1 TO WS-DD
END-IF
END-IF
Move WS-YY, WS-MM & WS-DD to resultant o/p format yy/mm/dd.
END-IF

hope this helps!!
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Nov 06, 2010 6:30 pm
Reply with quote

check...
integer-of-date/date-of-integer/ceedate and friends
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Nov 06, 2010 6:58 pm
Reply with quote

Hectorsam101, this statement
Quote:
I dont think there are any one line statements to do date arithmatic in cobol.
is wrong. Enterprise COBOL has functions to convert dates into integers, after which you can use COMPUTE, ADD and SUBTRACT statements to do date arithmetic in days, and then use another function to convert the computed value back into a date. Doing date arithmetic in months would require IF statements and arithmetic statements but days arithmetic has become quite easy in COBOL.
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Mon Nov 08, 2010 10:11 pm
Reply with quote

Code:
01 row-dt           PIC 9(08).
01 sub-days         PIC 9(08).
01 row-c-dt         PIC 9(08).

     COMPUTE row-c-dt = FUNCTION DATE-OF-INTEGER
       (FUNCTION INTEGER-OF-DATE(row-dt) - SUB-DAYS)
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 Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top