View previous topic :: View next topic
|
Author |
Message |
arraiyan.parveen Warnings : 1 New User
Joined: 10 Feb 2010 Posts: 5 Location: chennai
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
HectorSam101
New User
Joined: 04 Nov 2010 Posts: 3 Location: IN
|
|
|
|
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....... >
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
check...
integer-of-date/date-of-integer/ceedate and friends |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Mickeydusaor
Active User
Joined: 24 May 2006 Posts: 258 Location: Salem, Oregon
|
|
|
|
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 |
|
|
|