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

Add 3 hours to Timestamp


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Jeya Raj

New User


Joined: 14 Jan 2007
Posts: 33
Location: USA

PostPosted: Sun Jun 17, 2007 7:31 pm
Reply with quote

Hi,

I'm getting process timesatmp(WS-TIMESTAMP) calling task(subprogram) and i need to 3 hours into it. My WS-TIMESTAMP is X(26)(format is CCYY-MM-DD-HH-MM-SEC.NSEC).

I used
EXEC SQL
SET WS-TIMESTAMP = (WS-TIMESTAMP + 3 hours)
END-EXEC.

It is giving compilation error.

Is there any other way to add 3 hours into timestamp. I have to use this modified Timesatmp into cursor as host variable.

Thanks.
Back to top
View user's profile Send private message
Jeya Raj

New User


Joined: 14 Jan 2007
Posts: 33
Location: USA

PostPosted: Mon Jun 18, 2007 3:34 am
Reply with quote

Hi,

I'm getting process timesatmp(WS-TIMESTAMP)by calling task(subprogram) and i need to add 3 hours into it. My WS-TIMESTAMP is X(26)(format is CCYY-MM-DD-HH-MM-SEC.NSEC).

I used

EXEC SQL
SET WS-TIMESTAMP = (WS-TIMESTAMP + 3 hours)
END-EXEC.

It is giving me compilation error.

Is there any other way to add 3 hours into timestamp. I have to use this modified Timesatmp into cursor as a host variable.

Thanks.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Mon Jun 18, 2007 3:47 am
Reply with quote

Slowdown, double posting will get you into trouble....Haven't you read the forum rules and guidlines?
It is Sunday (still), give it a break.....
You have (almost) been warned.... icon_biggrin.gif
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Jun 18, 2007 5:43 am
Reply with quote

Jeya Raj wrote:
Hi,

I'm getting process timesatmp(WS-TIMESTAMP)by calling task(subprogram) and i need to add 3 hours into it. My WS-TIMESTAMP is X(26)(format is CCYY-MM-DD-HH-MM-SEC.NSEC).

I used

EXEC SQL
SET WS-TIMESTAMP = (WS-TIMESTAMP + 3 hours)
END-EXEC.

It is giving me compilation error.

Is there any other way to add 3 hours into timestamp. I have to use this modified Timesatmp into cursor as a host variable.

Thanks.


Code:

EXEC SQL
SET :WS-TIMESTAMP = TIMESTAMP(:WS-TIMESTAMP) + 3 hours
END-EXEC.


You were close. icon_sad.gif But please post your error messages in the future so people don't have to ask for them!
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jun 18, 2007 6:00 am
Reply with quote

Hello,

Also, please keep in mind that questions posted on Sat and Sun are likely to see slower response time than those posted during the week.

As Bill cautions, double posting is not proper. Posting the same question in multiple forums is also a no-no.

When you don't receive a reply as quickly as you'd prefer, hang in there. For most questions, someone will have a suggestion/solution - it just may take a little while.
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Mon Jun 18, 2007 10:42 pm
Reply with quote

How about:

SELECT CURRENT TIMESTAMP + 3 HOURS
FROM SYSIBM.SYSDUMMY1;
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Mon Jun 18, 2007 10:59 pm
Reply with quote

Sorry - the solution I provided adds 3 hours to the current time. I see you want to add 3 hours to your own timestamp value:

See if the following works...

MOVE "2007-06-11-23.59.59.123456" TO WS-TIMESTAMP

SELECT :WS-TIMESTAMP + 3 HOURS
FROM SYSIBM.SYSDUMMY1

I also have COBOL logic that converts a DB2 timestamp into absolute microseconds (1 million microseconds in a second). And another section that converts it back from microseconds to DB2 format.

There are 180,000,000 microseconds in 3 hours (3 * 60 * 1000000). So the logic would be:

1. Convert timestamp to microseconds.
2. Add 180,000,000 to microseconds.
3. Convert microseconds back to timestamp.

Of course this logic is best packaged as a set of copybooks or as a utility. The DB2 approach is so simple so you would only need to use the COBOL approach if you had a good reason for avoiding DB2.

If you need the conversion logic - just ask and I can post.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Jun 18, 2007 11:51 pm
Reply with quote

TG Murphy wrote:
Sorry - the solution I provided adds 3 hours to the current time. I see you want to add 3 hours to your own timestamp value:

See if the following works...

MOVE "2007-06-11-23.59.59.123456" TO WS-TIMESTAMP

SELECT :WS-TIMESTAMP + 3 HOURS
FROM SYSIBM.SYSDUMMY1


I also have COBOL logic that converts a DB2 timestamp into absolute microseconds (1 million microseconds in a second). And another section that converts it back from microseconds to DB2 format.

There are 180,000,000 microseconds in 3 hours (3 * 60 * 1000000). So the logic would be:

