Control Language Programming for IBM i Jim Buck, Bryan Meyers, and Dan Riehl First Edition First MC Press Printing—August 2011 © 2008 by Jim Buck, Bryan Meyers, and Dan Riehl. All rights reserved. Every attempt has been made to provide correct information. However, the publisher and the authors do not guarantee the accuracy of the book and do not assume responsibility for information included in or omitted from it. The following terms are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both: IBM, IBM i, i5/OS, OS/400, System i, iSeries, AS/400, Power Systems, Integrated Language Environment, Rational, and WebSphere. A current list of IBM trademarks is available on the Web at http://www.ibm.com/legal/us/en/copytrade.shtml. Microsoft and Windows are registered trademarks of Microsoft Corporation in the United States, other countries, or both. Java and all Java-based trademarks are trademarks or registered trademarks of Oracle and/or its affiliates in the United States, other countries, or both. Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. UNIX is a registered trademark of The Open Group in the United States and other countries. Other company, product, or service names may be trademarks or service marks of others. Printed in Canada. ALL RIGHTS RESERVED. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. MC Press offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include custom covers and content particular to your business, training goals, marketing focus, and branding interest. MC Press Online, LLC Corporate Offices P.O. Box 4886 Ketchum, ID 83340-4886 USA For information regarding sales and/or customer service, please contact: MC Press P.O. Box 4300 Big Sandy, TX 75755-4300 USA Toll Free: (877) 226-5394 For information regarding permissions or special orders, please contact: [email protected] ISBN: 978-1-58347-358-0 To our wives, Sandy and Kathea — the best riding, sailing, and life partners anyone could hope for — Jim Buck and Bryan Meyers For my wonderful children, Heather, Donn, and Simone And for my new grandson, Asher Ezekiel Riehl — Dan Riehl Acknowledgements Our deep gratitude goes to all who participated in making this new edition a reality. At MC Press Online, Merrikay Lee and Katie Tipton helped to smooth the transition to our new publisher. Katie also performed editing magic on our rough manuscript (converging multiple authors’ writing styles into one is no mean feat). Jan Fonda is responsible for the layout and the “look” of the book (we think it looks pretty great, Jan). Special thanks go to Guy Vig and Fernando Hurtado of IBM, who provided us with “heads up” information about new features in Release 6.1 and who guided us through a couple of rough spots in illustrating them. ~ For errata and other updates to this book, go to http://www.mc- store.com/5507.html. For information about instructors materials, please contact MC Press at [email protected]. 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