Verwandte Artikel zu Complete CL: Sixth Edition

Complete CL: Sixth Edition - Softcover

Holt, Ted

 
9781583474211: Complete CL: Sixth Edition

Inhaltsangabe

The IBM i Control Language, or CL, is the human interface to one of the most successful computing platforms ever. Mastery of this language is necessary to get the greatest benefit from the IBM i server. This book helps programmers and system administrators using IBM i get the most out of the platform by writing useful CL programs. This new edition has been updated for IBM i 7.3 and includes new built-in functions, new data types, and new support for SQL. Upon completion of the book, readers will be able to write and compile robust, production-grade programs in the IBM i Control Language, guided by a CL expert.

Die Inhaltsangabe kann sich auf eine andere Ausgabe dieses Titels beziehen.

Über die Autorin bzw. den Autor

Ted Holt holds a Master of Science degree in computer science from the University of Southern Mississippi and has taught at universities, community colleges, and vocational-technical schools. He has written numerous articles and technical tips for print and online publications, and is the author or coauthor of eight books, among them Complete CL, Power CL, and Qshell for iSeries.

Auszug. © Genehmigter Nachdruck. Alle Rechte vorbehalten.

Complete CL

The Definitive Control Language Programming Guide

By Ted Holt

MC Press

Copyright © 2017 Ted Holt
All rights reserved.
ISBN: 978-1-58347-421-1

Contents

Preface,
Chapter 1: Introduction,
Chapter 2: A First Look at CL,
Chapter 3: Constants and Variables,
Chapter 4: Basic Operators and Functions,
Chapter 5: Control Statements,
Chapter 6: Message Management,
Chapter 7: Interprogram and Intermodule Communications,
Chapter 8: Job and System Interface,
Chapter 9: Using Files,
Chapter 10: Using Quotes,
Chapter 11: Managing Objects,
Chapter 12: Batch Job Processing,
Chapter 13: Advanced Topics,
Chapter 14: Security Considerations,
Chapter 15: Sign-on Programs,
Chapter 16: Debugging,
Chapter 17: CL and the Integrated Language Environment,
Appendix A: Some Utility Commands,
Appendix B: CL Coding Style,
Appendix C: Sample Sign-on Program,
Appendix D: The Original Program Model,


CHAPTER 1

Introduction


Control Language (CL) is a programming language used primarily for control purposes with the IBM i operating system (formerly known as OS/400 and i5/OS). Originating in the early 1980s with the System/38 and continued on the AS/400, eServer iSeries, and System i, CL has undergone a series of improvements (and still does to this day). While CL is not a general-purpose, high-level language (HLL), its flexibility does allow it to be used for much more than simple control operations.

CL is based on commands. All program statements are nothing more than commands. Many of the commands are the same ones you would use manually, from the keyboard, to operate the computer.


Who Needs CL?

CL is for everyone. Because commands can be included in a CL program, you can automate most IBM i operations by writing a CL program that contains the necessary commands.

All IBM i shops are, by necessity, at least bilingual, because they must support at least two programming languages — and CL is one of them. The other language should be a high-level language such as COBOL or RPG.


Who Has CL?

Because CL is part of the computer's operating system, every system that runs IBM i has CL. Because every system that runs IBM i has CL, it should be the programming language of choice for any programs that do not require the higher functions provided by high-level languages like RPG. This would allow you to take the same program to another IBM i system with 100 percent certainty that the program will be usable. Such is not the case with other programming languages, such as RPG and COBOL, because most shops install only the compilers they need or wish to use. Yet, CL is absolutely everywhere.


Capabilities of CL

With CL you can do any of the following:

• Control system power up and power down.

• Change the configuration of the system through changes in system values or line, controller, and device descriptions.

• Manage work on the system by controlling subsystems, job queues, job priorities, memory pools, time slices, and so on.

• Start other jobs by calling programs directly or by submitting jobs to batch processing.

• Control system security by performing security checks or by actually changing user and object authorities.

• Control all forms of communications between your IBM i system and other systems (peers, hosts, PCs, remote controllers).

• Manage objects in libraries. Objects can be created, duplicated, changed, deleted, reorganized, cleared, renamed, and allocated with CL programs.

The preceding list is not all-inclusive. CL contains more than 1,000 commands with diverse functions.


Limitations of CL

As previously noted, CL is not an HLL. CL cannot accomplish everything a language such as RPG can accomplish.

• Database manipulations are limited to reading files. You cannot use CL commands to directly update or write individual records in database files. CL procedures can call APIs and run SQL commands to interact with databases, but not with the ease that HLLs can.

• CL supports only six data types: character, decimal, logical, signed integer, unsigned integer, and pointer.

CHAPTER 2

A First Look at CL


What better way to begin a study of CL programming than by looking at a typical CL procedure?


The Parts of a CL Procedure

A procedure is a compilable set of CL commands. Dissecting and analyzing the various parts of a CL procedure serve as a good introduction to CL. Figure 2.1 shows a typical CL procedure. The lines that make up a CL procedure can be called CL statements or CL commands. The two terms are interchangeable.

Figure 2.2 illustrates the structure of a typical CL procedure. The sections that follow explain each individual part of the procedure.


The PGM Command

The PGM (Program) command (Figure 2.3) identifies the beginning of the procedure.

The PARM parameter lists the parameters coming into (or going out of) the procedure. The example shown in Figure 2.3 contains only one parameter, called &greeting, which is a CL variable.


The COPYRIGHT Command

The COPYRIGHT command (Figure 2.4) provides a way to embed copyright information within a CL module. It is optional. If used, the COPYRIGHT command must follow the PGM command, and it must precede the global MONMSG (Monitor Message) commands and all executable commands.

To view the copyright information, use the DSPMOD (Display Module) command.


The Declarations

Figure 2.5 shows some examples of DCL (Declare CL Variable) commands.

Each DCL command defines a single variable to the CL procedure. All variables must be declared at the beginning of the procedure.

The DCL command has eight parameters, but only the first two are required. The first parameter, VAR, names the variable being declared. The second parameter, TYPE, indicates whether it is a character, decimal, unsigned integer, signed integer, logical, or pointer variable. The LEN parameter, indicates the variable's length. In addition, the VALUE parameter gives the variable its initial value. The other four parameters are used much less frequently than these.

In Figure 2.5, the parameter keywords VAR, TYPE, and LEN have been omitted to keep the procedure uncluttered. You could also code the DCLs as shown in Figure 2.6.

Also, notice that all variables are the *CHAR (character) type.

Besides DCL, the declaration section of the procedure can contain up to five DCLF(Declare File) commands. The examples shown in Figures 2.5 and 2.6 do not include any DCLF commands.

You may also include a DCLPRCOPT (Declare Processing Options) command in the declarations. Use this command to specify compiler options. In this way, you will ensure that future compilations are created with the proper option values and avoid nasty surprises that could arise if the wrong option values were used. Options that are specified in DCLPRCOPT override the options in the CRTBNDCL (Create Bound CL Program), CRTCLMOD (Create CL Module), and CRTCLPGM (Create CL Program) commands.


Global MONMSG

Although the MONMSG command is described at length in chapter 6, it deserves a brief mention now. An example is shown in Figure 2.7.

The MONMSG command is used to take corrective action when an error is detected by the system after executing any command in a CL...

„Über diesen Titel“ kann sich auf eine andere Ausgabe dieses Titels beziehen.