D and P Position-less Specs, Part Two

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

PR and PI D-Specs - Yes, the PR and PI structures are D-specs, but because they are very special D- specs they get their own control statements.

Missed Part One?  Read it here.

Editor's Note: This article is excerpted from chapter 14 of 21st Century RPG: /Free, ILE, and MVC, by David Shirey.

Fortunately, things for the PI and PR specs are done pretty much the same way as normal data control statements are. And the end-pi/end-pr is not required, but I like it.

D and P Position-less Specs, Part Two - Figure 1

If you have a return value coming back, and you use a keyword to set the data type, then that must be indicated on the PR line of the complex.

As with data structures, if a subfield associated with a P-spec is the name of an RPG opcode, then you have to use the dcl_parm thing on the front of the subfield definition.

D and P Position-less Specs, Part Two - Figure 2

If there is no name for the group, then you can use *N just as you could for data structures.

D and P Position-less Specs, Part Two - Figure 3

On the PR, the extpgm keyword is optional; if you don’t code it, the compiler will default to using the name of the PR group as the program name being called. But this is only if the program name is 10 characters or less, otherwise it will initiate the Star Trek “Frank Gorshin” destruct sequence.

Also on the PR group, if the program you are calling has a mixed-case name, then you need to use the extproc keyword.

dcl-pr          EL3write          extproc('EL3write');

Or you could use the *dclcase to avoid retyping the name.

dcl-pr          EL3write          extproc(*dclcase);

This can sometimes help prevent typo errors if you have several programs you are calling that have similar names, and you copy lines but forget to change the name in the extproc keyword. Or, you can stop using mixed-case, weirdo names that you can easily screw up. Your choice.

D and P Position-less Specs, Part Two - Now It's Your Turn

P-Specs

Finally, we get to the procedures syntax in free format. In spec language, these are defined by a P-spec, but using the new free-form format, it starts with a dcl- proc with a procedure name and keywords and ends with the end-proc (the procedure name on the end-proc is optional). This end-proc is required.

dcl-proc        procedure-name     keywords;

end-proc    procedure-name;

I know by now you are all set with simple examples, so here is one that is a little more complex. But I think you can see that the basic principles are the same.

D and P Position-less Specs, Part Two - Figure 5

D and P Position-less Specs, Part Two - Now It's Your Turn

If/Then/Else in a Control Statement

I know. This is really weird. But with the 7.1 TR7 you can actually imbed If/Then/Else commands within the position-less control statements.

Now I know what you are thinking: why? Right?

Well, maybe you want to vary the keywords that are associated with a file. Or a data structure.

Or maybe you just like to make things very complicated. There are a lot of people who like to do that. I have read many of their articles.

To be honest, it doesn’t really matter why you would want to do this; what’s important is you can.

And seriously, sometimes it might be helpful to be able to assign file control statement keywords based on some external thingy. Like suppose you had a flag that was set based on a user profile value, and it indicated a level of trust: either an input-only or update state. You could control that with code like this built right into where your F-specs would go now. And don’t confuse the slash in front of the IF with the // that indicates a comment. These are not comments.

D and P Position-less Specs, Part Two - Figure 6

D and P Position-less Specs, Part Two - Now It's Your Turn 3

Mixing File and Data Control Statements

Historically, we keep F- and D-specs apart because that is just the way things are done. You don’t mix whiskey and vodka, do you? No normal person would do that, would they? No. But if you have a recipe that does so, I would be curious, just from an intellectual point of view, of course. But I digress.

Some of it is just how you think. I like seeing all the file control statements at one point, but some people may prefer to see everything associated with one file in one spot. I can see advantages to that actually, and maybe I should rethink how I do things. But the chances of that are small. Anyway, you could have the file control statement, followed by all the data control statements related to that file before the next file control statement. I have to admit, I may eventually like that. But I doubt it.

Another use would be if you want to define a non-character key for a file. If we go back a chapter, we saw that key fields defined on the file control statement had to be character-type fields. But now you could embed a data control statement in there and set up a data structure for the character field that was packed, for example:

D and P Position-less Specs, Part Two - Figure 7

The point is, you now have a lot more flexibility in how you do things, and eventually you will find ways to use that flexibility.

D and P Position-less Specs, Part Two - Now It's Your Turn 4

What Ya Shoulda Learned

There is a lot of detail in here, and I am not going to go back through it and list every single fact we covered. I guess the salient points are the basic structure of the control statements and what the keywords and options are for each one.

Obviously, it will take some practice for you to feel as comfortable with them as you do with our old friends the F/D/H/P-specs.

But moving forward is a part of life, and I think this is an important part of your RPG life. If you are on a release that supports this, take a couple of programs, just for practice to start with, and convert them to the appropriate control statements.

In the end, this is something you practice and get good with, rather than just memorizing.

Want to learn more?  You can pick up Dave Shirey's book, 21st Century RPG: /Free, ILE, and MVC, at the MC Press Bookstore Today!

David Shirey

David Shirey is president of Shirey Consulting Services, providing technical and business consulting services for the IBM i world. Among the services provided are IBM i technical support, including application design and programming services, ERP installation and support, and EDI setup and maintenance. With experience in a wide range of industries (food and beverage to electronics to hard manufacturing to drugs--the legal kind--to medical devices to fulfillment houses) and a wide range of business sizes served (from very large, like Fresh Express, to much smaller, like Labconco), SCS has the knowledge and experience to assist with your technical or business issues. You may contact Dave by email at This email address is being protected from spambots. You need JavaScript enabled to view it. or by phone at (616) 304-2466.


MC Press books written by David Shirey available now on the MC Press Bookstore.

21st Century RPG: /Free, ILE, and MVC 21st Century RPG: /Free, ILE, and MVC
Boost your productivity, modernize your applications, and upgrade your skills with these powerful coding methods.
List Price $69.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: