RPG Divide and Move Remainder – DIV MVR in ILE RPGLE /FREE 

 April 23, 2019

By  NickLitten

This is purely a little memory jogger for me. Nothing to read here move along move along…..

I just upgraded an old program that had a piece of code doing this:

C  DS#POS Div  256         POSLIN 
C         Mvr POSCOL

This old RPG400 code is reading the cursor position from the display file information data structure and doing some divisions then MOVING REMAINDER into a field to find the column. Quite smelly code I know, but also code that doesnt translate into modern RPG very well.

I had to scratch my head to remember how to do DIVISION and REMAINDERS in modern ILE RPG. so decided to quickly blog it so that I dont forget again.

I changed the file information data structure into a qualified data structure and then rewrote it in modern RPG like this:

poslin = infds_dspf.RowColumn / 256;
poscol = %rem(infds_dspf.RowColumn:256);

Some of the archaic whiff has been polished off. It’s nice because you dont need the actual divison statement anymore you can use a much simpler, cleaner %REM big to get your remainder:


C  A Div 256 B
C         Mvr C


C = %rem(A:256);

Still Confused?

Here is a little example from the IBM Manual:

dcl-s A int(10) inz(123);                   
dcl-s B int(10) inz(27);
dcl-s DIV int(10);
dcl-s REM int(10);
dcl-s E int(10);

DIV = %DIV(A:B); // DIV is now 4
REM = %REM(A:B); // REM is now 15
E = DIV*B + REM; // E is now 123


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Trekkie, 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.

Nick Litten

related posts:

{"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!