Calling Unicode-enabled commands

Read this information to know how to pass Unicode to a Unicode-enabled CL command. This information applies to system-provided commands that have been Unicode enabled as well as any user-written commands that take advantage of the Unicode-enabled support.

CL command support for Unicode

Several system-provided CL commands support Unicode on some parameters. These commands include a note in the documentation that states the parameter is Unicode enabled. Depending on how the command is called, you can pass these commands a Unicode value for the parameter that can contain any Unicode character.

For example, the Directory (DIR) parameter of the Create Directory (MKDIR) command is Unicode enabled.

Before the DIR parameter was Unicode enabled, if you had a program that called the Process Commands (QCAPCMD) API to issue a MKDIR command, you had to pass the DIR name in the job's CCSID. This forced you to choose an EBCDIC CCSID and this might have limited your choice. For example, this limitation would show up if you wanted to create a directory that had both Greek and Russian characters. You could not do this because no EBCDIC CCSID contains both sets of characters.

Now that the DIR parameter is Unicode enabled, you can change your program to call the QCAPCMD API and pass it a Unicode directory path name on the MKDIR command. Because the name is in Unicode, it can contain both Greek and Russian characters.

If a command has been Unicode enabled, this does not affect any other invocations of the command. For example, there are no changes to any calls to the command from the QCMD prompt line. However, such calls cannot take advantage of the Unicode enablement either.

How to call the QCAPCMD API to pass Unicode to a CL command

When you call the QCAPCMD API, you have the option to pass the entire string to the QCAPCMD API as an EBCDIC or a Unicode value.

These are the possible CCSID values:

  • 0. The command input string is in the job CCSID.
  • 1208. The command string is in UTF-8.
  • 1200. The command string is in UTF-16.

If you set this value to 1208 or 1200, the entire input string must be passed in Unicode. That is, all data must be passed as the Unicode value, not just the parameters you have set to Unicode.

How to use UTF-8 source files to pass Unicode to a CL command

You can create a source member that can contain any Unicode character (character that is encoded in UTF-8) and submit this to CL for processing. For example, this allows a batch job to copy a whole set of integrated file system objects regardless of the languages in the names. Before CL is Unicode enabled, you could not do this in a single batch job because all information would be converted to one EBCDIC job CCSID and no Job CCSID supports more than one or two languages.

Here is an example of a source member that is encoded in UTF-8 with Russian and Greek file names:
//BCHJOB
MKDIR DIR('~/sample')
MKDIR DIR('~/sample/one')
MKDIR DIR('~/sample/Κέντρα πληροφοριών')
MKDIR DIR('~/sample/ποлучения дοποлнительнοй')
MKDIR DIR('~/sample/my backup info')
//ENDBCHJOB
The UTF-8 file can be created by the following command:
CRTSRCPF FILE(MYLIB/UTF8TEST) MBR(TEST) TEXT('test of utf8 file') CCSID(1208) 

After that, you need to use a UTF-8 enabled method to update the file. For example, you can use the Rational® Development Studio for i licensed program to edit this UTF-8 file directly. Then, you can use the Submit Data Base Jobs (SBMDBJOB) command to issue the request.

QCMD prompt line support for Unicode

The system QCMD prompt line does not support Unicode.