.st0{fill:#FFFFFF;}

Updating Numeric DTAARA in RPGLE 

 October 17, 2019

By  NickLitten

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:

Updating Numeric DTAARA
*LDA

Of course this string of data can be populated with a mixture of values:

Updating Numeric DTAARA in RPGLE 1
*LDA populated with different datatypes

So, since a DataStructure in RPG is always character – how do we update a numeric only data area?

Updating a Numeric Data Structure in RPG/FREE

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.

Updating Numeric DTAARA in RPGLE 2

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:

Updating Numeric DTAARA in RPGLE 3
Splattery death of updating a numeric DS

How do we fix this?

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 šŸ™‚

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad 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 remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

  • In your example you change two things. You go from DS to single variable, but you also go from zoned to packed. *DEC is packed. Zoned is stored differently on disk so zoned wouldn’t work regardless. Just curious if you tried that and it still didn’t work?

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
    __CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

    Get In Touch

    Iā€™m always looking for awesome input, feedback and critique!

    >