April 20


RPG coding tip #73 – using [H SPEC COPYRIGHT]

By NickLitten

April 20, 2013

copyright, cttl-opt, hspec

RPG4 (or RPGLE as its sometimes known) has a neat and little used header specification command called ‘COPYRIGHT’

Presumably, this h-spec function was originally implemented by IBM so that software houses can embed their object copyright within the program source. But us RPG developers are a resourceful lot, and the H SPEC COPYRIGHT statement is an excellent way of storing the current modification version of any given program object.

Genuine ibm i developer

Sometimes, I am working on a version of a program and planning on making many changes during the coming days or maybe weeks. For structured testing of these code versions, or to allow a different colleague to work on a ‘code-frozen’ earlier version, I might want to store the iterative versions in different levels of a testing environment. You could do this by changing the program object description to add a version number V1.1, V1.2, V1.3, V2 etc But this it can be far too easy to have a fat finger moment, or to just forget.

So, how do we control versions in RPG?

Simples — using the COPYRIGHT H-SPEC actually embeds the version number within the program object itself.

By adding the H COPYRIGHT comment into the first line of code, means we can look at the compiled version (and of course the related source code if you have it) and clearly see the version number. For example, adding something like:

In the OLD VERSION of RPG you would use a H-Spec

H COPYRIGHT('My Company © 2017 YADA YADA  |  Nick Litten V1R1 last changed July 2017')

In the CURRENT VERSION of RPG you would use free format

dcl-opt copyright('My Company © 2017 YADA YADA  |  Nick Litten V1R1 last changed July 2017');

to a program and compile it.

This text is free-format and can contain a character literal with a maximum length of 256.
So, when you issue a DSPPGM (program-name) you see the comment embedded in the actual program object itself. Here is an example from the Projex4i Toolkit:

H spec copyright
H SPEC COPYRIGHT with modification history on line 3

Super useful and easy way of recording the source code changes.


You can do the same technique with CL and with RPG including it as a DUMP variable as well

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips