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

 April 20, 2013

By  NickLitten

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.

RPG coding tip #73 - using [H SPEC COPYRIGHT] 1

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


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

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

Get In Touch

I’m always looking for awesome input, feedback and critique!


Snug CBD

 20% Discount

I have partnered with SNUG CBD givING you Organic CBD
20% discount code "NL20"