In last week's newsletter, I referred to something called the "Two-Digit Prefix Syndrome." Many of you responded to tell me that I used the wrong word -- I meant "Two-Character Prefix Syndrome!" You're absolutely right, that's what I meant! Thanks for pointing it out.
One thing that I did not mention last week is that RPG's PREFIX keyword has the ability to strip the prefixes from the fields of a file and replace them with a different prefix. For example, in my shop we have a file called ITMMAST. Every field in that file has a two-character prefix of IM. If I wanted to, I could change that prefix in my RPG program using the PREFIX keyword. In the following example, the IM is changed to XX:
FITMMAST IF E K DISK prefix('XX': 2)
The second parameter to the PREFIX keyword tells the RPG compiler how many characters to strip off of the field name. It removes the first two characters, which are IM in the ITMMAST example, and then adds the XX prefix to the start. So a field that was previously called IMDESC will now be called XXDESC.
The LIKEREC keyword will define a data structure that has the same fields as a record format that you've defined in your program. Using it in combination with the PREFIX keyword leads to the interesting ability to strip one prefix and add the name of a qualified data structure as a new prefix. Consider the following code:
D ITEM DS likerec(ITMMASTF:*INPUT)
chain key ITMMASTF;
The PREFIX keyword strips off the first two characters, in this case IM, from every field. It adds "ITEM." as a new prefix so that the data will be read into a qualified data structure named ITEM. That'll now be the record format that RPG uses for this file. Since LIKEREC copies the definition that the F-spec has for the file, it'll also be without the IM prefix. The result is that I've changed the field name from IMDESC to ITEM.DESC.
You can read the previous article about eliminating the two-character prefix syndrome at the following link: