Blog
iDevelop

« OCEAN Views | Main | Scratching the Programming Itch »

July 30, 2014

Comments

Birgitta Hauser

Yet an other reason why to work with real date and time values:

SQL provides a lot of scalar functions for date and time caluclation that can be easily used in RPG.

Example:
/Free
Exec SQL Set :MyWeekIso = Week_ISO(:MyDate);
Dsply MyWeekIso;

Exec SQL Set :MyMonthEnd = Last_Day(:MyDate);

Exec SQL Set :NextMonday = Next_Day(:MyDate, 'Monday');

Exec SQL Set :IsWeekEnd = Case When DayOfWeek_ISO >= 6 Then '1' Else '0' End;
/End-Free

Those functions only work with real date/time fields. SQL does not play very nicely with numeric date/time fields.

So why reinventing the wheel.

Birgitta

John Erps

I'm always a bit surprised / irritated when the argument is something like this, that it takes more processing time or disk space. In my view in 99% it's just a scapegoat to not follow/implement decent rules (maintainability/correct) because too much time or too difficult etc. In this day of age, especially on IBM i and Power 8 these days, disk space is abundant and cheap (compared to labor), and - especially on IBM i - there is plenty of excess processor time. So i can't really imagine that turning off something like date validation really has a noticeable impact. For me it's an obscure feature which should be only used in very specific circumstances (and really well documented) where you for example want to process a billion records with 20 date fields, in a tight loop or so. And even then. Just 3 years ago i was "advised" by an old geezer - when making an RPG/400 program - to sort the subroutines such that the one most called is at the front. Because it improves performance.... really. And other nice bits such as "use as less work fields as possible". It just means that that person really has no idea, whatsoever, what's happening in the OS (or the compiler in this specific case). I mean, putting the most called subroutine in front only has a noticeable impact if the computer still uses drum memory. The last drum memory that IBM produced was in 1962. :)

The comments to this entry are closed.