Radinator
Radinator

Reputation: 1088

Advantage of defining a prototype in D-Specs in RPGLE

I recently learned somthing about loacal procedures in fixed format RPG IV and their definition either in the D-Specs and implementation in P-Specs section or omitting the D-Specs definition.

According to the IBM Documentation, if I omit the definition in D the compiler will automatically generate the necessary definition from the procedure interface followed by the P-Spec where I implement my procedure.

Now I wonder what is the advantage of defining the procedure interface two times? Is there any benifit of writing (almost) the same code twice (in D-Specs in the top and below the P-Spec) or is this just a option for the programmer to have some meaningfull place where to define the input/outpu parameter for the procedure?

Thanks in advance

Upvotes: 0

Views: 552

Answers (2)

Brian Sleeth
Brian Sleeth

Reputation: 1

In most cases a D-spec prototype is not required. However, a prototype is required if the subprocedure returns a value and you use "LIKE(subprocedure-name)" to declare variables like the return value.

d doStuff         pr            10a                               
d  input                              like(doStuff)               
d                                     const                       

In the above example, the parameter "input" is defined like the return value of the subprocedure "doStuff". If you do not include the D-spec prototype, the program will not compile.

Upvotes: 0

jmarkmurphy
jmarkmurphy

Reputation: 11493

Starting at IBM i v7.1, for internal procedures, there is no advantage to creating prototypes, and in fact there is a risk that you will get them wrong (though that issue is easily detected and corrected). Prior to that, all procedures required a prototype. For procedures that are exported from a service program, or a module, the prototypes are critical. I keep those in a separate copy book so that I can include the same prototypes in my module source, and in the source of the program using the module. In this way you only have to have a single copy of the prototypes floating around, and it is easy to include wherever you need them.

Upvotes: 8

Related Questions