IBM Support

Everyone knows what X'7D' means ... unfortunately

General Page

You are in: RPG Cafe > Avoid X'7D'

Short URL:

RPG Cafe: Don't use x'7D'

Everyone knows what X'7D' means ... unfortunately

cmd = 'ADDPFM LIB/FILE MBR(' + mbr + ') '
+ 'TEXT(' + X'7D' + text + X'7D' + ')';

Unfortunately, too many RPG programmers know what X'7D' means. It is a common coding technique to code X'7D' when a single quotation mark is wanted in an RPG program. However, using X'7D' for a single quotation mark can be unclear for some programmers, and it could give incorrect results in some cases.

RPG has syntax for a single quotation mark character. Similar to 'A' being a single A character, you code '''' for a single quotation mark character. The inner quote has to be doubled because that's how RPG handles quotes within a character literal.

Which is more readable, X'7D' or ''''? Neither is readable.

Instead of using either X'7D' or '''' within your calculations, use a named constant. Call it QUOTE or SINGLE_QUOTE or APOSTROPHE. Define it in a /copy file and copy it in whenever you need it.

cmd = 'ADDPFM LIB/FILE MBR(' + mbr + ') '
+ 'TEXT(' + QUOTE + text + QUOTE + ')';

The new question is "How to define the named constant?" In one way, it doesn't matter, since the meaning of the constant is clear from its name.

But it must be defined as '''':

  1. X'7D' is not a single quotation mark in ASCII or UTF-8. If you append X'7D' to an ASCII or UTF-8 string in RPG, it is treated as a hexadecimal literal in ASCII or UTF-8. You do not get the results you expect.

Try this program:

dcl-s fld_job  char(3) ccsid(*jobrun);
dcl-s fld_utf8 char(3) ccsid(*utf8);
dcl-c BAD_QUOTE x'7d';
dcl-c GOOD_QUOTE '''';

fld_job = 'abc';
fld_utf8 = 'abc';
dsply (fld_job + BAD_QUOTE);
dsply (fld_utf8 + BAD_QUOTE);
dsply (fld_job + GOOD_QUOTE);
dsply (fld_utf8 + GOOD_QUOTE);

It displays the following:

DSPLY  abc'
DSPLY  abc}
DSPLY  abc'
DSPLY  abc'

[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SS69QP","label":"Rational Development Studio for i"},"Component":"ILE RPG Compiler","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

Modified date:
16 December 2019