You are previewing Complete CL: The Definitive Control Language Programming Guide, Fourth Edition.
O'Reilly logo
Complete CL: The Definitive Control Language Programming Guide, Fourth Edition

Book Description

The effective use of Control Language (CL) is a critical skill for anyone working with IBM's robust midrange eServer family (i5, iSeries, and AS/400). But why settle for just enough CL knowledge to get by? From the simplest task to the most complex process, CL is at the heart of your server. Become a CL guru and fully leverage the abilities of your system. All it takes is a little time, effort, and Complete CL, 4th Edition.

Authors Ted Holt and Ernie Malaga present the latest version of a classic, bringing together all the basics of CL, plus the latest innovations in one thorough, well-organized, and easy-to-read package. In a clear, straightforward manner, the authors teach you how to write both simple and advanced CL programs, how to understand the strengths and limitations of CL, how to avoid common mistakes, and much, much more. With this book, you will master CL and extend the capabilities of your i5/iSeries. Programmers, operators, security officers, system administrators, or any IT professional working with OS/400 and i5/OS will benefit greatly by reading this book.

When getting by isn't good enough, get Complete CL, 4th Edition.

Complete CL, 4th Edition is fully updated to include the numerous enhancements to IBM's i5/OS, including a beefed-up compiler with new control structures, new data types, a new way to create documentation, a relaxation of old limits, and more.

In this latest edition, you'll learn how to:
- Code sophisticated looping techniques with the new control structures(SELECT, DOWHILE, DOUNTIL, and DOFOR)
- Expand your coding capabilities with the new integer data types
- Get beyond file processing limitations by learning how to process multiple files in a CL program
- Utilize IBM's powerful APIs by learning to pass parameters to procedures by value
- Use V5R3 control structures, variable types, and other enhancements
- Plus, you'll develop the skills needed to:
- Manipulate strings with built-in functions and operators
- Code looping and decision structures
- Make CL procedures communicate with users or with one another via messages
- Use data queues and data areas
- Understand and use overrides effectively
- Process display and database files
- Use APIs
- Effectively use the QTEMP library
- Understand and avoid the pitfalls of adopted authorities
- Understand security issues
- Develop a good CL coding style
- Understand differences between OPM and ILE
- Use CL in both batch and interactive processing
- Compile CL programs and modules and bind modules into programs
- Use the interactive debugger

