Updating any numeric DTAARA in RPGLE is slightly different in RPG /FREEFORMAT than in the good old fashioned column based RPG/400. Using RPG ILE, data structures are treated as character data. The nature of a data area is that its a string of data that can contain a mixture of various data formats.
If we play with the local data area (*LDA) its essentially a long string of stuff:
Of course this string of data can be populated with a mixture of values:
So, since a DataStructure in RPG is always character – how do we update a numeric only data area?
Let’s stop my waffle and look at an example. That is why you are here after all.
I have a numeric DS called EMLRECNUM, cunningly designed to hold an increment count of the number of emails floated out into the ether.
Annoyingly I can define a Data Structure like this and it looks correct:
dcl-ds EmlRecNum dtaara('EMLRECNUM') qualified; count zoned(9:0); end-ds ;
and when I try to update it like this:
in *lock EmlRecNum; emlrecnum.count += 1; out EmlRecNum;
Most annoyingly it all compiles and looks/feels like a jolly simple peace of RPG code.
But when you run it… oh boy... big wet explosion follows:
If the only thing in the DTAARA is a *DEC value, use a stand-a-lone field rather than a data structure:
dcl-s EmlRecNum packed(9:0) dtaara('EMLRECNUM');
We treat the update in the exact same way:
in *lock EmlRecNum; emlrecnum += 1; out EmlRecNum;
And thats that.
But it made me scratch my head for waaay too long. So, i hope it helps some other propellor headed IBM-i programmer type chaps or chappettes or transchappies out there 🙂
IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and in the words of the most interesting man in the world: Stay thirsty my friend.
Funky IBM i Email Validation Program using SQL Regex
Using RPGLE to extract invoice numbers from an alpha string
How do we Check for Batch or Interactive in CLLE
Second Look: IBM RDi Extract Procedure Refactoring feature
Rational Developer for IBM i 9.6 Fixpack 7 is pretty pretty good
Grabbing a library description in RPG with SQL
New Developerworks RDi website is ‘IBM Rational Developer for i Hub’
How to Upload a SAVF with IBM I ACS a.k.a. Upgrade HTTPAPI (LIBHTTP) to V7.2
Developerworks Connections Sunset – How to Extend RDi