.st0{fill:#FFFFFF;}

The RPG Logic Cycle 

 October 14, 2008

By  NickLitten

The RPG LOGIC CYCLE is the backbone of the old RPG programming language. It’s use has faded in recent years but it should still be known and understood by every modern RPG language Developer 😉

So, regardless of whether you want to code modern or *cough* old style….

lets see what the ‘RPG Logic Cycle’ offers

The first and last time the program goes through the cycle is slightly different from all the in-between cycle runs:

Before the first record is read the first time through the cycle, the program resolves any parameters passed to it, writes the records conditioned by the First Page (1P) indicator, does file and data initialization, and processes any heading or detail output operations. This may also include printing heading lines.

During the last time a program goes through the cycle, when no more records are available, the LR (last record) indicator and L1 through L9 (control level) indicators are set on, and file and data area cleanup is done.

At the most basic level think of the logic cycle as a simple tool for handling all file reading for you. As simple breakdown of the cycle is this:

rpg logic cycle

All heading and detail lines (H or D in position 17 of the output specifications) are processed.

The next input record is read and the record identifying and control level indicators are set on.

Total calculations are processed. They are conditioned by an L1 through L9 or LR indicator, or an L0 entry.

All total output lines are processed. (identified by a T in position 17 of the output specifications).

It is determined if the LR indicator is on. If it is on, the program is ended.

The fields of the selected input records are moved from the record to a processing area. Field indicators are set on.

All detail calculations are processed (those not conditioned by control level indicators in positions 7 and 8 of the calculation specifications) on the data from the record read at the beginning of the cycle.

Before you get too scared

Realistically no body would use the logic cycle anymore… not since the mid 90’s anyway…. modern RPG /FREE and a modularized clean coding approach is obviously the favored technique.

Sometimes good style and efficient runtime performance don’t mix. Wherever you face a conflict between the two, choose good style. Hard-to-read programs are hard to debug, hard to maintain, and hard to get right. Program correctness must always win out over speed.

  • Make it right before you make it faster.

  • Keep it right when you make it faster.

  • Make it clear before you make it faster.

  • Don’t sacrifice clarity for small gains in efficiency

Phew I hear you say.

But if you want to see more then a more detailed breakdown of the cycle is attached here. 

[thrive_link color=’blue’ link=’https://www.nicklitten.com/wp-content/uploads/rpg_logic_cycle.pdf’ target=’_self’ size=’medium’ align=”]RPG Logic Cycle PDF[/thrive_link]

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:

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

>