Control Language Programming for IBM i

Control Language Programming for IBM i

Control Language Programming for IBM i

Control Language Programming for IBM i

Paperback(New Edition)

$79.95 
  • SHIP THIS ITEM
    Qualifies for Free Shipping
  • PICK UP IN STORE
    Check Availability at Nearby Stores

Related collections and offers


Overview

Covering the basics of Control Language (CL) programming as well as the latest CL features—including new structured-programming capabilities, file-processing enhancements, and the Integrated Language Environment—this resource is geared towards students learning CL. The book guides readers towards a professional grasp of CL techniques, introducing complex processes and concepts through review questions, hands-on exercises, and programming assignments that reinforce each chapter’s contents. In addition to 25 chapters that cover CL from start to finish, a comprehensive appendix with condensed references to the most commonly used CL commands is also included along with two additional appendixes that cover the essentials of programming tools and debugging.

Product Details

ISBN-13: 9781583473580
Publisher: MC Press, LLC
Publication date: 09/01/2011
Edition description: New Edition
Pages: 592
Product dimensions: 8.30(w) x 9.90(h) x 1.30(d)

About the Author


Jim Buck is a programmer with more than 25 years of experience, an analyst instructor at Gateway Technical College, and the president of the Wisconsin Midrange Computer Professional Association. He is the coauthor of Mastering IBM i and the recipient of the 2007 IBM System i Innovation-Education Excellence Award. He lives in Kenosha, Wisconsin. Bryan Meyers is the author of numerous books, including Desktop Guide to CL Programming, RPG IV Jump Start, and VisualAge for RPG. He lives in Billings, Montana. Dan Riehl is the president of the 400 School and the IT Security and Compliance Group, LLC. He is a writer and technical editor for System iNEWS and the author of Control Language Programming for the AS/400. He lives in Chesterfield, Missouri.

Read an Excerpt

Control Language Programming for IBM i


By Jim Buck, Bryan Meyers, Dan Riehl

MC Press

Copyright © 2008 Jim Buck, Bryan Meyers, and Dan Riehl
All rights reserved.
ISBN: 978-1-58347-358-0


CHAPTER 1

What Is CL?

* * *

Chapter Overview

This chapter examines the unique role of the IBM i operating system's Control Language (CL) in relation to other computer languages and describes CL's strengths and weaknesses. Emphasis is placed on the use of CL to control workflow and to define job streams to the System i computer. You will become familiar with the contrast between CL and typical high-level languages (HLLs), such as Cobol and RPG. The chapter also contains a brief discussion of compiled and interpreted CL, along with an explanation of the execution environment restrictions in effect when you use CL commands.


What CL Is

Control Language (CL) is a set of commands that you use to control operations and to request system-related functions on the IBM System i computer. IBM provides CL as an integrated part of the IBM i operating system (formerly known as i5/OS, and before that as OS/400), not as a separate product.

As a means of controlling workflow, CL serves purposes comparable to Job Control Language (JCL) on mainframe computers. CL, however, provides much more functionality than JCL. In some respects, CL is similar to the PC-DOS, Windows, or Linux commands you may use on a PC. Operations such as copying files, redirecting output, and making directories in those operating systems have direct CL counterparts.

CL originated on the IBM System/38 computer in the late 1970s and continued as the principal system-control language when IBM introduced the AS/400 in 1988. The AS/400 version of CL provided many enhancements over the S/38 version, including new commands and other added functionality. As the AS/400 and its OS/400 operating system evolved into the System i and its i5/OS, now IBM i, operating system, the system retained CL as its system-control language, making the necessary enhancements and changes to support new features and capabilities. Because of similarities among the various versions of CL, many S/38 and AS/400 CL commands and programs can be used on the System i, and vice versa.

A single CL statement is called a command. A CL command is the primary means of interacting with the System i. Nearly everything the computer does is requested by a command. There are commands to create and delete objects, commands to start programs, a command to power down the system, and even a command to create a command.

You can think of a command as an instruction to the computer to perform some function. For example, the DLTF (Delete File) command instructs the System i to delete a file. This command would be comparable to the DEL command, which is a part of DOS on personal computers. Most CL commands are supplied by IBM as part of the operating system, but you also can create your own commands, customized to your own installation's particular needs.

CL, as shipped by IBM, consists of thousands of commands but still maintains a useful consistency that makes the language easy to learn and to understand. You can use most CL commands in at least two ways: by typing them individually onto a command line and by grouping them together into a CL program. CL programs typically consist of multiple CL commands that define procedures or operations on the computer. By combining multiple commands within a CL program, you can automate most System i operations.

You should write CL programs to perform repetitive processing, thereby reducing errors and operator/user intervention. CL also is a natural choice for many utility programs that control or monitor system-related activities on the System i. Here are a few of the many functions CL can perform:

• Start jobs by calling programs or by submitting jobs for batch processing

• Control the sequence of processing within a program and among different programs

• Check for the existence of objects in the system and check for security authorizations to objects

• Create and manage system objects (e.g., files, programs, commands)