1. Convert timestamp to microseconds.
2. Add 180,000,000 to microseconds.
3. Convert microseconds back to timestamp.

Of course this logic is best packaged as a set of copybooks or as a utility. The DB2 approach is so simple so you would only need to use the COBOL approach if you had a good reason for avoiding DB2.

If you need the conversion logic - just ask and I can post.


And just where is DB2 going to put ws-timestamp after is adds 3 hours to it.
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Tue Jun 19, 2007 12:16 am
Reply with quote

Craq,

Does this look better?

EXEC SQL SELECT
TIMESTAMP(:WS-TIMESTAMP) + 3 HOURS
INTO :WS-NEW-TIMESTAMP
FROM SYSIBM.SYSDUMMY1
END-EXEC

I haven't tested so you may need to tinker with what I gave you.

The first SQL I proposed above was in SPUFI format so that is how I managed to leave out the INTO...
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Jun 19, 2007 12:24 am
Reply with quote

TG Murphy wrote:
Craq,

Does this look better?

EXEC SQL SELECT
TIMESTAMP(:WS-TIMESTAMP) + 3 HOURS
INTO :WS-NEW-TIMESTAMP
FROM SYSIBM.SYSDUMMY1
END-EXEC

I haven't tested so you may need to tinker with what I gave you.

The first SQL I proposed above was in SPUFI format so that is how I managed to leave out the INTO...

Why bother with reference to a table when the SET does the samething with out any table reference.
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Tue Jun 19, 2007 1:30 am
Reply with quote

Sure. Agree.

I was under the impression that the syntax "+ 3 MONTHS" for some reason did not work with SET.

I sure could be wrong about that - if you can get it working using the SET command then I agree it is a better way than having to reference SYSIBM.SYSDUMMY1.

I don't have the time to test it all out at the moment. Maybe somebody can do this...
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Tue Jun 19, 2007 1:52 am
Reply with quote

Craq,

You were right. No need to use SELECT from SYSIBM.SYSDUMMY1.

I tested it and the following works fine...

MOVE "1999-01-01-14.59.59.123456" TO WS-TS

EXEC SQL SET :WS-NEW-TS = TIMESTAMP(:WS-TS) + 3 HOURS
END-EXEC

The only thing I can think of is that original SQL (see first post above) did not specify the colon to start off the host variable.

Good catch Craq..
Back to top
View user's profile Send private message
Jeya Raj

New User


Joined: 14 Jan 2007
Posts: 33
Location: USA

PostPosted: Tue Jun 19, 2007 4:49 am
Reply with quote

Thanks all for your tips. I'll try it tonight.

Thanks for your warning William. I forgot about the rules.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Jun 19, 2007 5:05 am
Reply with quote

Jeya Raj wrote:
Thanks all for your tips. I'll try it tonight.
Good luck, and remember, we are here.....
Back to top
View user's profile Send private message
Jeya Raj

New User


Joined: 14 Jan 2007
Posts: 33
Location: USA

PostPosted: Thu Jun 21, 2007 6:53 pm
Reply with quote

Thanks TG. It worked fine.
Back to top
View user's profile Send private message
rsundar83

New User


Joined: 05 Dec 2005
Posts: 1

PostPosted: Tue Jun 26, 2007 12:56 pm
Reply with quote

Hi,

With the above command, the module did not give any compilation error but the job abended exactly when it was processing this SQL.


WS-UPDT-TMSTMP = 2005-02-17-21.44.47.292406

EXEC SQL

SET :WS-CST-TMSTMP = TIMESTAMP(:WS-UPDT-TMSTMP) + 6 HOURS

END-EXEC.

fyi, WS-CST-TMSTMP & WS-UPDT-TMSTMP are declared as X(26).

any guess why?? i suspected precompiler options. But it looks fine to me. Can anyone please help me on this?
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Jun 26, 2007 2:39 pm
Reply with quote

rsundar83 wrote:
Hi,

With the above command, the module did not give any compilation error but the job abended exactly when it was processing this SQL.


WS-UPDT-TMSTMP = 2005-02-17-21.44.47.292406

EXEC SQL

SET :WS-CST-TMSTMP = TIMESTAMP(:WS-UPDT-TMSTMP) + 6 HOURS

END-EXEC.

fyi, WS-CST-TMSTMP & WS-UPDT-TMSTMP are declared as X(26).

any guess why?? i suspected precompiler options. But it looks fine to me. Can anyone please help me on this?


Would you be willing to share the abend messages etc with us? What was the value of ws-updt-tmstmp when the abend occured?
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 To get the count of rows for every 1 ... DB2 3
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts Timestamp difference and its average ... DB2 11
No new posts After hours quick-fix support for IBM... Mainframe Jobs 0
No new posts To get previous month from current ti... SYNCSORT 7
Search our Forums:

Back to Top