Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Obtain last day of next month
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
Author Message
aneeta

New User


Joined: 08 Dec 2005
Posts: 44
Location: Chennai

PostPosted: Fri Aug 15, 2008 4:31 pm    Post subject: Obtain last day of next month
Reply with quote

Hi,
My jobs runs on every month end..Eg Aug 31.I need to get the next month end using SQL query.Eg Sep 30 when it runs on Aug 31.
Basically get the next month end when the job runs for current month end.

Can someone pls help me with the query.This is a urgent requierement.

Thanks
Aneeta
Back to top
View user's profile Send private message
References
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 1618
Location: germany

PostPosted: Fri Aug 15, 2008 4:55 pm    Post subject:
Reply with quote

Not a db2 solution, but is accurate and faster than using db2:
(stolen from Kolusu)

Code:

01 WS-MONTH-END-DD             PIC X(24) VALUE             
                               '312831303130313130313031'.
01 WS-TBL-MONTH-END REDEFINES WS-MONTH-END-DD.             
    05 TBL-MONTH-END-DAY       PIC 9(02) OCCURS 12 TIMES. 

01 WS-GREG-DATE.
   05 WS-GREG-YEAR             PIC 9(04).
   05 WS-GREG-MNTH             PIC 9(02).
   05 WS-GREG-DAY              PIC 9(02).

EVALUATE TRUE                                     
    WHEN FUNCTION MOD (WS-GREG-YEAR 4)   NOT ZERO   
    WHEN FUNCTION MOD (WS-GREG-YEAR 100)     ZERO     
     AND FUNCTION MOD (WS-GREG-YEAR 400) NOT ZERO
    MOVE '28' TO WS-TBL-MONTH-END (3: 2)         
WHEN OTHER                                       
    MOVE '29' TO WS-TBL-MONTH-END (3: 2)         
END-EVALUATE                                     
                                                 
MOVE TBL-MONTH-END-DAY(WS-GREG-MNTH)             
                           TO WS-GREG-DAY
       
DISPLAY 'LAST-DATE OF MONTH:' WS-GREG-DATE       
Back to top
View user's profile Send private message
ulfnsc

New User


Joined: 15 Jan 2004
Posts: 18
Location: Stockholm, SWEDEN

PostPosted: Fri Aug 15, 2008 5:47 pm    Post subject:
Reply with quote

What if the job run's in dec 2008 (20081231) ??
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 1618
Location: germany

PostPosted: Fri Aug 15, 2008 5:55 pm    Post subject:
Reply with quote

He only asked for month end.

besides, it is not a db2 solution.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 1618
Location: germany

PostPosted: Fri Aug 15, 2008 6:42 pm    Post subject:
Reply with quote

Since Ulf pointed out that my routine sucked, how about using the last_day function:

Code:

SELECT LAST_DAY('2008-01-01')
FROM SYSIBM.SYSDUMMY1
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 1618
Location: germany

PostPosted: Fri Aug 15, 2008 7:24 pm    Post subject:
Reply with quote

or even better. if your date is aug 31

Code:

SELECT LAST_DAY(DATE('2008-08-31') + 1 MONTH )
FROM SYSIBM.SYSDUMMY1


of course you can do this with host variables
Back to top
View user's profile Send private message
aneeta

New User


Joined: 08 Dec 2005
Posts: 44
Location: Chennai

PostPosted: Fri Aug 15, 2008 10:56 pm    Post subject: Reply to: Obtain last day of next month
Reply with quote

Hi,
I tried the last query and its throwing sysntax error.

Thanks
Aneeta
Back to top
View user's profile Send private message
Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 92
Location: New York

PostPosted: Sat Aug 16, 2008 12:16 am    Post subject:
Reply with quote

Hi

For me, Dick query is working fine and returning result. Please let us know the error you are getting?
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 8643
Location: 221 B Baker St

PostPosted: Sat Aug 16, 2008 12:31 am    Post subject:
Reply with quote

Hello,

