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
 

 

Cobol - date calculations

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Cobol - date calculations
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

Senior Member


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

PostPosted: Wed Oct 27, 2010 3:27 pm    Post subject:
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: 7935
Location: Bellevue, IA

PostPosted: Wed Oct 27, 2010 5:13 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Oct 27, 2010 5:19 pm    Post subject: Reply to: Cobol
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Sat Nov 06, 2010 6:30 pm    Post subject: Reply to: Cobol - date calculations
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: 7935
Location: Bellevue, IA

PostPosted: Sat Nov 06, 2010 6:58 pm    Post subject:
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    Post subject:
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    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. Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm


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