Message files and message descriptions offer a convenient method of storing messages and text. The IBM i OS itself makes extensive use of message descriptions for all sorts of user communication, program to program messages, display panel constants, command definition prompts, and error text to mention some of the most prominent and visual employments. I’ve previously published a couple of articles discussing and displaying how to use message descriptions as an extension to the system request menu as well as how to replace display file constants with message identifiers and texts.
Being such a versatile and widely used facility, message files and message descriptions also have a lot to offer in the domain of application development. In terms of for example user dialog, error handling, and multi-language support, message descriptions provide a flexible and comprehensible approach that can easily be incorporated and maintained by using the many message handling APIs and CL commands available. Having taken advantage of the message facilities included with the IBM i, I’ve often needed to copy a message description, but IBM hasn’t provided a Copy Message Description (CPYMSGD) command, but this article does!
If you need to copy message descriptions from one message file to another, the Merge Message File (MRGMSGF) command helps you, but only if the message identifier won’t change. Copying and renaming a message description is impossible. Because the Retrieve Message (QMHRTVM) API can return all message description attributes, I can write my own CPYMSGD command! More about the CPYMSGD command in a minute.
A message description has quite a few attributes. A quick count on the Add Message Description (ADDMSGD) command prompt finds 17 parameters in addition to the primary Message identifier (MSGID) and Message file (MSGF) parameters. Some of these are really only useful for messages sent by the IBM i, but others are valuable to programmers like me. I briefly mention some of the most useful ones here, but I urge you to look up the ADDMSGD command’s help text for more details.
Download the save file containing the source code.