On Mon, Aug 10, 2015 at 7:54 PM, Dan <dan27649@xxxxxxxxx> wrote:
Thanks Vern. I knew I had seen this type of combo statement before.
Unfortunately, I need variable p in a subsequent statement's %subst
function, so no sense doing two scans per iteration.
Yeah, so you just have to devote a line to assigning p, so you can
reuse the value later.
It often happens that you need two (or more) lines in RPG for common
tasks that seem like maybe they could be squeezed into one. Perhaps
the most basic and common of these is looping over records in a file
without using the built-in cycle.
It always felt a little wasteful to me that a single loop needed two
READx statements (or a CHAIN and a READx). Or, if you were determined
to write the loop with only a single READx statement, then you'd need
an extra comparison (you couldn't rely on the loop's conditional,
because it was in the wrong place; you needed an IF inside the loop to
break out of it). Both of these seem uglier than necessary to me:
setll
reade
dow not %eof
<stuff>
reade
enddo
setll
dow True
reade
if %eof
leave
endif
<stuff>
enddo
Eventually I got over it. I learned to accept that this is how RPG is
built, and these are both probably idiomatic RPG. (I even gave up
using CHAIN with HI indicator at the top and READE with EQ indicator
at the bottom, in favor of being able to use %EOF.)
Another example, back before RPG IV, was getting the remainder of a
division. You had to do the division by itself on one line (often
throwing away the result), then retrieve the remainder on the next. So
clumsy.
Face it, RPG is not made to be concise. It's made to be simple to
implement, simple to write, and simple to read. And I'd say it meets
those goals pretty well.
John Y.
As an Amazon Associate we earn from qualifying purchases.