Quote:
I tried the last query and its throwing sysntax error.
Possibly a copy/paste or typing error.

As requested, please post the error as well as the query that gives the error (use copy/paste for both the query and the error).
Back to top
View user's profile Send private message
aneeta

New User


Joined: 08 Dec 2005
Posts: 44
Location: Chennai

PostPosted: Wed Aug 20, 2008 9:27 am    Post subject: Reply to: Obtain last day of next month
Reply with quote

Hi All.
This is the error message I get.
DSNE610I NUMBER OF ROWS DISPLAYED IS 0
DSNT408I SQLCODE = -20101, ERROR: THE FUNCTION LAST_DAY FAILED WITH REASON
00E73004
DSNT418I SQLSTATE = 56060 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNXRLET SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = 1050 0 0 -1 0 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'0000041A' X'00000000' X'00000000' X'FFFFFFFF'
X'00000000' X'00000000' SQL DIAGNOSTIC INFORMATION
DSNT417I SQLWARN0-5 = W,,,,, SQL WARNINGS
DSNT417I SQLWARN6-A = W,,,, SQL WARNINGS

I checked that the field LAST_DAY is not found in the SYSDUMMY1 Table.

Pls help me.

Thanks
Aneeta
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 1618
Location: germany

PostPosted: Wed Aug 20, 2008 11:16 am    Post subject:
Reply with quote

what columns did you find in SYSIBM.SYSDUMMY1 ?
Back to top
View user's profile Send private message
aneeta

New User


Joined: 08 Dec 2005
Posts: 44
Location: Chennai

PostPosted: Thu Aug 21, 2008 1:08 pm    Post subject: Reply to: Obtain last day of next month
Reply with quote

hI,
When I execute this query I get the output but not for last day.

SELECT CURRENT TIMESTAMP
FROM SYSIBM.SYSDUMMY1;

Pls help me resolve this.I need to complete this by THURDSAY.

Thanks
Aneeta
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 1618
Location: germany

PostPosted: Thu Aug 21, 2008 1:16 pm    Post subject:
Reply with quote

as Dick asked, please post your query......... this is thursday and it is your deadline, not ours.
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 183
Location: Pune

PostPosted: Thu Aug 21, 2008 2:30 pm    Post subject:
Reply with quote

You can try the following query.

If you run this query on 31st August, the output will be 2008-09-30
SELECT (CURRENT DATE + 1 MONTHS) FROM SYSIBM.SYSDUMMY1;
Back to top
View user's profile Send private message
aneeta

New User


Joined: 08 Dec 2005
Posts: 44
Location: Chennai

PostPosted: Thu Aug 21, 2008 9:55 pm    Post subject: Reply to: Obtain last day of next month
Reply with quote

SELECT LAST_DAY(DATE('2008-08-31') + 1 MONTH )
FROM SYSIBM.SYSDUMMY1;


DSNE610I NUMBER OF ROWS DISPLAYED IS 0
DSNT408I SQLCODE = -20101, ERROR: THE FUNCTION LAST_DAY FAILED WITH REASON
00E73004
DSNT418I SQLSTATE = 56060 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNXRLET SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = 1050 0 0 -1 0 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'0000041A' X'00000000' X'00000000' X'FFFFFFFF'
X'00000000' X'00000000' SQL DIAGNOSTIC INFORMATION
DSNT417I SQLWARN0-5 = W,,,,, SQL WARNINGS
DSNT417I SQLWARN6-A = W,,,, SQL WARNINGS
DSNE618I ROLLBACK PERFORMED, SQLCODE IS 0
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0

DSNE601I SQL STATEMENTS ASSUMED TO BE BETWEEN COLUMNS 1 AND 72
DSNE620I NUMBER OF SQL STATEMENTS PROCESSED IS 1
DSNE621I NUMBER OF INPUT RECORDS READ IS 2
DSNE622I NUMBER OF OUTPUT RECORDS WRITTEN IS 24
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 HoursGoto page 1, 2  Next
Page 1 of 2