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.
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.
If there is no name for the group, then you can use *N just as you could for data structures.
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.
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.
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.
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:
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.
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!
LATEST COMMENTS
MC Press Online