开发者

Primary and full procedural files in RPG

What is the difference between primary and full开发者_JS百科 procedural files as defined in RPG?


A primary file uses the RPG logic cycle for reading through your data. A full procedural file is one where your logic controls access to your data records. Full procedural files are by far the most common usage. In fact, I don't think I've ever written a program that uses the logic cycle since school. I rarely see them in the wild.

The RPG logic cycle works roughly like this:

  1. Read a record in the primary file.
  2. Perform level-break calculation specs
  3. Move the data from the file area to fields in your RPG program
  4. Perform detail level calculation specs
  5. Go back to the beginning.

After the last record is read, the LR indicator gets set and level break calculations are executed and then the program ends.


Yes, it is COMPLETELY different in RPG. Same database table, but 100% different way of program logic.

This choice is the heart and soul of RPG programming. Therefore, start reading the RPG Programmer's guide.

If you are new to iSeries programming (and by your other questions I know you are ;-), then use full procedural files. This is simular to other languages and systems.

Even better, use the latest version of ILE RPG. This support all the concepts that you know from other languages (procedures, functions, local variables and free format). Older versions are also quite good and do what they are made for, but their concepts are a little bit more exotic.


A 'P'rimary file is somewhat similar to a SQL FROM table. With SQL, you don't need to state explicitly when to read the next row from a table when you run an UPDATE or DELETE statement; you only need to state which rows to process with WHERE and possibly what actions to take against columns. You have no direct control over the timing of disk I/O in the underlying logic; RPG (and SQL) takes care of that automatically.

But it is also possible to use SQL's FETCH statement to have more direct control over individual row processing. You can think of a RPG 'F'ull-procedural file like a SQL FETCHed table. With 'F'ull-procedural processing, you will need to code operations (verbs) such as READ or WRITE in order to move from record to record.

In that sense, moving from the older culture of RPG 'P'rimary files to the later RPG 'F'ull-procedural files is like going to a more primitive form of database interaction before something more modern like SQL existed.

Yet, concurrent and later on-going advances in the RPG language simultaneously allowed RPG to evolve to today's fully free-form language that has no necessary visual relationship to its early roots as merely a 'R'eport 'P'rogram 'G'enerator. Today, it's effectively used by many systems programmers on IBM i possibly more often than C. (C still has a couple notable advantages, e.g., it has advanced optimizers that aren't available for other languages, bit-level operations such as shifts, etc.; it depends on what functions are needed whether RPG is appropriate or not. Faster development is certainly possible in RPG.)

To understand the uses of 'P'rimary (and 'S'econdary and related) files, it's necessary to understand how the RPG "Cycle" works. If 'F'ull-procedural files are used, you effectively code your own version of a 'cycle'. What you get in return is a 'cycle' that doesn't limit you in any way; the logic is exactly the way you code it to be.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