Can the length of *CCHAR replacement data change?

The length of *CCHAR replacement data can change. This is why *CCHAR replacement data is required to be a variable-length field.

The length of the field grows when converting from an SBCS CCSID to the UCS-2 Level-1 CCSID. The length of the field shrinks when converting from the UCS-2 Level-1 CCSID to an SBCS CCSID.

For example, you define message description TST0011 as 'Printer &1; has error &2;' in message file MYMSGF that has a CCSID of 65535. '&1' is defined as *CCHAR data (*VARY 2) in length. This is the name of the printer. &2; is defined as a *CHAR data with a length of 1. This is an error code. Enter the following Send Program Message command to send this message to message queue MYMSGQ:

SNDPGMMSG MSGID(TST0011) MSGF(MYLIB/MYMSGF) TOMSGQ(MYLIB/MYMSGQ) +
MSGDTA(X'000400500030F1') CCSID(61952)

X'0004' is the length of the variable *CCHAR data. X'00500030' represents the characters P0 in CCSID 61952. If message queue MYMSGQ has a CCSID of 00037, the replacement data is converted to X'0002D7F0F1' before it is sent to the message queue. If message queue MYMSGQ has a CCSID of 65535, the data is not converted when it is sent to the message queue.

Your application programs cannot hard-code the position of the return code in this example. When message queue MYMSGQ has a CCSID of 00037, the return code is 5 bytes into the message text. When message queue MYMSGQ has a CCSID of 65535, the return code is 7 bytes into the message text.