Skip to main content
Jonathan Smith
Rocketeer
Jul 8, 2022 1:17 PM UTC

UniBasic code to perform your own OCONV / ICONV using UniVersal Date Time Stamps

As a normal practice I wouldn't be posting example code onto the forum unless someone was needing help about a specific problem. We did have a question come in from a customer this week asking for a new conversion code be added to UniData. This brought up a couple of interesting subjects. The customer was not aware that you could write your own code following a template to create your own conversion codes. It took me some time to find where this was buried in the manuals I can understand why they would not have come across it.

So just in case others were not aware you could do this I thought I'd share with you how you do this.

SUBROUTINE SUBNAME( return_val, STATUS, input_val, TYPE )
***************************************************************
*
* Brief functional description
*
* (c) Copyright notice
**************************************************************
*
* Detailed description
*
* Usage, such as return_val = OCONV(input_val,"USUBNAME")
*
**************************************************************
* processing code area:
* Arguments:
* return_val = final data to return.
* STATUS = 0 for success, other for failure.
* input_val= data to be converted or processed.
* TYPE: 0 for ICONV, 1 for OCONV.
*
RETURN
END

The customer was asking for some conversion codes to be added around UTL time stamps. So I'm attaching my example code I provided to the customer to demonstrate some ideas around around UTL conversions and would welcome any comments around UTL and in particular handling time zones.

So my example does the following it takes the input of UTL string in for format 2019-06-06T08:58:42.1878669+09:00 or 2019-06-06T08:58:42+09:00 and it will return on ICONV the internal date and internal time of the UTC time. So ICONV(" 2019-06-06T08:58:42.1878669+09:00", "UUTCL") returns 19912 86322.1878669
where 19912 = 17/07/2022 and 86322.1878669 = 23:58:42

In terms of the OCONV it takes 19912 86322.1878669 and then converts that into UTL time stamp of the timezone that the server is running in, so on my Windows Laptop (being UK based) OCONV("19912 86322.1878669","UUTCL") returns 2022-07-07T23:58:42.1878669+00:00 (Dublin, Edinburgh, Lisbon, London) if I use the same example on one of our Denver based unix servers it returns 2022-07-07T23:58:42.1878669-06:00 (MDT Mountain Daylight Time)

So in terms of the attachments with post the user conversion program is called UTCL, there is a testing program called TIME.TEST and there is a look up file called TIMEZONES, the TIMEZONES and D_TIMEZONES files are the Windows / Linux Versions and the TIMEZONES.UX and D_TIMEZONES.UK files are for AIX / HPUX and Solaris.

I hope they provide an example to those of you who didn't know you could do this and also I'd be interested to hear your thoughts about how you want to determine a timezone programmatically.

