Control language (CL) is a high-level programming language used primarily on IBM's AS/400 and iSeries systems.

What Do You Mean by Control Language?
Control language is a specialized programming language developed by IBM for use on its AS/400 and iSeries systems, now known as IBM i. It is primarily designed to facilitate the automation and management of system-level tasks, providing a way to control and automate operations on these systems. CL is tightly integrated with the IBM i operating system, allowing users to write programs that can interact with system resources, manage job execution, manipulate files, and execute operating system commands.
Unlike general-purpose programming languages, CL is focused on system management and process automation rather than complex application development. It allows users to control the flow of jobs, define system parameters, and manage input/output operations without requiring a deep understanding of lower-level machine code or system internals. CL is especially useful for system administrators who need to automate repetitive tasks, such as running batch jobs, scheduling tasks, or managing file systems.
Types of Control Language
Control language can be broadly categorized into several types based on how it is used and the functionality it provides. Below are the key types of Control Language used in IBM i systems.
CL Commands
CL commands are individual instructions written in Control Language to perform specific tasks on the system. These commands can be used for various purposes such as managing files, controlling job execution, interacting with system resources, or performing system-level tasks like job scheduling. CL commands are typically executed in sequence to automate processes or manage system functions. Examples include WRKACTJOB (work with active jobs) and ENDTCPSVR (end TCP server).
CL Programs
A CL program is a collection of CL commands grouped together to perform a series of operations as part of a larger task. CL programs allow users to automate complex procedures and integrate multiple commands into a single executable. These programs are stored as objects within the IBM i system and can be executed in batch or interactive modes. They can also be called by other programs or commands, facilitating reusable and efficient automation. CL programs are typically used to automate system maintenance, job scheduling, or batch processing tasks.
CL Procedures
CL procedures are reusable blocks of code that contain a set of CL commands. Unlike CL programs, CL procedures are not standalone executables but are called within other CL programs or jobs. They provide a way to modularize code and reduce redundancy. Procedures allow system administrators and developers to write more efficient and maintainable code by breaking down complex tasks into smaller, reusable units.
CL Control Structures
CL control structures are elements within the CL language that provide the logic for managing the flow of execution. These structures allow users to create conditional execution paths, loops, and other decision-making constructs. Key control structures in CL include IF, DO, FOR, GOTO, and ENDDO, which help in controlling the flow of execution based on certain conditions or repeated tasks. These structures are vital for creating dynamic, responsive CL programs that can adapt to different runtime conditions.
CL Job Control
CL Job Control involves the use of CL commands to manage jobs on the IBM i system. This type of CL allows users to control how and when jobs are executed, monitor job status, manage job priorities, and handle job-related errors. Job control is a critical aspect of system administration, ensuring that resources are efficiently utilized and that tasks are scheduled according to system availability and priorities. Commands like CHGJOB (change job) and SBMJOB (submit job) are commonly used in job control.
Control Language Examples
Here are a few examples of control language commands and programs that demonstrate how tasks can be automated or system resources can be managed on IBM i systems:
1. Displaying Active Jobs
This CL command displays a list of all active jobs on the system.
WRKACTJOB
The WRKACTJOB command is used to work with active jobs. It presents a list of all jobs that are currently running, along with their status and other relevant details. This is useful for system administrators to monitor job activity and performance.
2. End TCP Server
This command ends a specific TCP/IP server.
ENDTCPSVR SERVER(*ALL)
The ENDTCPSVR command stops one or more TCP servers. The SERVER(*ALL) parameter specifies that all TCP servers should be stopped. This is typically used when performing maintenance on the network or system.
3. Submit Job
This command submits a job to the system for execution.
SBMJOB CMD(CALL PGM(MYPGM)) JOB(MYJOB) JOBQ(MYJOBQ)
The SBMJOB command submits a batch job. In this example, it submits a job that calls the program MYPGM. The job is placed in the job queue MYJOBQ, and it will be executed as part of the job stream.
4. Changing Job Attributes
This command changes the priority of the current job.
CHGJOB JOB(*CURRENT) INQMSGRPY(*NONE)
The CHGJOB command is used to change attributes of the job. In this example, the job's message reply option is changed to *NONE, which means the job will not wait for user input for message replies, often used in batch jobs.
5. Conditional Execution
This CL program demonstrates a simple conditional logic structure.
IF COND(&MYVAR *EQ 'YES')
SNDMSG MSG('Condition is TRUE') TOUSR(*ALL)
ELSE
SNDMSG MSG('Condition is FALSE') TOUSR(*ALL)
ENDIF
This CL program checks if the variable &MYVAR is equal to 'YES'. If it is, it sends a message indicating the condition is true; otherwise, it sends a message indicating the condition is false.
What Is Control Language Used For?
Control language is primarily used for automating and managing system-level tasks on IBM i systems (formerly known as AS/400 and iSeries). It is designed to help system administrators and developers control job execution, manage system resources, and automate a wide range of processes. Some of the key uses of CL include:
- Job management. CL is used to control and manage jobs on the IBM i system. This includes submitting jobs, monitoring job status, changing job attributes, and controlling job queues. It allows administrators to automate tasks such as job scheduling, error handling, and job termination.
- System automation. CL is frequently used to automate repetitive system management tasks. These tasks can include performing backups, managing system resources (such as disk space and memory), starting or stopping system services, and running batch jobs. This automation reduces manual intervention and ensures consistency in operations.
- File and data management. CL enables users to manipulate files and databases within the IBM i environment. It can be used to create, delete, copy, or move files, as well as manage database records. CL allows for streamlined data management and simplifies interactions with IBM iโs file systems.
- Security and access control. CL commands are often used to manage user access, assign security profiles, and control system security settings. It can be used to create and manage user profiles, control access to certain resources, and enforce security policies.
- System configuration and setup. CL can be used to configure system settings, define system parameters, and set up environments for specific applications. It provides a way to automate the configuration of various system components, ensuring the system is set up correctly and efficiently.
- Error handling and troubleshooting. CL is also employed to monitor system health and performance. If errors occur or specific conditions are met, CL programs can generate alerts, log errors, or even take corrective actions automatically, helping administrators identify and resolve issues quickly.
- Program control and execution. CL allows for the creation and execution of programs and scripts that can control other programs. CL programs can call other programs, pass parameters, and manage the flow of execution based on specific conditions or inputs.
How to Implement Control Language?
Implementing control language on an IBM i system involves writing and executing CL programs or commands to automate and manage various system tasks. Below are the general steps to implement CL:
1. Access the IBM i system. To implement CL, you first need access to the IBM i system. You can connect to the system using a terminal emulator or the IBM Navigator for i, which provides a graphical interface for interacting with the system.
2. Write a CL program or command. CL programs are typically written using the IBM i's integrated development environment (IDE) or directly from a command line interface. You can either write individual CL commands that perform specific tasks or create CL programs which consist of multiple CL commands, structured with conditional logic, loops, and other control flow mechanisms.
Here's an example of a simple CL program:
PGM
DCL VAR(&MYVAR) TYPE(*CHAR) LEN(10)
CHGVAR VAR(&MYVAR) VALUE('HelloWorld')
SNDPGMMSG MSG(&MYVAR)
ENDPGM
This CL program declares a variable &MYVAR, assigns it the value 'HelloWorld', and then sends that value as a program message to the user.
3. Save the CL program. Once you've written the CL code, you need to save it as an object on the IBM i system. This is typically done with the CRTCLPGM command (Create CL Program). Hereโs an example of creating a CL program:
CRTCLPGM PGM(MYLIB/MYPROGRAM) SRCFILE(MYLIB/QCLSRC) SRCMBR(MYPROGRAM)
This command creates a CL program from the source code in a source file. MYLIB is the library where the program will be created, and QCLSRC is the source file containing the CL code.
4. Compile the CL program (if needed). Once saved, CL programs are automatically compiled into an executable format by the CRTCLPGM command. However, if you're editing or modifying an existing program, you'll need to recompile it using the UPDPROD (Update Program) or the CRTCLPGM command again.
5. Execute the CL program. After saving and compiling, you can run your CL program using the CALL command. Here's how to call a CL program:
CALL PGM(MYLIB/MYPROGRAM)
This command calls and executes the MYPROGRAM CL program from the specified library (MYLIB).
6. Use CL in batch jobs or scripts. CL programs can also be used in batch jobs to automate routine processes. You can schedule these jobs using job scheduling commands like SBMJOB (Submit Job). This command submits a job that will execute the MYPROGRAM CL program. The job is placed in the MYJOBQ job queue for execution.
7. Debug and troubleshoot. If you encounter issues, IBM i provides several tools to debug and troubleshoot CL programs. The STRDBG (Start Debugging) command helps you debug your CL program interactively. On the other hand, you can use the MONMSG command within CL to handle errors and generate appropriate error messages for easier diagnosis.
8. Deploy and automate. After your CL programs are tested and working, you can deploy them across the system. CL is commonly used for automating tasks like backups, job scheduling and file management. By leveraging CL, you can ensure that repetitive tasks are performed automatically without manual intervention.
9. Maintain and update CL programs. CL programs often require periodic maintenance or updates to handle new system requirements or changes in business processes. You can modify existing programs by editing the source code and recompiling them. You can also add new commands or logic to improve the functionality.
Why Is Control Language Important?
Control language is important because it provides a streamlined and efficient way to automate and manage system tasks on IBM i systems, such as job control, file manipulation, and system maintenance. By allowing system administrators to write and execute scripts, CL eliminates the need for manual intervention in routine tasks, improving consistency and reliability across system operations. It also offers flexibility to control the flow of jobs, manage system resources, and handle errors, all within a language that is simple yet powerful for system-level programming.
CL's integration with the IBM i operating system ensures seamless interaction with other applications and system components, making it an essential tool for optimizing the performance and stability of the system.
Are There Any Challenges in Implementing Control Language?
Implementing control language on IBM i systems can come with certain challenges, especially when integrating it into existing workflows or managing complex tasks. Below are some common challenges in implementing CL:
- Learning curve. While CL is relatively simple compared to other programming languages, there can still be a learning curve for new users or system administrators who are unfamiliar with its syntax or command structure. Understanding the nuances of CL, especially in complex system tasks, may take time for those not already experienced with IBM i environments.
- Limited debugging tools. CL programs often lack the advanced debugging tools available in other programming languages. While basic debugging is possible using the STRDBG command, it is not as robust or user-friendly as debugging environments found in other languages. This can make troubleshooting errors in CL programs more time-consuming and difficult.
- Error handling. CL's error-handling capabilities are somewhat limited compared to modern programming languages. While basic error handling can be done using the MONMSG command, more sophisticated error management features, such as exception handling or logging, are not built into the language by default. This can make managing errors in complex CL programs more cumbersome.
- Scalability and complexity. For larger or more complex systems, maintaining and scaling CL programs becomes challenging. CL is designed for system-level tasks and is not intended for complex application development, which can lead to difficulties when trying to integrate CL scripts into larger application workflows. As systems grow in complexity, the number of CL programs and their interdependencies can become harder to manage.
- Lack of advanced features. CL is not a general-purpose programming language and lacks some of the advanced features found in modern languages, such as object-oriented programming, multi-threading, and comprehensive libraries. This can make it less suited for complex application development and may limit its flexibility in certain scenarios.
- Dependency on IBM i system. CL is tightly tied to the IBM i operating system and is not portable to other platforms. If an organization decides to migrate away from the IBM i system, the CL programs may need to be rewritten or adapted for the new environment, creating additional costs and resource requirements for migration.
- Versioning and compatibility. Over time, IBM i systems receive updates and new versions of the operating system. These updates can sometimes introduce compatibility issues with older CL programs, requiring developers to review and modify existing code to ensure it works with the latest system version.