• Handle error conditions caused by commands or programs

• Control the operation of an application by establishing the values of variables used in the application, such as date, time, and other external information

• Control communications

• Send messages between programs and users or between programs and other programs

• Manage work on the system

• Create the environment in which a job will execute, controlling attributes such as which objects the job will use, what its execution priority will be, and how it will respond to unexpected errors

• Manipulate variable information, byte strings, and date formats

• Change the configuration of your server and define the devices attached to it


What CL Is Not

Although CL is very rich in function, it is not, in the classical sense of the term, considered to be a high-level language (HLL). You would not, for example, write a payroll application using CL exclusively. For such application programming on the System i, you would use a combination of CL and an HLL such as RPG or Cobol. You would use CL to implement the system-related procedures and functions of the application, and you would use the HLL to perform operations such as screen handling, file updates, and complex business logic. CL is used to manipulate and control an application's execution environment, generally as a "front end" to the HLL application programs.

Why wouldn't you use CL exclusively to create a typical business application? Because many functions perform better or are easier to write using an HLL, and CL just cannot do some computer operations. For example, CL programs can't add or update records in a database file, and CL has very limited printing capabilities. CL programs do not support the use of subfiles within application displays, nor do they support individual fields in program-described files. Database manipulation with CL is limited to reading files, and only a small number of files can be opened for I/O operations in a CL program. These missing pieces in CL make it unsuitable for developing a complete business application.


Controlling Workflow with CL

CL programs control the workflow of an application by letting you create job streams, which consist of CL commands to be executed in order. Within a CL program, you can alter the order of execution by testing various conditions that may exist during the execution of a job. You can monitor for errors that might occur while running a job and perform corrective actions or abort the job. You can pass values, or parameters, to and from CL programs to make them more flexible and to permit or restrict the execution of blocks of program code.

A CL program can incorporate conditional logic and special functions that are not available when you enter individual commands on a command line. You can also test and debug a CL program, just like any HLL program.

CL programs, unlike JCL, are implemented as compiled program objects rather than interpreted job streams. A CL program is a permanent object on the System i, created by compiling a group of CL commands.


CL Execution Environment and Restrictions

As you've learned, you can enter individual CL commands into the system interactively on a command line or include them in a CL program. You can submit individual CL commands and compiled CL programs for batch processing using the SBMJOB (Submit Job) command. Commands can also be included within a REXX language procedure.

If you group CL commands together, they can be compiled into a program object or submitted for interpretation during a batch process using the SBMDBJOB (Submit Database Job) command.

Some CL commands, such as STRSEU (used to start the Source Entry Utility), are valid only when used interactively. Others, such as CRTCLPGM (used to compile a CL program), should be used only within a batch process.

Several CL commands, such as GOTO and ENDPGM, are valid only when they appear within a CL program. You will become familiar with any such restrictions as we discuss the individual commands in detail.


An Introductory Program

So, what does a CL program look like? The following example is a simple CL program that sends a message to the user who runs the program.

We discuss the fine details of CL programming later. For now, here's an overview of what is happening in this program. First, the CL program defines three variables that will be used later in the program: the user of the program (&user), the current system date (&date), and the current system time (&time). Next, the program retrieves the name of the current user (i.e., the person who is signed on to the server), along with the current date and time. Finally, the system "glues together" a message and then sends the message to the user. For example:

Hello, JDOE, Login date-010112 time-152307

As you progress through this text, you'll learn more about the CL commands used in this program and become familiar with other CL commands and with the flavor of a CL program.


Chapter Summary

Control Language (CL) is a set of commands included with the IBM i operating system. You use CL to control operations and to request system- related functions on the System i.

Even with thousands of IBM-supplied commands, CL maintains a consistency that makes it easy to use and learn. You can type individual CL commands on a command line, or you can group commands together and compile them into a CL program.

You can use CL programs to perform repetitive processing, thus reducing errors and the need for operator intervention.

CL is not a high-level language (HLL), in the classical sense of the term, as Cobol and RPG are.

CL programs are compiled objects, not interpreted job streams.

CL commands can be entered interactively on a command line. A CL command or program can be submitted for batch processing using the SBMJOB (Submit Job) command. A group of CL commands can be compiled to form a program object, or they can be interpreted in a batch process using the SBMDBJOB (Submit Database Job) command.

Some CL commands are valid only when run interactively; others are valid only when they appear within a CL program.


Key Terms

CL program

Command

compiled program object

conditional logic

Control Language (CL)

CRTCLPGM

high-level language (HLL)

interpreted job stream

Job Control Language (JCL)

job stream

REXX language procedure

SBMDBJOB

SBMJOB

STRSEU


Review Questions

1. Which of the following programming objectives might be satisfied with CL programming?

a. Provide unattended overnight backup of system objects that have changed since the last weekly backup.

b. Control a sequence of programs to write vendor checks and post them to a general ledger.

c. Enforce a policy of changing a user's password every 50 times the user signs on to the server.

d. Provide unattended change of the system clock to or from Daylight Savings Time.

