Good news! There are more control statements to look at. I just didn’t want to make the last chapter too long. I know. You are thankful I am so considerate. It is my great weakness. “I am a martyr to my own generosity.”
Editor's Note: This article is excerpted from chapter 14 of 21st Century RPG: /Free, ILE, and MVC, by David Shirey.
So here’s the /Free scoop on D- (including PR and PI) specs and P-specs.
D-specs
If you have read the previous chapter, you can guess that things start not with a D in column 7 but with the data structure control keyword (DCS), dcl-ds, somewhere in columns 8–80.
This will then be followed by the data structure name, and whatever keywords that might be required.
dcl-ds Product_rec likerec(PMP100);
or if you like to leave a bit of space:
dcl-ds Product_rec likerec(PMP100);
As with the file control statement, use of ellipses is not supported.
Something else that is different from the control statements we have seen so far is that there are several types of data structure keywords, each one representing a different type of data structure.
We have already seen one of those, the dcl-ds, which is used for straight data structures, as shown above. But there are other types of data structures, and each has its own format.
DCS: Named Constants
The first thing that you can define are named constants, fields that can be set and then referred to by their name rather than their value. That is, if you have a field:
Cust_Code = '15';
what does that really mean? If you are a data junkie, then you know this is a customer who is “retail with a national base,” but for me, it is meaningless. If you use a named constant, however:
Cust_Code = Retail_Nat;
then it is much clearer what you are talking about.
In positional RPG, this was done by using a C in the definition type of the D- spec.
In /Free data structure control statements, however, we use the dcl-c keyword. The use of the CONST keyword is optional; the statement works the same with or without it. Once the constant is defined, you can use it in your program. And I honestly don’t know why I said that. Sort of stands to reason, doesn’t it?
dcl-c Initial_Date D'2010-01-01';
Or, if you like using the CONST keyword as a special reminder that it is a named constant field:
dcl-c Initial_Date CONST(D'2010-01-01');
DCS: Standalone Field
You can also define standalone fields, single fields that stand on their own rather than being part of a larger structure.
As you might expect, it starts with a dcl-s and ends with a semicolon. This is followed by the name of the standalone field.
That is followed by any keywords you want to specify. The first keyword must either be LIKE or the data type and length. Following are some examples. If you use LIKE, then no other keywords may be specified, although you may enter a length adjustment.
DCS: Data Structures
The data structure formulation is just a bit more verbose, but I definitely like the structure it imposes.
It starts with a dcl-ds. This is followed by a name. Or not. Data structures may either be named or unnamed (in which case a *N is put where the name would be). . Then come zero or more keywords to describe the data structure. And finally the semicolon.
If we are dealing with a program-defined data structure (that is, one where there are subfields under the main control statement), then we need to add an end-ds with an optional name field.
If the field is unnamed, then obviously, when you code the end-ds, you cannot put the name of the data structure in parentheses; you just use end-ds . End-ds is not used if you have the LIKE keyword on the top level because then you are unable to define subfields.
If you are defining subfields, you can also use the dcl-subf thing to identify what the subfields are. Please note that this is optional. Most of the time it should be pretty obvious, and for me it just gives something else to look at and confuse your visual receptors. The only time you have to use it is if the name of the subfield is the same as an RPG operator (e.g., WRITE).
DCS: Overlay
This is a small point but an important one, and it deserves a section of its own. Ready? Brace yourselves. The Overlay keyword is now only supported in specific situations.
Specifically, you can only use it to overlay subfields. It cannot be used to overlay the entire data structure.
Now remember, this is only when you are using the data structure control statements. And there is no support at all for the Overlay(ds:*next) because that means there is no set position—just put it after the last field in the data structure, which is meaningless. It amounts to no overlay functionality.
Since you can intermix the new control statements with the old D-specs, you could still use the Overlay on the D-spec. What replaces Overlay for the free- format specs is POS(999), where you can specify the position in the data structure that a particular field is going to start in.
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