Table of Contents

  1. Copyright
  2. Preface
  3. 1. Introduction
    1. Who Needs CL?
    2. Who Has CL?
    3. Capabilities of CL
    4. Limitations of CL
  4. 2. A First Look at CL
    1. The Parts of a CL Procedure
      1. The PGM Command
      2. The COPYRIGHT Command
      3. The Declarations
      4. Global MONMSG
      5. The Body of a Procedure
      6. The ENDPGM Command
    2. Entering the Source Code with SEU
      1. The Source Physical File
      2. Starting SEU
      3. Formatting the Statements with F4
      4. Uppercase or Lowercase?
      5. Positional Parameters or Keywords?
      6. Continuing on the Next Line
      7. Indented or Unindented?
    3. Compiling the Procedure
      1. The CRTBNDCL Command
      2. Output of CRTBNDCL
    4. Executing the Program
    5. Optional Components of a CL Procedure
      1. Blank Lines
      2. Comment Lines
      3. Comments on Command Lines
  5. 3. Constants and Variables
    1. What Is a Constant?
      1. Character Constants
      2. Decimal Constants
      3. Integer Constants
      4. Hexadecimal Constants
      5. Logical Constants
    2. What Are Variables?
      1. Declaring Variables
      2. Where Variables Can Be Used
      3. Parameters
  6. 4. Basic Operators and Functions
    1. The Chgvar Command
    2. Arithmetic Operators
      1. Substring Function
    3. Concatenating Strings
    4. Simulating Arrays in CL
    5. Binary Conversion
      1. Logical Operations
    6. Expressions and Operator Hierarchy
    7. The Cvtdat Command
  7. 5. Control Statements
    1. The If Command
      1. Simple Logical Expressions
      2. Complex Logical Expressions
    2. The Do and Enddo Commands
      1. Single-Level DO Groups
      2. Nesting DO Groups
      3. Nesting IF Commands
    3. The Else Command
      1. Using Do with ELSE
    4. The Select Command
    5. The Dowhile Command
    6. The Dountil Command
    7. The Dofor Command
    8. The Leave and Iterate Commands
    9. The Goto Command
    10. The Call and Callprc Commands
      1. Passing Variables as Parameters
      2. Passing Constants as Parameters
    11. The Endpgm and Return Commands
    12. The Tfrctl Command
  8. 6. Message Management
    1. What is a Message?
    2. Message Queues
      1. Permanent Message Queues
      2. Job Message Queues
    3. Types of Messages
      1. New versus Old
      2. Purpose of the Message
      3. Impromptu and Predefined Messages
    4. Using Predefined Messages
      1. Message Files
      2. Message Descriptions
    5. The Sndpgmmsg Command
      1. What to Say in the Message
      2. Who Should Get the Message
      3. Type of Message
      4. Getting the Reply
      5. Message Key
    6. The Sndusrmsg Command
      1. Sending Impromptu Messages
      2. Sending Predefined Messages
      3. Type of Message
      4. Who Gets the Message
      5. Receiving the Reply
    7. Messages that Can Be Monitored
      1. Parameters
      2. Program-Level (Global) MONMSG
      3. Command-Level MONMSG
      4. Specific and Generic Monitoring
    8. The Rcvmsg Command
      1. Get the Message from Where?
      2. Which Message to Receive?
      3. Message Received—Now What?
      4. How Long to Wait?
      5. Remove the Message Received?
      6. Examples of RCVMSG
    9. Other Message Management Commands
      1. Remove Messages (RMVMSG)
      2. Send Reply (SNDRPY)
      3. Send Message (SNDMSG)
      4. Send Break Message (SNDBRKMSG)
      5. DSPMSG and WRKMSG
      6. Clear Message Queue (CLRMSGQ)
    10. The System Reply List
      1. Purpose of the System Reply List
      2. Using the System Reply List
      3. Pitfalls
    11. Message Subfiles
      1. The Display File
      2. The CL Program
  9. 7. Interprogram and Intermodule Communications
    1. Using Parameters
      1. Parameter Variables
      2. Parameter Constants
      3. Limitations
    2. Using Data Areas
      1. The CRTDTAARA and DLTDTAARA Commands
      2. The CHGDTAARA, RTVDTAARA, and DSPDTAARA Commands
      3. Special Data Areas
    3. Using Switches
      1. Turning Switches On and Off
      2. Testing the Switches
      3. Using the Switches
    4. Using Messages
      1. Another Look at SNDPGMMSG
      2. Another Look at RCVMSG
    5. Using Data Queues
      1. Types of Data Queues
      2. The CRTDTAQ and DLTDTAQ Commands
      3. Sending, Receiving, and Clearing Data Queues
      4. Retrieving Data Queue Description
      5. Receiving from Data Queue without Deletion
      6. Utility Commands
      7. Advantages of Data Queues
      8. Disadvantages of Data Queues
  10. 8. Job and System Interface
    1. Library List Support
    2. Retrieving System Values
    3. Changing System Values
    4. The Rtvjoba and Chgjob Commands
    5. The Rtvusrprf, Chgusrprf, and Chgprf Commands
    6. The Rtvneta Command
    7. Summary of the Retrieve (RTV) Commands
  11. 9. Using Files
    1. Record-by-Record Processing of a File
      1. The DCLF Command
      2. The RCVF, WAIT, and ENDRCV Commands
      3. RCVF and Random Input
      4. The SNDF and SNDRCVF Commands
    2. Processing a File as a Whole
      1. Creating and Deleting Files
      2. Processing Database File Members
      3. The OVRXXXF and DLTOVR Commands
      4. Sorting with OPNQRYF
    3. Capturing Output Using Qtemp
      1. Using Permanent Work Files
      2. Using Outfiles
      3. Capturing OUTPUT(*PRINT)
  12. 10. Using Quotes
    1. Using Quotes in CL
    2. Embedded Quotes
      1. Expressions, Character Strings, and Command Strins
      2. Multiple Quotes
      3. Using an &QUOTE Variable
  13. 11. Managing Objects
    1. Creating Objects: The CRTXXX Commands
    2. Deleting Objects: The Dltxxx Commands
    3. Checking Existence: The Chkobj Command
    4. Retrieving Description: The Rtvobjd Command
    5. Retrieving Description: The Rtvmbrd Command
    6. Creating Duplicates: The Crtdupobj Command
    7. Manipulating Objects: Movobj, Chgobjd, and Rnmobj
    8. Allocating: The Alcobj Command
  14. 12. Batch Job Processing
    1. The Concept of Batch Processing
    2. Job Queues
    3. The Sbmjob Command
    4. An Unexpected Problem with Sbmjob
    5. Working with Submitted Jobs
    6. The Qsysopr Message Queue
    7. Self-Submitting Programs
  15. 13. Advanced Topics
    1. How to Code Selective Prompting
      1. A Common Mistake
      2. Making the Prompt Selective
    2. Notes
    3. Using Qcmdchk
      1. Calling QCMDCHK
      2. Selective Prompting and QCMDCHK
    4. Using Qcmdexc
      1. Why Bother with QCMDEXC in CL?
      2. Commands Not Allowed
    5. Using Qclscan
      1. Calling QCLSCAN
    6. Using Qdcxlate
      1. Standard Translations
      2. Using DLYJOB
      3. DLYJOB with DLY
      4. DLYJOB with RSMTIME
    7. Using Rclrsc and Rclactgrp
    8. Retrieving CL Source
      1. The RTVCLSRC Command
  16. 14. Security Considerations
    1. Securing the *Pgm Object
      1. An Example
      2. Securing an Object
      3. Take Care of *PUBLIC
    2. Adopting Authority
      1. Ownership
      2. Adopting Authority
      3. Another Example
      4. Adopted Authority from Other Programs in the Call Stack
      5. Other Risks of Adopted Authority
    3. Command Lines
      1. Limited Capabilities
      2. Pros and Cons of Command Lines
      3. Appearing Command Lines
  17. 15. Sign-On Programs
    1. Using Job Descriptions
    2. What Job Descriptions Cannot Do
    3. Sample Sign-On Program
  18. 16. Debugging
    1. The Strdbg Command
    2. The Enddbg Command
    3. Debugging Views
    4. An Example Interactive Debugging Session
    5. Debugging in Source View
    6. Other Important Debugger Commands
    7. Summary of Debugger Commands
    8. Debugging in List View
    9. Debugging in Statement View
    10. OPM Programs and the ILE Debugger
    11. Debugging Another Job
    12. The Dmpclpgm Command
  19. 17. CL and the Integrated Language Environment
    1. Types of Object Code
    2. Binding
      1. Binding by Copy
      2. Binding by Reference
      3. The Dynamic Call
    3. Compilation
      1. CRTCLMOD
      2. CRTSRVPGM
      3. CRTPGM
      4. CRTBNDCL
    4. Activation Groups
      1. The Default Activation Group
      2. ACTGRP(IDENTIFIER)
      3. ACTGRP(*NEW)
      4. ACTGRP(*CALLER)
      5. Destroying Activation Groups
    5. Parameter Descriptions
      1. PGM: Program Name
      2. SRCFILE: Source File Name
      3. SRCMBR: Source Member Name
      4. TEXT: Text Description
      5. DFTACTGRP: Default Activation Group
      6. OPTION: Compiler Listing Options
      7. USRPRF: Assumed User Profile
      8. LOG: Log Commands
      9. REPLACE: Replace Existing Program
      10. TGTRLS: Target Release
      11. AUT: Public Authority
      12. SRTSEQ: Sort Sequence
      13. LANGID: Language ID
      14. DBGVIEW: Debugging View
      15. ENBPFRCOL: Enable Performance Collection
      16. ACTGRP: Activation Group Name
      17. OPTIMIZE: Optimization
  20. A. Some Utility Commands
    1. Messages
      1. Forward Program Messages (FWDPGMMSG)
        1. Parameters
      2. Send Status Message (SNDSTSMSG)
        1. Parameters
      3. Display Program Messages (DSPPGMMSG)
        1. Parameters
    2. Programming Aids
      1. Start PDM (PDM)
        1. Parameters
      2. Initialize Library (INZLIB)
        1. Parameters
      3. Format CL Source (FMTCLSRC)
        1. Parameters
      4. Compare Source Members (CMPSRCMBR)
        1. Parameters
    3. Programming Shortcuts
      1. Create Work File (CRTWRKF)
        1. Parameters
      2. Duplicate Object (DUPOBJ)
        1. Parameters
      3. Save and Restore Library List (SAVLIBL, RSTLIBL)
        1. Parameters
    4. Data Queues
      1. Send to Data Queue (SNDDTAQ)
        1. Parameters
      2. Receive from Data Queue (RCVDTAQ)
        1. Parameters
      3. Clear Data Queue (CLRDTAQ)
        1. Parameters
      4. Retrieve Data Queue Description (RTVDTAQD)
        1. Parameters
      5. Reorganize Data Queue (RGZDTAQ)
        1. Parameters
    5. Other Commands
      1. Comment (COMMENT)
        1. Parameters
      2. Display Object Information (DSPOBJINF)
        1. Parameters
      3. Count Objects (CNTOBJ)
        1. Parameters
      4. Convert Print to Physical File (CVTPRTPF)
  21. B. CL Coding Style
    1. Starting Point: SEU + Command Prompter
    2. Add Comments
    3. Add Blank Lines
    4. Put Labels in Separate Lines
    5. Remove Leading Blanks
    6. Indent the Code
    7. Turn Identifiers to Lowercase
    8. Remove Unnecessary Keywords
    9. Align Similar Lines (DCLs in Particular)
      1. Choose the Right Code Editor
  22. C. Sample Sign-On Program
  23. D. Debugging OPM Programs
    1. The Strdbg Command
    2. The Line-Oriented Debugger
      1. The ADDBKP Command
      2. Changing and Removing Breakpoints
      3. Displaying and Changing Variables
      4. Conditional Breakpoints
      5. The ADDTRC, DSPTRC, and RMVTRC Commands
      6. The DSPTRCDTA and CLRTRCDTA Commands
  24. E. The Original Program Model
  25. F. Differences in S/38 CL
    1. Objects
      1. Object Type
      2. Qualified Names
    2. Changes in Commands
      1. New Commands
    3. System Values
      1. New System Values
      2. Changed System Values
      3. Obsolete System Values
    4. The S/38 Environment
      1. Description
      2. Converting to eServer i5 or iSeries
      3. No ILE
  26. G. For S/36 Programmers
    1. Interpreted versus Compiled Languages
    2. The S/36 Environment
      1. Entering and Leaving the S/36E
      2. Running S/36E Procedures
    3. CL Equivalents to S/36 OCL
      1. Substitution Expressions
      2. Procedure Control Expressions
      3. OCL Statements
      4. Most-Used OCL Procedures
      5. Control Commands
    4. Forgetting S/36 Techniques
      1. Control Record in a File
      2. Creating and Deleting Work Files
      3. Using the LDA to Pass Data
      4. Executing Dynamically Built Statements
      5. Using // FILE Label-xxx
      6. Abusing // PRINTER
      7. Indirect Reference Using ??N??
      8. Using #GSORT