Virtual Field

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Fromm603
Posts: 31
Joined: Fri Apr 26, 2019 10:51 pm

Virtual Field

Post by Fromm603 »

Trying to create my first virtual field. Our IBMi database stores the date in 4, 2 character fields (each 2,0). I want to create a virtual field that is MMDDYY (don't need century). My virtual field derivation looks like the below, is there a better way?

#SOendymd := (#soendy.AsString + #soendm.AsString + #soendd.AsString).AsNumber

Somehow this doesn't seem to work all of the time.
caseywhite
Posts: 192
Joined: Thu May 26, 2016 1:17 am

Re: Virtual Field

Post by caseywhite »

I suspect the issue is that single digit numbers are being set to a 1 character string instead of 2 character string left padded with 0's. If you change your code to the following it will probably resolve your issue.

#SOendymd := (#soendy.AsString.RightAdjust(2 '0') + #soendm.AsString.RightAdjust(2 '0') + #soendd.AsString.RightAdjust(2 '0')).AsNumber
Post Reply