D and P Position-less Specs, Part One

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

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.

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

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.

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

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.

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

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).

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

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.

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

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: