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

Get current timestamp without using SQL query


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

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Tue Dec 14, 2010 3:30 pm
Reply with quote

I have a situation wherein I have to fetch the current timestamp without using SQL query. Now naturally quetion arises that why not use SQL query? This is because as per the architecture of the system we are not supposed to put SQL queries in the main module. But I have to get the timestamp in main module itself.

One way to do it, is to code a small program for fetching timestamp which will be called by main module.

But I want to know is there any other way which gives me the timestamp in main module itself?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Dec 14, 2010 3:37 pm
Reply with quote

Timestamp of what
Back to top
View user's profile Send private message
mlp

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Tue Dec 14, 2010 3:39 pm
Reply with quote

I need to get the current timestamp. The same is written in above post.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Dec 14, 2010 3:42 pm
Reply with quote

I am not a programmer but you say that you want a cuurent timestamp, and I asked a timestamp of what.

Do you mean the current system time, a timestamp of a table, a timestamp of something else, a timestamp on your clock card.

The help that you receive is directly related to the amount of useful information that you gives us.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 14, 2010 3:45 pm
Reply with quote

Expat,

this one is totally yours. Cause i like you. icon_wink.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Dec 14, 2010 3:48 pm
Reply with quote

Peter,

No please, consider this as your Christmas gift icon_biggrin.gif
Back to top
View user's profile Send private message
mlp

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Tue Dec 14, 2010 3:48 pm
Reply with quote

I need to get current system timestamp. And the resolution should be till microseconds. Becuase I need to get the microseconds from the timestamp for further processing.

I hope now it is more clear.... icon_smile.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Dec 14, 2010 3:53 pm
Reply with quote

if you want to derive/access a db2 CURRENT TIMESTAMP
(which is year, month, day, hour, min, sec, mill-sec)
for a COBOL (any programming language),
then an invocation of SQL from within the run-unit to return the CURRENT TIMESTAMP is what you need to do.


mlp wrote:
I need to get the current timestamp. The same is written in above post.

you want an answer to a very, very, very, simple, elemental problem,
and the fact that you even need to ask shows how little knowledge/skill you have.

that you answered expat's question in such a manner displays why you are asking a forum in the internet instead of a senior (or even beginner) at your site.

you are obviously oblivious to most everything around you, except yourself.
Back to top
View user's profile Send private message
mlp

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Tue Dec 14, 2010 4:03 pm
Reply with quote

I dont want to question anybody's knowledge. I thought the current timestamp will be obivious. But I clarified the same in my successive post.

The reason I posted this topic is not to test any senior member's knowledge. I know the work-around and can implement my solution(as per my first post). But I really want to know that getting the current system timestamp "without using SQL query" is possible or not. I think it is a very honset question going in a very wrong direction.

If my post have sent you any wrong signals then my apologies for the same.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 14, 2010 4:08 pm
Reply with quote

Intrinsic fucntion CURRENT-DATE

Enterprise COBOL for z/OS Language Reference
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Tue Dec 14, 2010 4:37 pm
Reply with quote

Also, REXX's function TIME('L') will give you the same result.

O.
Back to top
View user's profile Send private message
mlp

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Tue Dec 14, 2010 5:19 pm
Reply with quote

Hi Ofer, I think you really got my requirement.

But I need the time (in microseconds) in COBOL program.

Searched the COBOL manual but did not get anything which satisfies my requirement.

I think coding a program which gets the DB2 timestamp which is called by main module is the only way of getting the microseconds in the main module.
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: Tue Dec 14, 2010 5:20 pm
Reply with quote

Quote:
I thought the current timestamp will be obivious.
Terminology is critical in IT, where similar terms may mean very different things. "Timestamp" is a specific term, usually used in reference to databases, that refers to the date and time a particular record was added or updated in the data base. And do not blame others for your shortcoming in not being able to use the appropriate terminology -- it is YOUR responsibility to learn the terminology.

You are asking for the current system time (not timestamp), down to the millisecond. Find the Language Environment Programming Reference manual and read up on the CEE date functions -- you can get what you want from LE.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Dec 14, 2010 5:25 pm
Reply with quote

