Control Language
| Company type | Scripting language |
|---|---|
| Industry | Computer software |
| Founder | IBM |
| Headquarters | United States |
| Products | Command objects (*CMD), CL programs |
The Control Language (CL) is a scripting language created by IBM initially for the System/38 Control Program Facility, and subsequently adopted in OS/400 (currently known as IBM i). It shares similarities with IBM's Job Control Language and is composed of command objects (*CMD) that either trigger programs or offer assistance. Additionally, CL supports the development of CL programs—comparable to shell scripts—featuring commands that facilitate program control structures (such as IF/ELSE), variable declarations, and file handling.
CL was primarily crafted for system management tasks and is predominantly used to generate compiled programs; interpreted CL scripts executed through the SBMDBJOB command are seldom utilized.
IBM created an extensive set of commands designed to manage system-level operations including program compilation, data backup, configuration adjustments, and object administration. Beyond system maintenance, commands can also be tailored for user-defined applications.
Commands and programs
In System/38 and AS/400 environments, program parameters (command-line arguments) are defined as fixed sequences consisting of numeric, alphanumeric, Boolean, or other data types where the order is critical. This contrasts with Unix or DOS systems where parameters are typically arrays of character pointers without positional constraints.
To overcome this limitation, IBM introduced the concept of command objects (*CMD). These allow parameters to be entered in any sequence while internally aligning them with the program’s expected parameter order. Developers specify each parameter’s type, identifier, prompt description, default values (applied if omitted), and any constraints or transformations prior to passing them to the program.
Fundamentally, a command represents a single program that executes upon invocation. It aggregates both user-provided and default parameters into a structured list delivered to the program during execution.
Syntax
The simplified CL command syntax can be expressed in BNF as follows: <syntaxhighlight lang="bnf">
<CL-command> ::= command-name [<positional-parameter-list>] [<named-parameter-list>]
<positional-parameter-list> ::= <parameter-value> [<positional-parameter-list>]
<named-parameter-list> ::= parameter-name "(" <parameter-element-list> ")" [<named-parameter-list>]
<parameter-element-list> ::= <parameter-value> [<parameter-element-list>]
<parameter-value> ::= CL-name |
qualified-CL-name |
"*"special-value |
generic-CL-name"*" |
"'"alphanumeric-value"'" |
numeric-value |
"X'"hexadecimal-value"'"
</syntaxhighlight> Parameters ending with -name adhere to object naming rules, typically beginning with a letter and limited to ten characters. Command names in CL are not case-sensitive.
An illustrative example is the Change Program (CHGPGM) command:
CHGPGM MYPGM OPTIMIZE(*FULL) RMVOBS(*BLKORD *PRCORD) TEXT('My program.')
This invocation includes four parameters:
- MYPGM: A mandatory positional parameter indicating the program name.
- OPTIMIZE(*FULL): A named parameter specifying full optimization.
- RMVOBS(*BLKORD *PRCORD): A named parameter directing removal of two profiling data types.
- TEXT('My program.'): A named parameter providing updated descriptive text for the program.
Parameters left unspecified default to *SAME, which means no modification occurs, except for the required PGM parameter.
Prompting
CL commands can be initiated either directly on the command line or within a CL program source by entering the command and pressing F4. Alternatively, prefixing the command with a question mark (?) also triggers prompting.
Upon prompting, the system presents a parameter entry screen that prioritizes mandatory parameters at the top and places parameters with default values toward the bottom. Pressing F10 reveals every available parameter. Parameters that depend on previous selections adjust dynamically based on chosen inputs.
This prompting feature enables users to view acceptable input values by positioning the cursor over a parameter field and pressing F4 once more, which displays input criteria and valid options.
To input extended names or specify multiple objects, entering a plus sign (+) substitutes the value field, facilitating the inclusion of longer entries or lists.
Command help
Context-sensitive help is accessible for commands but is optional. When available, placing the cursor on a specific parameter and pressing F1 provides detailed help for that parameter. For comprehensive assistance covering the entire command and its parameters, pressing F1 anywhere on the prompt followed by F2 offers extended help documentation.
Creating new commands
It is possible to develop new commands that call non-system programs while functioning similarly to native commands. The Command Definition Language (CDL) is thoroughly explained in the CL Programmer's Guide.
It is advisable to create help screens for custom commands and their parameters. These help screens utilize panel group objects (*PNLGRP), which are constructed using the UIM language outlined in the IBM AS/400 Application Display Programming manual.
Starting with version V5R3, an automated approach generates help panels through the command:
GENCMDDOC CMD(MYLIB/MYCMD) TODIR('/QSYS.LIB/MYLIB.LIB/QPNLSRC.FILE') GENOPT(*UIM)
This produces a UIM panel group template encompassing all command parameters. The generated file can be modified, compiled using CRTPNLGRP, and linked to the command by executing CHGCMD HLPPNLGRP().
Finding the right command
Version V7R3 includes 2,262 built-in IBM commands, with navigation streamlined through Standardized Abbreviations, Command Grouping Menus, and Command Selection features.
Standardized abbreviations
IBM employs standardized abbreviations for command names: verbs such as change are shortened to CHG, display to DSP, work to WRK, and create to CRT. Subjects follow similar abbreviations; for example, program becomes PGM, and user is abbreviated as USR. Users can explore all verbs and subjects via the VERB and SUBJECT menus by entering GO VERB or GO SUBJECT.
The term "Control Language Programming" is abbreviated as CLP; with ILE programming, the source type shifts to CLLE.
The VERB and SUBJECT menus belong to Command Grouping Menus. Each abbreviation of three or four letters has an associated menu starting with CMD. For instance, GO CMDCHG displays all commands beginning with CHG, while GO CMDPGM lists program-related commands.
Additional menus can be accessed by pressing F4 on a blank AS/400 command line.
Command selection
When only part of a command name is known or third-party applications use non-standard AS/400 abbreviations, users can enter the known fragment followed by an asterisk (*) and press Enter. The system then presents matching commands from the job's library list. Users may browse this list and select commands using option 1.
This capability operates through the SLTCMD command. To select every command within a library, prompt SLTCMD and input *ALL.
Sample code
This CL script facilitates interactive date conversion between Julian and MDY formats, with the output displayed on terminal line 24. It requires two input parameters: &IN, representing the date string (either in Julian format YYNNN or MDY format MMDDYY), and &TYP, indicating the desired output format ('J' for Julian or 'M' for MDY). For instance, executing CALL PGM(ICVTDATC) PARM('04180' 'M') transforms the Julian date 04180 into MDY format 062804, corresponding to June 28, 2004.
PGM (&IN &TYP)
DCL &IN *CHAR 6
DCL &OUT *CHAR 8
DCL &TYP *CHAR 1
IF (&TYP = J) +
DO
CVTDAT DATE(&IN) TOVAR(&OUT) FROMFMT(*MDY) +
TOFMT(*JUL) TOSEP(*NONE)
ENDDO
ELSE IF (&TYP = M) +
DO
CVTDAT DATE(&IN) TOVAR(&OUT) FROMFMT(*JUL) +
TOFMT(*MDY) TOSEP(*NONE)
ENDDO
SNDPGMMSG MSG('IN=' || &IN || ' OUT=' || &OUT) +
MSGTYPE(*COMP)
ENDPGM