View previous topic :: View next topic
|
Author |
Message |
ntmartins
New User
Joined: 03 Mar 2008 Posts: 11 Location: Lisboa, Portugal
|
|
|
|
Hi there,
I think this is possible: use DB2 to validate if a timestamp variable e correct. Meaning validate date and time format.
Can anyone tell me how to do it?
I'm need to do it in a cobol program. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Code: |
EXEC SQL
SET :WS-TS2 = :WS-TS1 + 1 MICROSECOND
END-EXEC.
IF SQLCODE NOT = 0
you have a problem
END-IF. |
|
|
Back to top |
|
|
ntmartins
New User
Joined: 03 Mar 2008 Posts: 11 Location: Lisboa, Portugal
|
|
|
|
In truth it was a basic question. I should have tried to think a bit more.
Thank you for your answer. |
|
Back to top |
|
|
ntmartins
New User
Joined: 03 Mar 2008 Posts: 11 Location: Lisboa, Portugal
|
|
|
|
I've tried this solution but i'm having an bind error.
Both variables were defined as Char 26.
BIND PACKAGE(DGB0.DCCBAU) MEMBER(MAUQ123A) OWNER(DCOWNDB) QUALIFIER(DCOWNDB
DEGREE(ANY) EXPLAIN(YES) VALIDATE(BIND) OPTHINT('MAUQ123A')
DSNX200I -DGB2 BIND SQL ERROR
USING DCOWNDB AUTHORITY
PLAN=(NOT APPLICABLE)
DBRM=MAUQ123A
STATEMENT=499
SQLCODE=-171
SQLSTATE=42815
TOKENS=1 +
CSECT NAME=DSNXOBFA
RDS CODE=30
DSNT233I -DGB2 UNSUCCESSFUL BIND FOR
PACKAGE = DGB0.DCCBAU.MAUQ123A.() |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
What is the actual definition of the fields and what is the actual sql statement. |
|
Back to top |
|
|
ntmartins
New User
Joined: 03 Mar 2008 Posts: 11 Location: Lisboa, Portugal
|
|
|
|
Problem solved.
But here's the explanation for future references...
fields definition:
WS-TS1 PIC X(26).
WS-TS2 PIC (X26).
SQL Statement
EXEC SQL
SET :WS-TS1 = :WS-TS2 + 1 MICROSECOND
END EXEC.
Anyway, I've been looking into DB2 manual and the function MICROSECOND returns the microseconds from a timestamp!
When we try the statement on Spufi we get:
---------+---------+---------+---------+---------+---------+---------+---------+
SELECT '2009-03-10-15.55.00.846647' + 1 MICROSECOND
FROM SYSIBM.SYSDUMMY1
;
---------+---------+---------+---------+---------+---------+---------+---------+
DSNT408I SQLCODE = -171, ERROR: THE DATA TYPE, LENGTH, OR VALUE OF ARGUMENT 1
OF + IS INVALID
Because the correct sentence would be this:
---------+---------+---------+---------+---------+---------
SELECT MICROSECOND('2009-03-10-15.55.00.846647')
FROM SYSIBM.SYSDUMMY1
;
---------+---------+---------+---------+---------+---------
---------+---------+---------+---------+---------+---------
846647
So, the solution was:
Fields
WS-TS1 PIC X(26).
WS-DATEDUMMY PIC X(10).
SQL Statement
EXEC SQL
SET :WS-DATEDUMMY = DATE(:WS-TS1)
END-EXEC.
IF SQLCODE NOT EQUAL 0
ERROR
END-IF.
Thank you anyway. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Microsecond is a named duration which can be added or subtacted from a timestamp.
Code: |
SELECT '2009-03-10-15.55.00.846647' + 1 MICROSECOND
FROM SYSIBM.SYSDUMMY1
should be
SELECT TIMESTAMP('2009-03-10-15.55.00.846647') + 1 MICROSECOND
FROM SYSIBM.SYSDUMMY1
|
MICROSECOND( ) is a function. |
|
Back to top |
|
|
ntmartins
New User
Joined: 03 Mar 2008 Posts: 11 Location: Lisboa, Portugal
|
|
|
|
Ok, got that.
Thank you for your time and explanation. |
|
Back to top |
|
|
|