Also, the solution given by Ofer DOES go down to micro second level, so it is obvious that you DID NOT follow up on his suggestion.

You can execute TSO commands from a COBOL program, so you can use Ofer's suggestion, so stop being so negative and ask adult questions

Maybe something like ........................

Hi Ofer your suggestion gives me what I want, but can I do this from within a COBOL program and if so can you help me understand how.

Easy eh ?
Back to top
View user's profile Send private message
RahulChaudhari

New User


Joined: 03 Nov 2010
Posts: 11
Location: India

PostPosted: Tue Dec 14, 2010 5:33 pm
Reply with quote

Hi all,
simply writting accept <variable-name> from time will give u current timestamp in cobol.
hh:mm:ss:miliseconds please let me know if i am wrong.
thank you.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Dec 14, 2010 5:54 pm
Reply with quote

the accept from CURRENT DATE will return

yyyymmddhhmmssmm
not
yyyymmddhhmmssmmmmmm
the later being a 'timestamp' (without the '-', ':', and '.')

by the way, RahulChaudhari,
you are wrong.
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: Tue Dec 14, 2010 6:01 pm
Reply with quote

RahulChaudhari, not only do you use the wrong terminology ("timestamp" is not used in the COBOL Language Reference manual anywhere in talking about the ACCEPT verb), but you are also wrong about what is returned.
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: Tue Dec 14, 2010 6:03 pm
Reply with quote

A small Assembler sub-program which is CALLED. It issues a STCK instruction, then uses the STCKCONV Macro to convert the STCK value to CCYYMMDDHHMMSSTHMIJU, with "MIJU" representing Milliseconds, Ten-Thousandths, Hundred-Thousandths and Microseconds, respectively.

Normally, this should not be used in CICS. But, check with your CICS Sysprog anyway as he/she might have a workaround.

Also, LE Callable routine CEELOCT will return the date/time as CCYYMMDDHHMMSSTHM, with the low-order "M" representing Milliseconds or the "THM" portion could be interpreted as Milliseconds.

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

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Wed Dec 15, 2010 10:17 am
Reply with quote

Now, we have two ways of getting the time.

1) With CEELOCT call which gives time till millisecond
2) With REXX function TIME('L') using TSO commands which gets time till last microsecond.

Now question is, which is best suited for the CICS env. I dont know for sure, but Can TSO commands be invoked from CICS env?
Back to top
View user's profile Send private message
RahulChaudhari

New User


Joined: 03 Nov 2010
Posts: 11
Location: India

PostPosted: Wed Dec 15, 2010 1:38 pm
Reply with quote

dbzTHEdinosauer wrote:
the accept from CURRENT DATE will return

yyyymmddhhmmssmm
not
yyyymmddhhmmssmmmmmm
the later being a 'timestamp' (without the '-', ':', and '.')

by the way, RahulChaudhari,
you are wrong.

Dear sir,
If i am not wrong ACCEPT <variable name> FROM DATE will give you current date in yymmdd format & not as you have written.ACCEPT <variable name> FROM TIME will give you output as hhmmssmm and REDEFINING this can give you desired output in any format like separator as / , - , : or any other separator you want.
Thank you.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Dec 15, 2010 2:27 pm
Reply with quote

RahulChaudhari,

if you would bother to read my post: CURRENT DATE will return exactly what I stated. (RTFM).

The verbiage that you used, db2 timestamp, requires a 6 digit millisecond,
none of which can be derieved from an ACCEPT statement.

again,
RahulChaudhari, YOU ARE WRONG!
again, RTFM
Back to top
View user's profile Send private message
prasun007

New User


Joined: 03 Jul 2009
Posts: 5
Location: pune

PostPosted: Thu Dec 16, 2010 11:36 pm
Reply with quote

Hi,

@Rahul : mlp
needs the time upto micro second and not upto milli second.
COBOL has a Intrinsic funtion to get the current date like below:

Quote:
Probably the most useful intrinsic function is CURRENT-DATE which is a replacement for ACCEPT DATE and ACCEPT TIME. CURRENT-DATE is Y2K-compliant, having a 4-digit year. This function returns a 20-character alphanumeric field which is laid out as follows:

