Tuesday, September 17, 2013

I Hate Suffix Data types

Lotusscript has been around a long time, and it has some nuances that can drive a person crazy. In particular ME. This is even more true when attempting to process data from an external database with long legacy roots.  Taking a page from BASIC, Lotusscript provides a convenient way to implicitly type variables called the data type suffix.  I really don't know what they are any more, and I don't care.  I would rather explicitly declare my variables anyway.  Fortunately Lotusscript allows me to force that.  Just put Option Declare in the (Options) section of the script, and you are on your way. Usually...

I was happily porting a Domino database which retrieved certain data points from a PRMS database to get that data from an Epicore CMS database. This all resides on a state of the art Power System running IBM i as the operating system.  But Epicore has a long tradition with IBM going back at least o the AS/400 days and a time where RPG only allowed 8 character field names. This led to many creative abreviations, and the frequent use of special characters like # to mean number.  So I am trying to retrieve an invoice number from and A/R Transaction file and the field name is something like ARINV#. Makes sense if you only have 8 characters to work with.  Enter Lotusscript and the Lotus connectors extension.  It is easy enough to read the record and pull out most of the data I want into a Notes document like so:

doc.customer = rec.arcust(0)
doc.name = rec.arcnam(0)
doc.invoice = rec.arinv#(0)

And there I have a problem.  Even though I have told Lotusscript to force explicit definitions, Lotus connector extension (*lclsx) has declared ARINV as in integer because of the data type suffix at the end of the variable name.  Not only does it now think a character variable is really an integer (CMS defines this field as a character), but it thinks the variable name is really ARINV not ARINV#. Charming.

Now the fix looks ok for this field

Dim arinvno As LCField
Set arinvno = rec.Lookup("arinv#")
doc.invoice = arinvno.Text(0)

But you have to remember that doesn't work for all data types.  If it were an integer I would have had to type:

Dim arinvno As LCField
Set arinvno = rec.Lookup("arinv#")
doc.invoice = arinvno.GetInt(1)

And now we are so far from consistent code that if you don't do it every day, or you don't have a reference manual laying around you are just plain out of luck.  Where the heck did the 1 come from?  Turns out that the Get<Type> functions use a 1 based index where nearly everything else in Lotusscript uses a 0 based index. You gotta love that.

SOAPBOX OFF