------------------------------
Jonathan Smith
UniData ATS
Rocket Support
------------------------------

    12 replies

    Bill Brutzman
    Participating Frequently
    Jul 8, 2022 4:22 PM UTC
    As a normal practice I wouldn't be posting example code onto the forum unless someone was needing help about a specific problem. We did have a question come in from a customer this week asking for a new conversion code be added to UniData. This brought up a couple of interesting subjects. The customer was not aware that you could write your own code following a template to create your own conversion codes. It took me some time to find where this was buried in the manuals I can understand why they would not have come across it.

    So just in case others were not aware you could do this I thought I'd share with you how you do this.

    SUBROUTINE SUBNAME( return_val, STATUS, input_val, TYPE )
    ***************************************************************
    *
    * Brief functional description
    *
    * (c) Copyright notice
    **************************************************************
    *
    * Detailed description
    *
    * Usage, such as return_val = OCONV(input_val,"USUBNAME")
    *
    **************************************************************
    * processing code area:
    * Arguments:
    * return_val = final data to return.
    * STATUS = 0 for success, other for failure.
    * input_val= data to be converted or processed.
    * TYPE: 0 for ICONV, 1 for OCONV.
    *
    RETURN
    END

    The customer was asking for some conversion codes to be added around UTL time stamps. So I'm attaching my example code I provided to the customer to demonstrate some ideas around around UTL conversions and would welcome any comments around UTL and in particular handling time zones.

    So my example does the following it takes the input of UTL string in for format 2019-06-06T08:58:42.1878669+09:00 or 2019-06-06T08:58:42+09:00 and it will return on ICONV the internal date and internal time of the UTC time. So ICONV(" 2019-06-06T08:58:42.1878669+09:00", "UUTCL") returns 19912 86322.1878669
    where 19912 = 17/07/2022 and 86322.1878669 = 23:58:42

    In terms of the OCONV it takes 19912 86322.1878669 and then converts that into UTL time stamp of the timezone that the server is running in, so on my Windows Laptop (being UK based) OCONV("19912 86322.1878669","UUTCL") returns 2022-07-07T23:58:42.1878669+00:00 (Dublin, Edinburgh, Lisbon, London) if I use the same example on one of our Denver based unix servers it returns 2022-07-07T23:58:42.1878669-06:00 (MDT Mountain Daylight Time)

    So in terms of the attachments with post the user conversion program is called UTCL, there is a testing program called TIME.TEST and there is a look up file called TIMEZONES, the TIMEZONES and D_TIMEZONES files are the Windows / Linux Versions and the TIMEZONES.UX and D_TIMEZONES.UK files are for AIX / HPUX and Solaris.

    I hope they provide an example to those of you who didn't know you could do this and also I'd be interested to hear your thoughts about how you want to determine a timezone programmatically.

    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Jonathan:

    Q1. Why NOT post code?
    Q2. Is not almost everything a specific problem?

    Please clarify.

    ------------------------------
    Bill Brutzman
    IT Manager
    Hk Metalcraft Manufacturing Corporation
    Lodi NJ US
    ------------------------------
    Jonathan Smith
    Rocketeer
    Jul 8, 2022 4:43 PM UTC
    Jonathan:

    Q1. Why NOT post code?
    Q2. Is not almost everything a specific problem?

    Please clarify.

    ------------------------------
    Bill Brutzman
    IT Manager
    Hk Metalcraft Manufacturing Corporation
    Lodi NJ US
    ------------------------------
    Bill ... How would you programmaticly get the system to find out what post code it is in. Finding the systems time zone can be found out via a Unix or Windows command... or you could even enquire on the system or users time zone environment variable. I am not aware of any easy way to get the post code that a system or user is in and then how would you tie translate that to the timezone the post code is in.

    Thanks



    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Rocket Software - Senior Principal Technical Support Engineer - UniData ATS
    Bill Brutzman
    Participating Frequently
    Jul 8, 2022 5:50 PM UTC
    Bill ... How would you programmaticly get the system to find out what post code it is in. Finding the systems time zone can be found out via a Unix or Windows command... or you could even enquire on the system or users time zone environment variable. I am not aware of any easy way to get the post code that a system or user is in and then how would you tie translate that to the timezone the post code is in.

    Thanks



    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Jonathan:

    Thanks for responding but _ my question Q1 is much more general.

    I interpreted your message as something like _ please do not reveal any (UniBasic) source code on this forum.   Perhaps the intent of your comment is related to intellectual property (legal) considerations.  Please clarify.

    --Bill

    ------------------------------
    Bill Brutzman
    IT Manager
    Hk Metalcraft Manufacturing Corporation
    Lodi NJ US
    ------------------------------
    Jonathan Smith
    Rocketeer
    Jul 9, 2022 12:54 AM UTC
    Jonathan:

    Thanks for responding but _ my question Q1 is much more general.

    I interpreted your message as something like _ please do not reveal any (UniBasic) source code on this forum.   Perhaps the intent of your comment is related to intellectual property (legal) considerations.  Please clarify.

    --Bill

    ------------------------------
    Bill Brutzman
    IT Manager
    Hk Metalcraft Manufacturing Corporation
    Lodi NJ US
    ------------------------------
    Bill I have no problem with the source code being shared as it was put onto the forum as an example.

    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Rocket Software - Senior Principal Technical Support Engineer - UniData ATS
    Chuck Stevenson
    Participating Frequently
    Jul 11, 2022 9:01 AM UTC
    As a normal practice I wouldn't be posting example code onto the forum unless someone was needing help about a specific problem. We did have a question come in from a customer this week asking for a new conversion code be added to UniData. This brought up a couple of interesting subjects. The customer was not aware that you could write your own code following a template to create your own conversion codes. It took me some time to find where this was buried in the manuals I can understand why they would not have come across it.

    So just in case others were not aware you could do this I thought I'd share with you how you do this.

    SUBROUTINE SUBNAME( return_val, STATUS, input_val, TYPE )
    ***************************************************************
    *
    * Brief functional description
    *
    * (c) Copyright notice
    **************************************************************
    *
    * Detailed description
    *
    * Usage, such as return_val = OCONV(input_val,"USUBNAME")
    *
    **************************************************************
    * processing code area:
    * Arguments:
    * return_val = final data to return.
    * STATUS = 0 for success, other for failure.
    * input_val= data to be converted or processed.
    * TYPE: 0 for ICONV, 1 for OCONV.
    *
    RETURN
    END

    The customer was asking for some conversion codes to be added around UTL time stamps. So I'm attaching my example code I provided to the customer to demonstrate some ideas around around UTL conversions and would welcome any comments around UTL and in particular handling time zones.

    So my example does the following it takes the input of UTL string in for format 2019-06-06T08:58:42.1878669+09:00 or 2019-06-06T08:58:42+09:00 and it will return on ICONV the internal date and internal time of the UTC time. So ICONV(" 2019-06-06T08:58:42.1878669+09:00", "UUTCL") returns 19912 86322.1878669
    where 19912 = 17/07/2022 and 86322.1878669 = 23:58:42

    In terms of the OCONV it takes 19912 86322.1878669 and then converts that into UTL time stamp of the timezone that the server is running in, so on my Windows Laptop (being UK based) OCONV("19912 86322.1878669","UUTCL") returns 2022-07-07T23:58:42.1878669+00:00 (Dublin, Edinburgh, Lisbon, London) if I use the same example on one of our Denver based unix servers it returns 2022-07-07T23:58:42.1878669-06:00 (MDT Mountain Daylight Time)

    So in terms of the attachments with post the user conversion program is called UTCL, there is a testing program called TIME.TEST and there is a look up file called TIMEZONES, the TIMEZONES and D_TIMEZONES files are the Windows / Linux Versions and the TIMEZONES.UX and D_TIMEZONES.UK files are for AIX / HPUX and Solaris.

    I hope they provide an example to those of you who didn't know you could do this and also I'd be interested to hear your thoughts about how you want to determine a timezone programmatically.

    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Jonathon,

    What is the best way to pass parameters into a user-defined conversion via the conversion attribute <3> of a dictionary?  (<7> or <8> is A- or S-items).

    As an example, consider the "MD" conversion:  MD0, MD20P.
    Or consider all the various options for a "D" conversion: D [n] [*m] [ s] [fmt [[f1, f2, f3, f4, f5]]] [E] [L]

    I've wanted to do do things like that with my own user conversion subroutines.

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------
    Jonathan Smith
    Rocketeer
    Jul 11, 2022 9:28 AM UTC
    Jonathon,

    What is the best way to pass parameters into a user-defined conversion via the conversion attribute <3> of a dictionary?  (<7> or <8> is A- or S-items).

    As an example, consider the "MD" conversion:  MD0, MD20P.
    Or consider all the various options for a "D" conversion: D [n] [*m] [ s] [fmt [[f1, f2, f3, f4, f5]]] [E] [L]

    I've wanted to do do things like that with my own user conversion subroutines.

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------
    Hi Chuck,

    The example I highlighted was for UniData. UniData does not have the Pick Style dictionaries where 7 and 8 are the conversion and correlative. How to do to write one of the programs and use it is covered in the 'User Exits' part of the 'Using UniData' manual.  The first part of any conversion code so M,D etc all tell UniData / UniVerse how to process the conversion.

    With a conversion code of Uuser_exit  The user_exit just specifies which catalogued program to use it does not have any other options as was never designed to do so. (You may know this , others might not) Originally the user_exit code was put in place to provide Pick style calls such as U50BB. If you sort SYS_BP in UniData you'll see 30 or so  programs at the top which are user_exit replacements for old Pick style ones. Given that the user_exit template is pre-defined as well, I do not see an easy way to specify anything other than the user_exit in the conversion code field.

    All that being said I could probably think of a few ways of doing what you're asking but in terms of the adding stuff to the user exit code itself to be read by the function program then there is no way to do this.

    Thanks,
    Jonathan



    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Rocket Software - Senior Principal Technical Support Engineer - UniData ATS
    Chuck Stevenson
    Participating Frequently
    Jul 11, 2022 4:05 PM UTC
    Hi Chuck,

    The example I highlighted was for UniData. UniData does not have the Pick Style dictionaries where 7 and 8 are the conversion and correlative. How to do to write one of the programs and use it is covered in the 'User Exits' part of the 'Using UniData' manual.  The first part of any conversion code so M,D etc all tell UniData / UniVerse how to process the conversion.

    With a conversion code of Uuser_exit  The user_exit just specifies which catalogued program to use it does not have any other options as was never designed to do so. (You may know this , others might not) Originally the user_exit code was put in place to provide Pick style calls such as U50BB. If you sort SYS_BP in UniData you'll see 30 or so  programs at the top which are user_exit replacements for old Pick style ones. Given that the user_exit template is pre-defined as well, I do not see an easy way to specify anything other than the user_exit in the conversion code field.

    All that being said I could probably think of a few ways of doing what you're asking but in terms of the adding stuff to the user exit code itself to be read by the function program then there is no way to do this.

    Thanks,
    Jonathan



    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Jonathon,
    Yes, that's what I thought.   I've always wanted it but didn't think there was a way.  Hope springs eternal.
    One way you could do it:  Allow a syntax like U[userexit]:[options]

    [options] would probably be as cryptic as with the out-of-the-box conversion codes.

    The existence of :[options] would assume another input argument argument to be passed to the userexit subroutine, or let the 2nd argument, which is currently the status outarg,  do double duty as options inarg.

    SUBROUTINE Unnnn (answer, status, data, type)
    becomes:
    SUBROUTINE Unnnn (answer, status, data, type, options)
    or
    SUBROUTINE Unnnn (answer, optionsIN.statusOUT, data, type)


    For UV users listening in, this is best described in appendix A of the "Pick Users Guide" pdf,  part of the complete UV Documentation Suite.

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------
    John Jenkins
    Participating Frequently
    Jul 12, 2022 6:06 PM UTC
    Jonathon,
    Yes, that's what I thought.   I've always wanted it but didn't think there was a way.  Hope springs eternal.
    One way you could do it:  Allow a syntax like U[userexit]:[options]

    [options] would probably be as cryptic as with the out-of-the-box conversion codes.

    The existence of :[options] would assume another input argument argument to be passed to the userexit subroutine, or let the 2nd argument, which is currently the status outarg,  do double duty as options inarg.

    SUBROUTINE Unnnn (answer, status, data, type)
    becomes:
    SUBROUTINE Unnnn (answer, status, data, type, options)
    or
    SUBROUTINE Unnnn (answer, optionsIN.statusOUT, data, type)


    For UV users listening in, this is best described in appendix A of the "Pick Users Guide" pdf,  part of the complete UV Documentation Suite.

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------
    Chuck,

    As two trains of thought:
    1) You can always pass a dynamic array as an argument - e.g. both the data and extended conversion options in separate elements. A Multivalue data set in field1 and conversion options in field 2 for example.

    2) CALLC is also an option for anything particularly awkward or performance sensitive.
    I have used CALLC many times in the past for tasks such as:
    • Time-critical byte-level processing of data blocks.
    • TCP communications (before this was made available in BASIC)
    • File-transfer (MV-to-Other MV - long before FTP and TCP were available) using peer-to-peer. MV to IBM mainframe ('Pick Angel' of memory)
    • Driving auto-diallers, modems, interactive voice synthesisers and a cash-register interface (amongst others).
    (I have been around long enough to remember when 'Interrupt-Clock-Reset-Sense Switch One-Load-Run was a weekly -and occasionally suddenly  required - event).

    Regards

    JJ

    ------------------------------
    John Jenkins
    Thame, Oxfordshire
    ------------------------------
    JJ
    Chuck Stevenson
    Participating Frequently
    Jul 13, 2022 9:00 AM UTC
    Chuck,

    As two trains of thought:
    1) You can always pass a dynamic array as an argument - e.g. both the data and extended conversion options in separate elements. A Multivalue data set in field1 and conversion options in field 2 for example.

    2) CALLC is also an option for anything particularly awkward or performance sensitive.
    I have used CALLC many times in the past for tasks such as:
    • Time-critical byte-level processing of data blocks.
    • TCP communications (before this was made available in BASIC)
    • File-transfer (MV-to-Other MV - long before FTP and TCP were available) using peer-to-peer. MV to IBM mainframe ('Pick Angel' of memory)
    • Driving auto-diallers, modems, interactive voice synthesisers and a cash-register interface (amongst others).
    (I have been around long enough to remember when 'Interrupt-Clock-Reset-Sense Switch One-Load-Run was a weekly -and occasionally suddenly  required - event).

    Regards

    JJ

    ------------------------------
    John Jenkins
    Thame, Oxfordshire
    ------------------------------
    JJ,
    I appreciate your thoughtful reply.  Some further thoughts or explanation of the problem.  1st,  I'm on UV, not UD.  I realize the thread started with a UD discussion,  but if I recall UD correctly, what I'm calling a shortcoming is essentially the same.
    From your CALLC  comments, it sounds like you're addressing the general case, which includes old Pick-style user exits in Pick-style Procs.
    My interest is user-defined conversion codes in dictionaries.

     "You can always pass a dynamic array as an argument - e.g. both the data and extended conversion options in separate elements. A Multivalue data set in field1 and conversion options in field 2 for example."

    For ICONV/OCONV user exits, the syntax is restricted to:

         SUBROUTINE Unnnn (answer, status, data, type)

    Retrieve populates & reads the arguments when it calls the subroutine.
    In a dictionary,  one could monkey with what's passed in the 3rd argument, to include options  not just data.  But system delimiters must be avoided.  Something like:
    01: I
    02: CATS( RAW.DATA, REUSE( ":[options]" )
    03:U[user exit]

    but at that point it's easier, clearer to just use a garden variety I-descriptor subroutine.  Which is what we do today.

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    US
    ------------------------------
    Jul 13, 2022 12:15 PM UTC
    Bill ... How would you programmaticly get the system to find out what post code it is in. Finding the systems time zone can be found out via a Unix or Windows command... or you could even enquire on the system or users time zone environment variable. I am not aware of any easy way to get the post code that a system or user is in and then how would you tie translate that to the timezone the post code is in.

    Thanks



    ------------------------------
    Jonathan Smith
    UniData ATS
    Rocket Support
    ------------------------------
    Jonathan - I believe "Bill" was asking about your statement..."As a normal practice I wouldn't be posting example code onto the forum unless" - why? As a developer's forum, this is where I go to bounce ideas/code with other developers, we share code snippets and the like.  Yes, we have to be mindful of relevant IP and NDAs, but a snippet of code is not a violation, especially in this case of an OCONV/ICONV hack.  I, as well, am curious, "as a normal practice", why not post code? A lot of colleagues on this site, post, we analyze, discuss, bounce ideas off each other, etc.  This is more or less our sandbox to play discuss/develop ideas/concepts and the like.

    ------------------------------
    Stacy Mecklenburg
    Senior Developer
    Software Solutions Unlimited
    San Anselmo CA US
    ------------------------------