Trapping error with DTE()

Started by JimGwynn, February 14, 2020, 03:01:59 PM

Previous topic - Next topic

JimGwynn

I am attempting to trap error generated by the DTE() command

Example = I know the data is bad but that is what I am trying to catch
0010 LET OUTDT$="40129C0"
0020 LET DT$=DTE(MID(OUTDT$,1,2)+"/"+MID(OUTDT$,3,2)+"/"+MID(OUTDT$,5,2):"%Mz/%Dz/%Yl",ERR=*NEXT)
0030 PRINT OUTDT$

Does not trap Error #41





Dave Fullerton

Hi:

The error gets trapped, you're just sending it automatically to the next line:

0010 let outdt$="40129C0"
0020 let dt$=dte(mid(outdt$,1,2)+"/"+mid(outdt$,3,2)+"/"+mid(outdt$,5,2):"%Mz/%Dz/%Yl",err=BAD_DATE)
0030 print outdt$
0100 BAD_DATE:! ^100,5
0110 print err
0120 escape

I hope this helps

Regards

Dave

Mike King

If what you want to do is validate the date and you are running PxPlus 2018 or newer, simply use the JUL function as in:

X=JUL(DateString$, DateFormat$,ERR=Error_Branch)

For example, all the following will fail:

JUL("40129C0","MMDDYY") ! Length wrong
JUL("131290", "MMDDYY") ! Month 30 is bad
JUL("022919", "MMDDYY") ! Not a leap Year


These will work:

JUL("022819","MMDDYY")
JUL("02/28/19","MM/DD/YY")
JUL("02-28-2019","MM-DD-YYYY")
JUL("02/28/2019","MM-DD-YYYY") ! The parser doesn't care what non-numeric delimiter you use


Mike King
President - BBSysco Consulting - http://www.bbsysco.com
eMail: mike.king@bbsysco.com

JimGwynn

Quote from: Dave Fullerton on February 14, 2020, 03:23:29 PM
Hi:

The error gets trapped, you're just sending it automatically to the next line:

0010 let outdt$="40129C0"
0020 let dt$=dte(mid(outdt$,1,2)+"/"+mid(outdt$,3,2)+"/"+mid(outdt$,5,2):"%Mz/%Dz/%Yl",err=BAD_DATE)
0030 print outdt$
0100 BAD_DATE:! ^100,5
0110 print err
0120 escape

I hope this helps

Regards

Dave

What is happening to me is it does not get to the next lines - Throws and Error #41.

John_S

It traps the error for me, so I am not sure why it is throwing an error for you.  Here is my test code.  When I run it I get "bad date, error 41".

00010  LET OUTDT$="40129C0"
00020  LET DT$=DTE(MID(OUTDT$,1,2)+"/"+MID(OUTDT$,3,2)+"/"+ \
             MID(OUTDT$,5,2):"%Mz/%Dz/%Yl",ERR=0050)
00030  PRINT DT$
00040  ESCAPE
00050  PRINT "bad date, error ",ERR
00060  ESCAPE