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
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: 8697
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
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Dec 20, 2010 12:24 am
Reply with quote

FWIW, in CICS/TS 4.1, the ASKTIME ABSTIME returned value will contain (most of the time) a non-X'0' millisecond digit, in the high-order nibble of the last (sign) byte. In other words, not rounded as in previous version/releases.

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

New User


Joined: 23 Sep 2005
Posts: 91

PostPosted: Mon Dec 20, 2010 9:01 am
Reply with quote

Got lot of information regarding the time, date and timestamp.

Thanks Everybody !!

And as far as my issue is concerned I still require the microseconds and moreover in CICS env. But I think after all of this discussion it is now safe to conlude that I can get it (time in mircosencods) from DB2 only (with the current timestamp). Please correct me if I am wrong.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Dec 20, 2010 9:57 pm
Reply with quote

If you had told us why you need such a thing, we could have given many more good ideas.

For example, maybe 100th of second is enough for your need.
Once I used the time (up to 100th of second) and added a counter instead of the millisec (can't remember exactly the precision used, but that's the general idea).

And again, if you had said "CICS" from the beginning, some suggestions would never have been made.
Bottom line, some people just lost their time with you icon_mad.gif
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