e. Store comprehensive information about a firm's customers in a database.

f. Monitor the status of all communications lines attached to a server.

g. Calculate the amortization of a loan.

h. Calculate payroll amounts for standard deductions and federal income withholding.

i. Print a vendor listing including vendor name, address, and amount owed.

2. CL can be used on which of the following computers?

a. IBM System i

b. IBM System z

c. IBM System x

d. IBM AS/400

e. Apple Macintosh

f. IBM 3090 mainframe

g. IBM System/38

h. IBM System p

3. Which of the following file operations can you perform with CL?

a. Read records from a database file

b. Update records in a database file

c. Read the records from several database files

d. Make a copy of a file

e. Delete a file

4. If a CL program is written for V4R2 of i5/OS, is this program compatible with a newer version of i5/OS or IBM i — for example, with IBM i 6.1? Explain why or why not.

5. What command is used to create a CL program?

6. Can all CL commands be executed from the command line?

7. Explain why CL is not considered an HLL.

8. List the functions that CL can perform.

9. Research why a language such as CL is needed on a system. Why isn't all processing handled by HLLs?

CHAPTER 2

Control Language Command Names

* * *

Chapter Overview

This chapter addresses the way CL command names are structured. You will become familiar with the abbreviations used to denote common actions, subjects, modifiers, and subject phrases that determine CL command names.


Verbs and Subjects

You learned in Chapter 1 that CL is made up of thousands of IBM-supplied commands. How will you ever learn them all? Although CL command names may seem foreign to you initially, learning them will not be as daunting a task as it first seems. IBM developed the language in a logical, consistent manner that makes it relatively easy to determine the name of the command required to accomplish a given task. Once you learn the simple logic behind the IBM naming conventions, you'll find it easy to understand and use most of the commands.

CL command names are a shorthand form of the standard grammar for an English-language imperative statement. Each command is an instruction to the computer to perform an action. The commands consist of a verb, or action, followed by the subject that will be acted upon (in English grammar, we refer to the subject as the object, but because "object" has a specialized meaning on the System i, we use the word "subject" here for clarity). For example, the CL command to edit the contents of a database file is EDTF, the imperative statement being "edit a file." The command consists of two parts: the verb EDT, an abbreviated form of the English verb "edit," and the subject F, a shorthand form of the word "file."

If you were to guess what the CL command would be to "delete a program," you might guess, correctly, that the verb would be "delete" and the subject would be "program." Shortening the verb "delete" would produce the CL verb DLT, and shortening the word "program" would produce the CL subject PGM. When you combine the CL verb and subject, the result is the CL command DLTPGM.

CL command names are limited to a maximum length of 10 characters. The verbs are usually represented by three characters (e.g., DLT for delete, EDT for edit), and the subjects are usually represented by one to three characters (e.g., F for file, PGM for program).

A challenge exists when you know the imperative statement that describes the function you want the computer to perform, but you do not know the CL abbreviation for the verb or subject. For example, suppose you want to "send a message" to someone on the system, telling him or her that you are free for a meeting today at two o'clock. You know that the verb is "send" and the subject is "message." But how do you correctly guess the CL shorthand version of the verb and subject?

There are a number of choices for an abbreviated version of the verb "send." You could guess SEN, SND, SED, or even the entire verb SEND. And the abbreviated version of the subject "message" could be MES, MSG, M, or many other combinations of the letters contained in the word "message." The correct CL command for "send a message" is SNDMSG. SND is the CL shorthand for the verb "send," and MSG is the abbreviated version of the subject "message." However, as you can see, determining the correct shorthand version could require some guesswork on your part. A general rule of thumb is that CL abbreviates words to their three most significant consonants. When a CL abbreviation includes a vowel, it is usually the first vowel or the only vowel in a word.

Fortunately, once you know CL's shorthand version of a word, that shorthand version usually will be consistent, regardless of where in the command name it is used. For example, the command to display information about the data stored on a tape is DSPTAP. DSP is the verb, and TAP is the subject. CL also lets you initialize a tape for use on the system. In this case, the subject TAP does not change, but the action you want to perform — the verb — changes from display to initialize. The standard CL verb for initialize, INZ, replaces the verb DSP to form the command INZTAP (Initialize Tape).

The following table lists some common English verbs and their CL abbreviations.

While many English verbs have their consistent shorthand version in CL, so also do subjects. For example, the command to display a tape, as you now know, is DSPTAP. CL also lets you display information about the data stored on an optical disk (e.g., CD, DVD). To form the command that performs this function, you use the same verb shorthand, DSP, but you use the subject shorthand OPT, for optical volume, the new subject. When you combine the two abbreviations, you get the command DSPOPT, to "display an optical volume."

The following table lists some commonly used subjects and their CL abbreviations.


(Continues...)

Excerpted from Control Language Programming for IBM i by Jim Buck, Bryan Meyers, Dan Riehl. Copyright © 2008 Jim Buck, Bryan Meyers, and Dan Riehl. Excerpted by permission of MC Press.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

From the B&N Reads Blog

Customer Reviews