01 WS-CURRENT-DATE-FIELDS.
05 WS-CURRENT-DATE.
10 WS-CURRENT-YEAR PIC 9(4).
10 WS-CURRENT-MONTH PIC 9(2).
10 WS-CURRENT-DAY PIC 9(2).
05 WS-CURRENT-TIME.
10 WS-CURRENT-HOUR PIC 9(2).
10 WS-CURRENT-MINUTE PIC 9(2).
10 WS-CURRENT-SECOND PIC 9(2).
10 WS-CURRENT-MS PIC 9(2).
05 WS-DIFF-FROM-GMT PIC S9(4).

So not only can you get the time down to the millisecond, but you can get the difference between your time and Greenwich Mean Time.



So I think By using COBOL intrinsic funtion we can get time upto milli second.
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: Fri Dec 17, 2010 12:38 am
Reply with quote

The value returned from FUNCTION CURRENT-DATE, is 21-bytes, with a format of -

01-08 - Date "CCYYMMDD"
09-16 - Time "HHMMSSTH" (The "TH" is tenths/hundreths)
17-07 - GMT Offset sign ("-" or "+")
18-21 - GMT Offset "HHMM" to Local

Under the covers, FUNCTION CURRENT-DATE uses LE Callable routines CEELOCT (for bytes 01-16) and CEEGMTO (for bytes 17-21).

However, the normal timestamp portion returned as part of CEELOCT is "HHMMSSTHM" with the low-order "M" representing milliseconds. But, the timestamp returned as part of FUNCTION CURRENT-DATE truncates this "M". Perhaps the "TH" returned with FUNCTION CURRENT-DATE is the actual CEELOCT "THM" rounded to "TH"? I'm unsure about this.

Although a called Assembler sub-program (as previously suggested), using a STCK instruction and STCKCONV Macro would work, this resolved value is most likely going to be GMT. So instead, another small Assembler sub-program, which issues the TIME Macro (LINKAGE=SYSTEM and ZONE=LT), will return the current local timestamp as "HHMMSSTHMIJU", with "MIJU" representing Milliseconds, Ten-Thousandths, Hundred-Thousandths and Microseconds, respectively.

This can be used in CICS (verify this with your CICS SYSPROG, they can be a little "touchy"), providing you pass the caller's storage to the sub-program for its own reentrant usage, obtained by the caller via a CICS GETMAIN CICSDATAKEY (Key 8) and the PPT entry for the sub-program must be defined as EXECKEY(CICS) in RDO.

TIME (LINKAGE=SYSTEM) uses cross-memory facilities (no interrupt, uses PC/PT instructions), whereas LINKAGE=SVC (the default) uses an SVC 11, which causes is an interrupt. Besides, the timestamp value returned in an SVC 11 (in R0), is X"HHMMSSTH", so its the same as FUNCTION CURRENT-DATE as far as granularity and the date returned is in R1 as X'0CYYDDDF' (packed-decimal), so in order to make this Y2K compliant, you would have to add X'1F000000' to R1, resulting in a valid century.

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Sun Dec 19, 2010 10:16 pm
Reply with quote

mlp,
nice of you to finally mention the word "CICS"...
Apparently if you have to call a routine you might as well use your own routine and get that CURRENT TIMESTAMP from DB2.
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: Sun Dec 19, 2010 10:50 pm
Reply with quote

Quote:
Now question is, which is best suited for the CICS env. I dont know for sure, but Can TSO commands be invoked from CICS env?
None of them is best suited for CICS -- TSO commands cannot be executed from CICS. If you had mentioned CICS from the start, we could have pointed you to EXEC CICS ASKTIME and EXEC CICS FORMATTIME, both of which are explained in the CICS Language Reference manual (link at the top of the page). The CICS commands return the time in milliseconds, rounded to the nearest hundredth of a second -- and that almost always is good enough for CICS transactions.
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 Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts To get the the current time DFSORT/ICETOOL 13
No new posts RC query -Time column CA Products 3
No new posts Changeman - how can we know the curr... Compuware & Other Tools 2
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top