wrox rexx programmers reference

Download Wrox Rexx Programmers Reference

If you can't read please download the document

Upload: vohanh

Post on 08-Dec-2016

309 views

Category:

Documents


14 download

TRANSCRIPT

Wrox.Rexx.Programmers.Reference.Feb.2005.eBook-DDU.pdf

Rexx Programmers Reference

Howard Fosdick

01_579967 ffirs.qxd 2/3/05 9:00 PM Page i

01_579967 ffirs.qxd 2/3/05 9:00 PM Page iv

Rexx Programmers Reference

Howard Fosdick

01_579967 ffirs.qxd 2/3/05 9:00 PM Page i

Rexx Programmers ReferencePublished byWiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256www.wiley.com

Copyright 2005 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 0-7645-7996-7

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

1MA/ST/QS/QV/IN

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any formor by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except aspermitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the priorwritten permission of the Publisher, or authorization through payment of the appropriate per-copy feeto the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978)646-8600. Requests to the Publisher for permission should be addressed to the Legal Department,Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317)572-4355, e-mail: [email protected].

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHORMAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COM-PLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WAR-RANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULARPURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONALMATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOREVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHERIS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SER-VICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PRO-FESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHORSHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATIONOR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCEOF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHERENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOM-MENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNETWEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHENTHIS WORK WAS WRITTEN AND WHEN IT IS READ.

For general information on our other products and services or to obtain technical support, please con-tact our Customer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317)572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in printmay not be available in electronic books.

Trademarks: Wiley, the Wiley Publishing logo, and related trade dress are trademarks or registeredtrademarks of John Wiley & Sons, Inc., and/or its affiliates, in the United States and other countries,and may not be used without written permission. All other trademarks are the property of theirrespective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

01_579967 ffirs.qxd 2/3/05 9:00 PM Page ii

About the Author

Howard FosdickHoward Fosdick has performed DBA and systems support work as an independent consultant for 15years. Hes coded in Rexx for nearly two decades and has worked in most other major scripting lan-guages. Fosdick has written many technical articles, founded two database users groups, and is knownas the originator of such concepts as hype cycles and open consulting.

01_579967 ffirs.qxd 2/3/05 9:00 PM Page iii

01_579967 ffirs.qxd 2/3/05 9:00 PM Page iv

CreditsSenior Acquisitions EditorDebra Williams Cauley

Development EditorEileen Bien Calabro

Production EditorFelicia Robinson

Technical ReviewerMark Hessling

Copy EditorPublication Services

Editorial ManagerMary Beth Wakefield

Vice President & Executive Group PublisherRichard Swadley

Vice President and PublisherJoseph B. Wikert

Project CoordinatorErin Smith

Graphics and Production SpecialistsJonelle BurnsCarrie FosterLauren GoddardDenny HagerJoyce HaugheyJennifer Heleine

Quality Control TechniciansJohn GreenoughLeeann HarneyJessica KramerCarl William Pierce

Proofreading and IndexingTECHBOOKS Production Services

01_579967 ffirs.qxd 2/3/05 9:00 PM Page v

01_579967 ffirs.qxd 2/3/05 9:00 PM Page vi

To Kate, my parents, and Phoebe Jane.

01_579967 ffirs.qxd 2/3/05 9:00 PM Page vii

01_579967 ffirs.qxd 2/3/05 9:00 PM Page viii

Foreword

Rexx is a very underrated programming language; elegant in design, simple syntax, easy to learn, useand maintain, yet as powerful as any other scripting language available today.

In 1979, Mike Cowlishaw, IBM fellow, designed a human-centric programming language, Rexx.Cowlishaws premise was that the programmer should not have to tell the interpreter what the languagesyntax was in each program they wrote; that was the job of the interpreter. So unlike most other program-ming languages, Rexx does not suffer from superfluous, meaningless punctuation characters throughoutthe code.

Since the release of Rexx outside of IBM, Rexx has been ported to virtually all operating systems andwas formally standardised with the publishing of the ANSI Standard for Rexx in 1996. In late 2004, IBMtransferred their implementation of Object REXX to the Rexx Language Association under an OpenSource license. This event signalled a new era in the history of Rexx.

This book provides a comprehensive reference and programming guide to the Rexx programming lan-guage. It shows how to use the most popular implementations of Rexx and Rexx external function pack-ages and is suited to both the programmer learning Rexx for the first time as well as the seasoned Rexxdeveloper requiring a single, comprehensive reference manual.

Rexx has had a major influence on my life for the past 20 years since I wrote my first XEDIT macro inRexx. In the last 10 years I have maintained the Regina Rexx interpreter, ably assisted by Florian Groe-Coosmann, and in my remaining spare time have developed several Rexx external function packages(and my XEDIT-like text editor, THE). However, like many developers of open source products, I havenever quite documented the products as completely as they deserve.

This is the book I would have liked to write if I had had the time. Im glad Howard had the time!

Mark HesslingAuthor of Rexx/SQL, Rexx/gd, Rexx/DW, Rexx/CURL,

Rexx/Curses, Rexx/Wrapper, Rexx/Trans, The Hessling Editor (THE), Maintainer of Regina,

Rexx/Tk, PDCurses, http://www.rexx.org/

01_579967 ffirs.qxd 2/3/05 9:00 PM Page ix

01_579967 ffirs.qxd 2/3/05 9:00 PM Page x

Acknowledgments

Special thanks are due to Mark Hessling, who writes and maintains Regina Rexx and a wide variety ofopen source Rexx tools and interfaces. As the technical reviewer for this book, Mark was an invaluablesource of recommendations for improvement as well as (oops!) corrections. His expertise and helpful-ness were critical to improving this book.

Special gratitude is also due to the inventor of Rexx, Michael Cowlishaw. His advice and feedback werevery much appreciated.

In the process of developing this book, I wrote inquiries to many people without any prior introduction.Each and every one of them responded helpfully. It was a great pleasure to meet people with such aninterest in Rexx, who so kindly answered questions and who greatly improved this book with their suggestions.

I would like to give heartfelt thanks to Mara Teresa Alonso y Albado, W. David Ashley, Gil Barmwater,Dr. Dennis Beckley, Alex Brodsky, Frank Clarke, Steve Coalbran, Ian Collier, Les Cottrell, MichaelCowlishaw, Chip Davis, Prof. Rony Flatscher, Jeff Glatt, Etienne Gloux, Bernard Golden, Bob Hamilton,Henri Henault , Stphane Henault, Mark Hessling, Jack Hicks, IBM Corporation, Ren Vincent Jansen,Jaxo Inc., Kre Johansson, Kilowatt Software, Les Koehler, Laboratorios Bag S.A., Joseph A. Latone,Henri LeFebure, Michael Lueck, Antoni Levato, Dave Martin, Rob McNair, Patrick TJ McPhee, Dr. LauraMurray, Walter u. Christel Pachl, Lee Peedin, Priscilla Polk, the Rexx Language Association, Pierre G.Richard, Peggy Robinson, Morris Rosenbaum, Dr. Elizabeth Rovelli, David Ruggles, Roger E. Sanders,Thomas Schneider, Theresa Stewart, UniForum Chicago, Vasilis Vlachoudis, Stan Wakefield, KeithWatts, Dr. Sandra Wittstein, and Claudio Zomparelli.

Beyond those who provided technical advice and input for this book, I wish to thank my editors at JohnWiley and Sons, Inc. Eileen Bien Calabro greatly improved the readability of this book through her writ-ing recommendations. Debra Williams Cauley provided insightful perspective and guidance on thepreparation and organization of the book. Finally, I thank Richard Swadley. I appreciate his confidenceand hope this book fulfills its promise both in the quality of its material and in its sales and distribution.

Special thank you to the following developers for permission to reprint or refer to their code (most ofthese items fall under various open source licenses):

W. David AshleyIBM Corporation, project leader of the Mod_Rexx project for scripts appearing in thechapter on Apache programming with Mod_Rexx

Les Cottrell and the Stanford Linear Accelerator LaboratoryAuthors of Rexx/CGI library for a scriptillustrating their Rexx/CGI library

Henri Henault & SonsAuthors of the Internet/REXX HHNS WorkBench for a script and screen shotillustrating the Internet/REXX HHNS WorkBench.

01_579967 ffirs.qxd 2/3/05 9:00 PM Page xi

Acknowledgments

Mark HesslingDeveloper/maintainer of Regina Rexx and many open source Rexx tools for materialon Rexx/gd and the reference tables of Rexx/Tk functions

Patrick TJ McPheeDeveloper of RexxXML for the example program appearing in the chapter onRexxXML

Pierre G. Richard, Joseph A. Latone, and Jaxo Inc.Developers of Rexx for Palm OS for example scriptsappearing in the chapter on Rexx for Palm OS

01_579967 ffirs.qxd 2/4/05 12:12 PM Page xii

Contents at a Glance

Foreword ixAcknowledgments xiIntroduction xxix

Part I 1

Chapter 1: Introduction to Scripting and Rexx 3Chapter 2: Language Basics 21Chapter 3: Control Structures 33Chapter 4: Arrays 53Chapter 5: Input and Output 67Chapter 6: String Manipulation 79Chapter 7: Numbers, Calculations, and Conversions 99Chapter 8: Subroutines, Functions, and Modularity 109Chapter 9: Debugging and the Trace Facility 133Chapter 10: Errors and Condition Trapping 143Chapter 11: The External Data Queue, or Stack 159Chapter 12: Rexx with Style 169Chapter 13: Writing Portable Rexx 189Chapter 14: Issuing System Commands 209Chapter 15: Interfacing to Relational Databases 229Chapter 16: Graphical User Interfaces 255Chapter 17: Web Programming with CGI and Apache 273Chapter 18: XML and Other Interfaces 291

Part II 305

Chapter 19: Evolution and Implementations 307Chapter 20: Regina 331Chapter 21: Rexx/imc 345Chapter 22: BRexx 359Chapter 23: Reginald 385Chapter 24: Handhelds and Embedded Programming 421Chapter 25: Rexx for Palm OS 433Chapter 26: r4 and Object-Oriented roo! 447Chapter 27: Open Object Rexx 459Chapter 28: Open Object Rexx Tutorial 475

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xiii

xiv

Contents at a Glance

Chapter 29: IBM Mainframe Rexx 493Chapter 30: NetRexx 515

Part III 529

Appendix A: Resources 531Appendix B: Instructions 535Appendix C: Functions 547Appendix D: Regina Extended Functions 573Appendix E: Mainframe Extended Functions 593Appendix F: Rexx/SQL Functions 597Appendix G: Rexx/Tk Functions 607Appendix H: Tools, Interfaces, and Packages 615Appendix I: Open Object Rexx: Classes and Methods 619Appendix J: Mod_Rexx: Functions and Special Variables 623Appendix K: NetRexx: Quick Reference 629Appendix L: Interpreter System Information 635Appendix M: Answers to Test Your Understanding Questions 637

Index 657

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xiv

Contents

Foreword ixAcknowledgments xi

Introduction xxix

Who This Book Is For xxxWhat This Book Covers xxxiHow This Book Is Structured xxxiWhat You Need to Use This Book xxxiiConventions xxxiiSource Code xxxiiiErrata xxxiiip2p.wrox.com xxxiv

Part I 1

Chapter 1: Introduction to Scripting and Rexx 3

Overview 3Why Scripting? 3Why Rexx? 6Power and Flexibility 7Universality 8Typical Rexx Applications 9What Rexx Doesnt Do 11Which Rexx? 12Downloading Regina Rexx 14Installing Regina under Windows 15Installing Regina under Linux and Unix 17

Installing Regina with Red Hat Package Manager 19Summary 20Test Your Understanding 20

Chapter 2: Language Basics 21

Overview 21A First Program 21

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xv

xvi

Contents

Language Elements 24Operators 27Summary 32Test Your Understanding 32

Chapter 3: Control Structures 33

Overview 33Structured Programming in Rexx 34IF Statements 35DO Statements 37A Sample Program 38SELECT Statements 40CALL Statements 41Another Sample Program 43Unstructured Control Instructions 47Summary 50Test Your Understanding 50

Chapter 4: Arrays 53

Overview 53The Basics 54A Sample Program 57Associative Arrays 60A Sample Associative Array Program 61Creating Data Structures Based on Arrays 63Summary 64Test Your Understanding 65

Chapter 5: Input and Output 67

Overview 67The Conceptual I/O Model 67Line-Oriented Standard I/O 69Character-Oriented Standard I/O 72Conversational I/O 75Redirected I/O 75I/O Issues 76Summary 77Test Your Understanding 77

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xvi

xvii

Contents

Chapter 6: String Manipulation 79

Overview 79Concatenation and Parsing 79A Sample Program 84String Functions 89The Word-Oriented Functions 92The Bit String Functions and Conversions 96Summary 98Test Your Understanding 98

Chapter 7: Numbers, Calculations, and Conversions 99

Overview 99The Basics 100More Numeric Functions 103Conversions 105A Sample Program 106Summary 107Test Your Understanding 108

Chapter 8: Subroutines, Functions, and Modularity 109

Overview 109The Building Blocks 110Internal Functions and Subroutines 111Passing Parameters into a Script from the Command Line 115Passing Parameters into Subroutines and Functions 116A Sample Program 118The Function Search Order 120Recursion 121More on Scoping 123Another Sample Program 128Summary 130Test Your Understanding 131

Chapter 9: Debugging and the Trace Facility 133

Overview 133The say Instruction 133The trace Instruction 135Reading Trace Output 138The trace Function 139

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xvii

xviii

Contents

Interactive Tracing 140Summary 142Test Your Understanding 142

Chapter 10: Errors and Condition Trapping 143

Overview 143Error Trapping 143How to Trap Errors 144A Sample Program 146An Improved Program 148Special Variables 151signal versus call 152The condition Function 154A Generic Error-Trap Routine 155Limitations 156Summary 157Test Your Understanding 157

Chapter 11: The External Data Queue, or Stack 159

Overview 159What Is the Stack? 160An Example Placing Data into the Stack and Retrieving It 162Another Example The Stack for Interroutine Communication 165Practical Use of the Stack 166Summary 168Test Your Understanding 168

Chapter 12: Rexx with Style 169

Overview 169Capitalize on Capitalization 170Good Variable Naming 171Use Spacing and Indentation 172Limit Nesting 174Comment Code 175Write Modular Code 177Write Structured Code 178Handle Errors 179Additional Suggestions 181

Subscripts 181Quotation marks for commands 181Consider declaring all variables 182

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xviii

xix

Contents

Rexx-aware editors 183Publish site standards for coding style 183Consider automated tools to ensure standards compliance 183Consider code reviews 183

Avoid Common Coding Errors 184Failing to end a comment 184Failing to end a literal string or parenthetical expression 184Improper coding of functions 184Forgetting that functions return a string 184Using parentheses on call 185Failure to use commas on call or in parse arg 185Confusing command-line arguments with internal routine arguments 185Global variables 185Forgetting return or exit 186Forgetting about automatic uppercase conversion 186Incorrectly continuing a statement 186Failing to use strict comparisons 187Incorrectly coding strict comparisons for numbers 187

Summary 187Test Your Understanding 187

Chapter 13: Writing Portable Rexx 189

Overview 189Factors Affecting Portability 190Rexx Standards 192How a Script Learns about Its Environment 195A Sample Program 200Techniques for Command Portability 201Issues in Code Portability 202I/O and Code Portability 205Interfaces for Portability RexxUtil 206Summary 207Test Your Understanding 207

Chapter 14: Issuing System Commands 209

Overview 209Issuing Operating System Commands 211Feedback from OS Commands 213Controlling Command I/O 216A Few Examples 218Discovering Defaults the address Function 220Issuing Commands to Other Environments 220

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xix

xx

Contents

A Sample Program 222Using the Stack for Command I/O 225Summary 227Test Your Understanding 227

Chapter 15: Interfacing to Relational Databases 229

Overview 229Rexx/SQL Features 230Downloading and Installing Rexx/SQL 231The Basics 232Example Displaying Database Information 234Example Create and Load a Table 239Example Select All Results from a Table 241Example Select and Update Table Rows 243Example Cursor Processing 245Bind Variables 247Working with Other Databases 248

Connecting to Oracle 248Connecting to DB2 UDB 248Connecting using ODBC 249Connecting to MySQL 249Oher database differences 249

Other Database Interfaces 250Summary 253Test Your Understanding 253

Chapter 16: Graphical User Interfaces 255

Overview 255Rexx/Tk 256Rexx/DW 256Rexx Dialog 257OODialog and the Object REXX GTK+ Project 257Dr. Dialog, VX*Rexx, VisPro Rexx 257

Rexx/Tk 258Downloading and installing 258Basic script design 259A simple example 260Your next steps 264

Rexx/DW 264Components 264Downloading and Installing Rexx/DW 265

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xx

xxi

Contents

Basic script design 265Your next steps 266

Graphical Images with Rexx/gd 266The logic of a Rexx/gd routine 267A sample program 268

Summary 272Test Your Understanding 272

Chapter 17: Web Programming with CGI and Apache 273

Overview 273Common Gateway Interface 273

The cgi-lib.rxx library 274The Internet/REXX HHNS WorkBench 276

Programming Apache with Mod_Rexx 281Functions and special variables 282Installation 282A sample script 283Example Rexx Server Pages 287Further Information 288

Summary 288Test Your Understanding 289

Chapter 18: XML and Other Interfaces 291

Overview 291XML with RexxXML 291

Licensing, downloading, and installation 295Common operations 295A sample script 299

Other Rexx Tools, Interfaces and Extensions 302Summary 303Test Your Understanding 303

Part II 305

Chapter 19: Evolution and Implementations 307

Overview 307The Evolution of Rexx 308Free Rexx Implementations 311Which Rexx? 313

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xxi

xxii

Contents

Rexx Intepreters 315Regina 317Rexx/imc 318BRexx 318Reginald 318Rexx for Palm OS 318r4 319

Object-Oriented Rexx 319roo! 319Open Object Rexx 319

NetRexx 320Mainframe Rexx 320Other IBM Rexxes 321Rexx for Handhelds and Embedded Programming 321Commercial Rexxes 322

uni-Rexx by The Workstation Group 323Personal Rexx by Quercus Systems 323S/Rexx by Treehouse Software Inc. 323Amiga Rexx 323

Rexx Compilers and Tokenizers 323Running Rexx in the Shell 324Rexx As an API 324Rexx As a Macro Language 324Multiple Rexx Interpreters on One Computer 325The Future of Rexx 327Summary 327Test Your Understanding 328

Chapter 20: Regina 331

Overview 331Advantages 332Reginas Extras 333

Interpreter options 334Functions 335Access to function libraries 339

Reginas SAA API 343Sample Scripts 343Summary 343Test Your Understanding 344

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xxii

xxiii

Contents

Chapter 21: Rexx/imc 345

Overview 345Advantages 345Installing Rexx/imc 346Features 348The C-language I/O Model 351Interfaces and Tools 351A Sample Program Environmental Information 352A Sample Program I/O 354Summary 356Test Your Understanding 357

Chapter 22: BRexx 359

Overview 359Advantages 360Downloading and Installation 360

Windows installation 361Windows or DOS installation 362Linux installation 362Unix installation 362Windows CE installation 363

Extra Built-in Functions 363Input/Output 364The External Function Libraries 366Windows CE 367Issuing Operating System Commands 368Example C-like I/O 369Example ANSI Screen I/O with Random Data Access 371Example Direct Data Access 376Example DOS Functions 378Summary 383Test Your Understanding 383

Chapter 23: Reginald 385

Overview 385Advantages 385Download and Installation 386Tools 386Windows GUI 388GUI Development Aids 390Input/output 390

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xxiii

xxiv

Contents

Documentation and Tutorials 392Other Features and Functions 393

Operating system commands 393Options 394Windows Registry 395GUI trace panel 395Error conditions 395Windows DLLs 395Sorting 396Multiple stacks 396Parameter passing 396do over loop 396Array indexing 397Improved interpret instruction 398Other functions 398

Leveraging Reginald 399Sample Scripts File, Directory, and Drive Management 400

Example display file information 402Sample Scripts GUIs 404

Another GUI Example 409Let My Computer Speak! 412

MIDI Rexx 414Accessing the Windows Registry 416Summary 418Test Your Understanding 419

Chapter 24: Handhelds and Embedded Programming 421

Overview 421Programming Handhelds 422Running Native Symbian/EPOC32 426DOS Emulation 426

PocketDOS 427XTM 428

Embedded Device Programming 429Summary 430Test Your Understanding 431

Chapter 25: Rexx for Palm OS 433

Overview 433Advantages 434Downloading and Installation 434

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xxiv

xxv

Contents

A Tutorial 435Summary 444Test Your Understanding 445

Chapter 26: r4 and Object-Oriented roo! 447

Overview 447Advantages 447Downloading and Installation 448

Preinstall 448Verification 449Documentation 449

Tools 450Object-Oriented Programming with roo! 452Summary 456Test Your Understanding 457

Chapter 27: Open Object Rexx 459

Overview 459Background 460Features 460Open Object Rexx for Linux 462

Installation using Red Hat Package Manager 463Installation without Red Hat Package Manager 463Postinstall steps 464

The Basics 464The Class Libraries 468Other Object Rexx Additions 469

New operators 469Directives 470Built-in objects 470Special variables 471New instructions 471New functions 472New condition traps 472New utility functions 472Rexx API 472

Open Object Rexx for Windows 472Summary 473Test Your Understanding 474

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xxv

xxvi

Contents

Chapter 28: Open Object Rexx Tutorial 475

Overview 475A First Program 476Squaring a Number Using Our Own Class and Method 477Another Simple OO Program 479Implementing a Stack through Objects 481A Video Circulation Application 485Concurrency 489Summary 491Test Your Understanding 492

Chapter 29: IBM Mainframe Rexx 493

Overview 493VM Rexx Differences 494

First line 494Online help facility 495File types 496Not symbol 496OS commands 496Instructions 496Functions 497Function packages and external functions 498CMS immediate commands 498Compiler 498Useful CMS commands 499

OS/TSO Rexx Differences 500Additional instructions and functions 501TSO/E external functions 501TSO/E Rexx commands 501TSO/E programming services 503

Mainframe Rexx and the Language Standards 503Interfaces 504

Sample Scripts 506Migrating Mainframe Scripts to Other Platforms 512Applying Your Rexx Skills to Other Platforms 513Further Information 513Summary 513Test Your Understanding 514

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xxvi

xxvii

Contents

Chapter 30: NetRexx 515

Overview 515Why NetRexx? 515Do You Have to Know Java to Use NetRexx? 516Downloading and Installation 517Ways to Run NetRexx Programs 518Features 519Sample Programs 523

A simple sample applet 525Summary 526Test Your Understanding 527

Part III 529Appendix A: Resources 531

Appendix B: Instructions 535

Appendix C: Functions 547

Appendix D: Regina Extended Functions 573

Appendix E: Mainframe Extended Functions 593

Appendix F: Rexx/SQL Functions 597

Appendix G: Rexx/Tk Functions 607

Appendix H: Tools, Interfaces, and Packages 615

Appendix I: Open Object Rexx: Classes and Methods 619

Appendix J: Mod_Rexx: Functions and Special Variables 623

Appendix K: NetRexx: Quick Reference 629

Appendix L: Interpreter System Information 635

Appendix M: Answers to Test Your Understanding Questions 637

Index 657

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xxvii

02_579967 ftoc.qxd 2/3/05 9:01 PM Page xxviii

Introduction

Of all the free scripting languages, why should you learn Rexx? Rexx is unique in that it combines powerwith ease of use. Long the dominant scripting language on mainframes, it is definitely a power language,yet it is also so easy to use that its popularity has expanded to every conceivable platform. Today the vastmajority of Rexx developers use the language on Windows, Linux, Unix, and dozens of other systems . . .and, there are nine free and open source Rexx interpreters available.

Heres the Rexx story in a nutshell:

Rexx runs on every platform under nearly every operating system.

So, your skills apply anywhere . . . and your code runs everywhere.

Rexx enjoys a strong international standard that applies to every Rexx interpreter . . .

from handhelds to PCs to servers to mainframes.

Rexx is as easy as BASIC, yet about as powerful as Perl.

Rexxs large user community means:

Many free interpreters optimized for different needs and environments

A vast array of free interfaces and tools

Good support

Rexx comes in object-oriented versions as well as a version that is Java-compatible (and even generates Java code!)

You may be wondering why ease of use is so important in a programming languageespecially if youare a high-end developer. First, understand that a truly easy language is easy to use, learn, remember,maintain, and code. The benefits to beginners are obvious. With Rexx, you can start coding almostimmediately. There are no syntax tricks or language details to memorize before you begin. And, sinceRexx is also a powerful language, you can rest assured that you wont run out of power as you learn andgrow in the language. Read the first few chapters in this book, and youll be scripting right away.Continue reading, and youll mature into advanced scripting before you finish.

If you are a highly experienced developer, Rexx offers more subtle benefits. You will be wildly productive,of course, as you free yourself from the shackles of syntax-driven code. More important is this: Simplicityyields reliability. Your error rate will decline, and youll develop more reliable programs. This benefit isgreatest for the largest systems and the most complicated scripts. Your scripts will also live longer becauseothers will be able to understand, maintain, and enhance them. Your clever scriptlets and application mas-terpieces wont die of neglect if you leave the company and continue your career elsewhere.

Few easy languages are also powerful. Now, how does Rexx do that?

03_579967 flast.qxd 2/11/05 2:49 PM Page xxix

xxx

Introduction

Rexx surrounds its small instruction with an extensive function library. Scripts leverage operating sys-tem commands, external interfaces, programs, and functions. Rexx is a glue language that ties it alltogether. Yet the language has few rules. Syntax is simple, minimal, flexible. Rexx doesnt care aboutuppercase or lowercase or formatting or spacing. Rexx scripts dont use special symbols and contain nopunctuation.

If youve worked in the shell languages, youll breathe a sigh of relief that youve found a powerful lan-guage in which you can program now and then without trying to recall arcane language rules. If youvestruggled with the syntax of languages such as Bash, Korn, Awk, or the C-shell, youll enjoy focusing onyour programming problem instead of linguistic peculiarities. And if youve ever had to maintain some-one elses Perl code, well . . . you might really be thankful for Rexx!

This book contains everything you need to know to get started with Rexx. How to freely download andinstall the product. How to program in standard Rexx and object-oriented Rexx. How to program hand-helds. How to program Windows, Linux, Unix, and mainframes. How to program in the Java environ-ment in a Rexx-based language called NetRexx. How to script operating system commands, control Webservers and databases and graphical user interfaces (GUIs) and Extensible Markup Language (XML) andApache and . . . you name it.

Everything you need is in this one bookits virtually a Rexx encyclopedia. It teaches standard Rexxso that your skills apply to any platformfrom handhelds to PCs and laptops to midrange servers run-ning any operating system to mainframes. Yet it goes beyond the basics to cover interface programmingand advanced techniques. The book starts out easy, and is based on coding examples throughout to makelearning fast, simple, and fun. But its comprehensive enough to go the distance and cover advancedscripting as well. And, you can freely download all the Rexx interpreters, tools, and interfaces it covers.Welcome to the world of free Rexx !

Who This Book Is ForThis book is for anyone who wants to learn Rexx, or who already works with Rexx and wants to expandhis or her knowledge of the language, its versions, interfaces, and tools. How you use this book dependson your previous programming or scripting knowledge and experience:

If you are a complete beginner who has heard about Rexx and have come this far, youve cometo the right place. Rexx is easily learned, and this book tells you everything you need to know.Its a progressive tutorial that wont let you get lost. And if you stick with it, youll be able tohandle almost any programming problem by the end of the book.

If you are an experienced programmer in some other scripting or programming language, thenyou too have come to the right place. You can learn Rexx very quickly simply by reading theearly chapters in this book. Youll be able to program in Rexx immediately. As the book pro-gresses into tutorials on interfaces to databases, Web servers, GUIs, and the like, youll learnhow to program Rexx in the context of the larger environment to meet your programming needs.

Power does not require coding complexity!

03_579967 flast.qxd 2/11/05 2:49 PM Page xxx

xxxi

Introduction

If you are a systems administrator or support person, youll be able to grow your knowledge ofa language that applies to a very wide variety of situations and can be a great tool. This bookcovers the interfaces, tools, and varieties and implementations of Rexx youll need to know about.It doesnt stop with the basics, but plows right on ahead into the advanced features youll wantto learn and use.

If you already use Rexx, you will be able to expand your knowledge through this book. You can learn about free Rexx interfaces and tools with which you may not be familiar. Youll learnabout Rexx programming in new environments, such as scripting handhelds, object-orientedRexx, and scripting in the Java environment with NetRexx. Youll also find the complete refer-ence in the appendices a useful source of consolidated information. This is the only Rexx refer-ence youll need on your desk.

What This Book CoversThis book teaches standard Rexx, quickly and simply. It teaches you what you need to know to workwith Rexx on any platform. Youll know a language that runs anywherefrom handheld devices such aspersonal digital assistants, pocket PCs, Palm Pilots, and mobile and smart phones to desktop and laptopPCs, with operating systems like Windows, Linux, and others, to midrange servers from all the majorvendorsright on up to the worlds largest mainframes. Rexx applies to almost any programming problem.

Beyond the Rexx language proper, this book covers all the major interfaces into Web servers, databases,GUIs, XML, and the like. It describes many of the free tools that are available to make scripting withRexx easier and more productive.

The book covers nine free Rexx interpreters. Eight of them meet the international standards for Rexx, yeteach adds its own special features and extensions. The book tells where to download each interpreter,shows how to install it, and demonstrates how to make the most of its advantages and extensions.

All the Rexx interpreters, tools, and interfaces this book covers are free or open source. The one excep-tion is IBM mainframe Rexx, which comes bundled with IBMs operating systems.

In the end, this book covers not only Rexx scripting, but also the whole world of Rexx programmingacross all environments and interfaces, and with all Rexx interpreters. It is truly a Rexx encyclopedia.

How This Book Is StructuredTake a quick look at the table of contents, and you will see that this book is broken down into threebroad sections:

The book begins with a progressive tutorial and examples that cover all the basic aspects of theRexx language. These eventually lead into more advanced scripting topics, such as how to writeportable code and using optimal coding style. The last chapters of this section (Chapters 15through 18) cover the most common Rexx interfaces and tools. These introduce and demon-strate how to code Rexx in interfacing to operating systems, SQL databases, Web servers, GUIs,XML, and other tools.

03_579967 flast.qxd 2/11/05 2:49 PM Page xxxi

xxxii

Introduction

The chapters of the second section of the book describe the different Rexx interpreters and theunique advantages of each. These chapters apply Rexx to different environments, such as hand-helds, mainframes, and various other platforms. They include tutorials on object-oriented Rexx,handheld scripting, and how to program in the Java environment with NetRexx.

Finally, the book has a detailed and comprehensive reference section in the form of a series ofappendices. This reference section is a complete stand-alone reference. You wont need anyother tome on your desk to write Rexx scripts.

How you decide to progress through the book really depends on your current skill level with regard to Rexx and scripting and what you want to do. You can use this book as a tutorial by working with itstraight through, or you can dive into particular chapters and topics that interest you. Or, just use theappendices as your complete Rexx reference. Any approach is fineuse the book in the way that is bestfor you.

What You Need to Use This BookYou need nothing besides this book to get started. While this book is an encyclopedia of Rexx, itsexamples were all run using freely downloadable Rexx interpreters, tools, and interfaces. The chaptersall tell you where to download any interpreters, tools, and interfaces the book demonstrates, as well ashow to set up and install them.The examples in this book were run and tested under Windows and/orLinux, but you can work with this book with Rexx running any operating system you like.

ConventionsTo help you get the most from the text and keep track of whats happening, weve used a number of con-ventions throughout the book.

Concerning styles in the text:

We italicize important words when we introduce them.

We show keyboard strokes like this: Ctrl-A.

We show filenames, URLs, variable names, and code within the text like this: my_file.txt.

We present code in two different ways:

In code examples we highlight new and important code with a gray background.

The gray highlighting is not used for code thats less important in the presentcontext, or that has been shown before.

Boxes like this one hold important, not-to-be-forgotten information that is directlyrelevant to the surrounding text.

03_579967 flast.qxd 2/11/05 2:49 PM Page xxxii

xxxiii

Introduction

The Rexx language is not case-sensitive, so its instructions and functions can be encoded in uppercase,lowercase, or mixed case. For example, the wordlength function can be encoded as wordlength,WordLength, or WORDLENGTH. This book uses capitalization typical to the platforms for which its samplescripts were written, but you can use any case you prefer.

Due to the typesetting software used in preparing this book, single quotation marks may appear as vertical,forward-leaning, or backward-leaning. All are simply single quotation marks to Rexx. For example, thesetwo coding examples are exactly equivalent, even though the quote marks slant in different directions:

say `Hello`

say Hello

Source CodeAs you work through the examples in this book, you may choose either to type in code manually or touse the source code files that accompany the book. The source code in this book is available for freedownload at www.wrox.com. Once at the site, simply locate the books title (either by using the Searchbox or by using one of the title lists) and click the Download Code link on the books detail page toobtain the source code for the book.

Once you have downloaded the code, just decompress it with your favorite compression tool.Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

ErrataWe make every effort to ensure that there are no errors in the text or in the code. However, no one is per-fect, and mistakes do occur. If you find an error in one of our books, such as a spelling mistake or faultypiece of code, we would be very grateful for your feedback. By sending in errata, you may save anotherreader hours of frustration and at the same time you will be helping us provide even higher-qualityinformation.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or oneof the title lists. Then, on the book details page, click the Book Errata link. On this page, you can view allerrata that has been submitted for this book and posted by Wrox editors. A complete book list, includinglinks to each books errata, is also available at www.wrox.com/misc-pages/booklist.shtml.

If you dont spot your error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. Well check the informationand, if appropriate, post a message to the books errata page and fix the problem in subsequent editionsof the book.

Because many books have similar titles, you may find it easier to search by ISBN;for this book the ISBN is 0764579967.

03_579967 flast.qxd 2/11/05 2:49 PM Page xxxiii

xxxiv

Introduction

p2p.wrox.comFor author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with otherreaders and technology users. The forums offer a subscription feature to email you on topics of yourchoosing when new posts are made to the forums. Wrox authors, editors, other industry experts, andyour fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only asyou read this book, but also as you develop your own applications. To join the forums, just follow thesesteps.

1. Go to p2p.wrox.com and click the Register link.2. Read the terms of use and click Agree.3. Complete the required information to join as well as any optional information you wish to pro-

vide and click Submit.

You will receive an email with information describing how to verify your account and complete the join-ing process.

Once you join, you can post new messages and respond to messages other users post. You can read mes-sages at any time on the Web. If you would like to have new messages from a particular forum emailedto you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, read the P2P FAQs for answers to questions abouthow the forum software works as well as many common questions specific to P2P and Wrox books. Toread the FAQs, click the FAQ link on any P2P page.

You can read messages in the forums without joining P2P; but in order to post yourown messages, you must join.

03_579967 flast.qxd 2/11/05 2:49 PM Page xxxiv

Part I

04_579967 pt01.qxd 2/3/05 9:01 PM Page 1

04_579967 pt01.qxd 2/3/05 9:01 PM Page 2

Introduction to Scriptingand Rexx

OverviewBefore learning the Rexx language, you need to consider the larger picture. What are scripting lan-guages? When and why are they used? What are Rexxs unique strengths as a scripting language,and what kinds of programming problems does it address? Are there any situations where Rexxwould not be the best language choice?

This chapter places Rexx within the larger context of programming technologies. The goal is togive you the background you need to understand how you can use Rexx to solve the program-ming problems you face.

Following this background, the chapter shows you how to download and install the most popularfree Rexx interpreter on your Windows, Linux, or Unix computer. Called Regina, this open-sourceinterpreter provides a basis for your experiments with Rexx as you progress in the language tuto-rial of subsequent chapters. Note that you can use any standard Rexx interpreter to learn Rexx. So,if you have some other Rexx interpreter available, you are welcome to use it. We show how todownload and install Regina for readers who do not already have a Rexx interpreter installed, orfor those who would like to install an open-source Rexx on their PC.

Why Scripting?Rexx is a scripting language. Whats that? While most developers would claim to know one whenthey see it, a precise definition is elusive. Scripting is not a crisply defined discipline but rather adirectional trend in software development. Scripting languages tend to be:

High level Each line of code in a script produces more executable instructions it doesmore than an equivalent line encoded in a lower-level or traditional language.

05_579967 ch01.qxd 2/3/05 9:02 PM Page 3

Glue languages Scripting languages stitch different components together operating systemcommands, graphical user interface (GUI) widgets, objects, functions, or service routines. Somecall scripting languages glue languages. They leverage existing code for higher productivity.

Interpreted Scripting languages do not translate or compile source code into the computersmachine code prior to execution. No compile step means quicker program development.

Interactive debugging Interpreted languages integrate interactive debugging. This gives devel-opers quick feedback about errors and makes them more productive.

Variable management Higher-level scripting languages automatically manage variables. Rexxprogrammers do not have to define or declare variables prior to use, nor do they need toassign maximum lengths for character strings or worry about the maximum number of ele-ments tables will hold. The scripting language handles all these programming details.

Typeless variables Powerful scripting languages like Rexx even relieve the programmer of theburden of declaring data types, defining the kind of data that variables contain. Rexx under-stands data by usage. It automatically converts data as necessary to perform arithmetic opera-tions or comparisons. Much of the housekeeping work programmers perform in traditionalprogramming languages is automated. This shifts the burden of programming from the devel-oper to the machine.

Figure 1-1 contrasts scripting languages and more traditional programming languages.

Figure 1-1

On the downside, scripting requires greater machine resources than hand-coded programs in traditional,compiled languages. But in an era where machine resources are less expensive than ever and continue todecline in price, trading off expensive developer time for cheaper hardware makes sense.

Examples Rexx, Perl, Python, Tcl/Tk, others

High level Interpretive More productive Varying degrees of automatic variable management Shifts burden to the machine Glue languages Acceptable execution speed

Lower level Compiled More detail-oriented Manual variable management Pre-declared variables More programmer effort Coding languages Optimize execution speed

Scripting Versus Traditional Languages

Scripting Traditional

Examples C, C++, COBOL, Java, Pascal, others

4

Chapter 1

05_579967 ch01.qxd 2/3/05 9:02 PM Page 4

Heres how hardware addresses scripting performance. The original IBM PC ran an 8088 processor at4.77 MHz. It executes less than a hundred clauses or statements of a Rexx script every second. CurrentPentiums execute several million Rexx clauses per second.

Just for fun, this table shows how much faster a standard Rexx benchmark script runs on typical PCs at5-or 6-year intervals. Later in this chapter, well show you how to benchmark your own computeragainst the numbers in this table:

Year Make Processor Speed Memory Operating Rexx Clauses System per Second

1982 IBM PC 8088 4.77 Mhz 320 KB DOS 6.2 Mansfield 70

Zenith 8088-2 8 Mhz 640 KB DOS 6.2 Mansfield 95

1988 Clone 386/DX 25 Mhz 2 MB DOS 6.2 BRexx 3,600

1993 Clone 486/SX 25 Mhz 8 MB Windows 3.1 BRexx 6,000

Clone 486/DX2 66 Mhz 8 MB Windows 3.1 BRexx 8,200

IBM 486/SX2 50 Mhz 20 MB Windows 95 BRexx 11,500

1998 Gate-way Pentium II 266 Mhz 512 MB Red Hat 8 Regina 180,000

Gate-way Pentium II 266 Mhz 512 MB Windows 98SE Regina 225,000

Gate-way Pentium II 266 Mhz 512 MB Windows 98SE BRexx 325,000

2005 Clone Celeron 2.6 Ghz 1 GB Windows XP Regina 1,100,000

Clone Celeron 2.6 Ghz 1 GB Windows XP BRexx 1,800,000

IBM Pentium IV 2.2 Ghz 768 MB Windows 2000 Regina 1,800,000

Clone Pentium IV 3.4 Ghz 1 GB Windows 2003 Regina 2,400,000

Source- authors hands-on tests (yep, even on the old IBM PC model 1!).

The bottom line is that the program that consumes over an hour on the 8088 runs in a second on a mod-ern Pentium. While the table ignores subtle factors that affect performance, the trend is clear. For mostprogramming projects, trading machine cycles for labor costs makes sense. Why not use a more produc-tive tool that shifts the burden to the machine?

Labor-saving benefits extend beyond program development to maintenance and enhancement. Expertslike T. Capers Jones estimate that up to 75 percent of IT labor costs are devoted to program maintenance.An easy-to-read, easy-to-maintain scripting language like Rexx saves a great deal of money.

Hardware performance increases geometrically, while the performance differentialbetween scripting and compiled languages remains constant.

5

Introduction to Scripting and Rexx

05_579967 ch01.qxd 2/3/05 9:02 PM Page 5

Sometimes, youll hear the claim that scripting languages dont support the development of large,robust, production-grade applications. Years ago, scripting languages were primitive and this chargerang true. But no longer. IT organizations routinely develop and run large applications written in Rexxand other scripting languages. For example, the author has scripted two production business applica-tions of over 10,000 lines. You can run an entire enterprise on scripts.

Why Rexx?The distinguishing feature of Rexx is that it combines ease of use with power. Its goal is to make scriptingas easy, fast, reliable, and error-free as possible. Many programming languages are designed for compat-ibility with older languages, the personal tastes of their inventors, the convenience of compiler-writers,or machine optimization. Rexx ignores extraneous objectives. It was designed from day one to be power-ful yet easy to use.

One person invented Rexx and guided its development: Michael Cowlishaw of IBMs UK laboratories.Cowlishaw gave the language the coherent vision and guiding hand that ambitious software projectsrequire to succeed. Anticipating how the Internet community would cooperate years later, he postedRexx on the net of its day, IBMs VNET, a network of tens of thousands of users. Cowlishaw solicitedand responded to thousands of emailed suggestions and recommendations on how people actually usedearly Rexx. The feedback enabled Cowlishaw to adapt Rexx to typical human behavior, making Rexx atruly easy-to-use language.

Ease of use is critical even to experienced developers because it leads to these benefits:

Low error rate An easy-to-use language results in fewer bugs per program. Languages that relyon arcane syntax, special characters and symbols, and default variables cause more errors.

Reliability Programs are more reliable due to the lower error rate.

Longer-lived code Maintenance costs dictate the usable life span of code. Rexx scripts are mucheasier to maintain than scripts written in languages that rely on special characters and complexsyntax.

Reduced cost Fast program development, coupled with a low error rate and high reliability,lead to reduced costs. Ease of maintenance is critical because up to three-quarters of IT profes-sionals engage in maintenance activities. Code written by others is easier to understand andmaintain if it is written in Rexx instead of syntax-driven languages like the shell languages orPerl. This reduces labor costs.

Higher productivity Developer productivity soars when the language is easy to work with.Scripting in Rexx is more productive than coding in either lower-level compiled languages orsyntax-based shell languages.

Quicker testing Interpretive scripting languages lend themselves to interactive testing.Programmers get quick feedback and can easily trace program execution. Combined with thelow error rate of an easy-to-use language, this means that less test time is required.

Easy to learn An easy-to-use language is easier to learn. If you have programmed in any otherprogramming or scripting language, you can pick up Rexx very quickly.

6

Chapter 1

05_579967 ch01.qxd 2/3/05 9:02 PM Page 6

Easy to remember If you write only the occasional program, Rexx is for you. Languages withspecial characters and quirky syntax force you to review their rules if you only script now andthen.

Transfer skills Since Rexx is easy to work with, developers find it easy to adapt to platform dif-ferences or the requirements of different interfaces. Rexx has a strong platform-independentstandard. As well, many Rexx interfaces and tools are themselves cross-platform products.

Power and FlexibilityThat Rexx is easy to learn and use does not mean that it has limited features or is some sort of beginnerslanguage. Rexx competes, feature for feature, with any of the other major scripting languages. If it didnt,it certainly would not be the primary scripting language for mainframes, nor would it have attained thewidespread use it enjoys today on so many other platforms. Nor would there be many hundreds of thou-sands of Rexx users distributed around the world.*

Ease of use and power traditionally force language trade-offs. It is easy to get one without the other, butdifficult to achieve both. Rexx is specifically designed to combine the two. It achieves this goal throughthese principles:

Simple syntax Some very powerful languages rely extensively on special symbols, nonobviousdefault behaviors, default variables, and other programming shortcuts. But there is no rule thatpower can only be achieved in this manner. Rexx eschews complex syntax programming andencourages simpler, more readable programming based on English-language keyword instruc-tions and functions.

Small command set, with functions providing the power Rexx has a small core of only two dozeninstructions. This simplicity is surrounded by the power of some 70 built-in functions. A well-defined, standard interface permits Rexx to call upon external function libraries. This allowsyou to extend the language yourself, and it means that many open-source extensions or librariesof routines are freely available. Rexx scripts also wield the full power of the operating systembecause they easily issue operating system commands.

Free-form language Rexx is not case-sensitive. It is a free-form language and is about as forgivingconcerning placement of its source text as a programming language can be. This permits pro-grammers to self-describe programs by techniques such as indentation, readable comments,case variations, and the like. Rexx relieves programmers from concern about syntax and place-ment, and lets them concentrate on the programming problem they face.

Consistent, reliable behavior Rexx behaves as one would assume at every opportunity. Itsearly user community provided feedback to one master developer who altered the languageto conform to typical human behavior. As the inventor states in his book defining Rexx: Thelanguage user is usually right. Rexx was designed to encourage good programming practiceand then enhanced by user feedback to conform to human expectations.

Modularity and structured programming Rexx encourages and supports modularity and struc-tured programming. Breaking up large programming problems into discrete pieces and restrictingprogram flow to a small set of language constructs contributes greatly to ease of use and a lowerror rate when developing large feature-full applications. These principles yield simplicitywithout compromising power.

7

Introduction to Scripting and Rexx

05_579967 ch01.qxd 2/3/05 9:02 PM Page 7

Fewer rules Put the preceding points together, and youll conclude that Rexx has fewer rulesthan many programming languages. Developers concentrate on their programming problem,not on language trivia.

Standardization While there are at least nine free Rexx interpreters, eight adhere to the Rexxstandards. This makes your scripts portable and your skills transferable. A standardized lan-guage is easier to use than one with numerous variants. Rexx has two strong, nearly identicalstandards. One is defined in the book The Rexx Language, or TRL-2, by Michael Cowlishaw(Prentice-Hall, 1990, second edition). The other is the 1996 standard from the American NationalStandards Institute, commonly referred to as ANSI-1996.

UniversalityRexx is a universal language. It runs on every platform, from handheld devices, to laptops and PCs, toservers of all kinds, all the way up to the largest mainframes. Here are the major platforms on which freeRexx interpreters run:

Operating System Family Operating Systems

Windows Windows 2003/2000, Windows XP, WindowsME/98SE/98/95, Windows CE, Windows 3.1, all others

Linux Red Hat, SuSE, UnitedLinux, Debian, Mandrake, Fedora, allothers

Unix Sun Solaris, IBM AIX, HP HP/UX, IRIX, Sun OS, DigitalUnix, all others

BSD OpenBSD, FreeBSD, NetBSD, others

Mac OS Mac OS X, Mac OS 9, Mac OS 8, others

DOS MS-DOS, PC-DOS, all others including free versions; both32- and 16- bit versions

OS/400 All versions, including i5/OS*

OS/2 OS/2 Warp, eCS (eComStation), osFree*

Mainframes VM, OS, VSE*

VM z/VM, VM/ESA, VM/XA, VM/SP, VM/CMS, CMS, others*

OS z/OS, OS/390, MVS/ESA, MVS/XA, MVS/SP, MVS, TSO,others*

VSE z/VSE, VSE/ESA, VSE/XA, DOS/VSE, DOS/VS, others*

Handhelds Runs natively under Windows CE, Palm OS, and Sym-bian/EPOC32; also runs under DOS emulators (such asPocketDOS, XTM, and all others)

8

Chapter 1

05_579967 ch01.qxd 2/3/05 9:02 PM Page 8

Operating System Family Operating Systems

Windows CE Windows CE .Net, Windows Pocket PC, Windows Mobile,Windows Handheld/PC or H/PC, and Windows for PocketPersonal Computer or Windows P/PC, Pocket PC PhoneEdition, Microsoft Smartphone, others

Symbian OS Symbian OS, EPOC32

Palm OS All versions

*Rexx comes bundled with the operating system.

Free or open-source Rexx also runs on OpenVMS, OpenEdition, BeOS, Amiga OS, AROS, AtheOS/Syllable,QNX (QNX4/QNX6), SkyOS, and others. Object-oriented Rexx interpreters run under Windows, Linux,Solaris, AIX, and OS/2.

The benefits of a universal language are:

Your skills apply to any platform.

Scripts run on any platform.

Heres an example. A site that downsizes its mainframes to Unix machines could install free Rexx on theUnix machines. Rexx becomes the vehicle to transfer personnel skills, while providing a base for migrat-ing scripts.

As another example, an organization migrating from Windows to object-oriented programming (OOP)under Linux could use free Rexx as its cross-platform entry point into OOP. Rexx runs under bothWindows and Linux and standard, procedural Rexx is a subset of object-oriented Rexx.

A final example: a company runs a data center with mainframes and Unix servers, uses Windows on thedesktop, and programs pocket PC handhelds for field agents. Rexx runs on all these platforms, mak-ing developers immediately productive across the whole range of company equipment. Rexx supportsthe platform range that allows a mainframer to program a handheld, or Windows developer to scriptunder Unix.

A standardized scripting language that is freely available across a wide range of systems yields unparal-leled skills applicability and code portability.

Typical Rexx ApplicationsRexx is a general-purpose language. It is designed to handle diverse programming needs. Its powergives it the flexibility to address almost any kind of programming problem. Here are examples.

As a glue language Rexx has long been used as a high-productivity glue language forstitching together existing commands, programs, and components. Rexx offers a higher-levelinterface to underlying system commands and facilities. It leverages services, functions, objects,widgets, programs, and controls.

9

Introduction to Scripting and Rexx

05_579967 ch01.qxd 2/3/05 9:02 PM Page 9

Automating repetitive tasks Rexx scripts automate repetitive tasks. You can quickly put togetherlittle scripts to tailor the environment or make your job easier. Rexx makes it easy to issue com-mands to the operating system (or other environments or programs) and react to their returncodes and outputs.

Systems administration Rexx is a high-level, easy-to-read, and easy-to-maintain way to scriptsystem administration tasks. By its nature, systems administration can be complex. Automatingit with an easily understood language raises system administration to a higher, more abstract,and more manageable level. If you ever have to enhance or maintain systems administrationscripts, youll be thankful if theyre written in Rexx instead of some of the alternatives!

Extending the operating system You typically run Rexx scripts simply by typing their name atthe operating systems command prompt. In writing scripts, you create new operating systemcommands that extend or customize the operating system or programming environment.

Application interfaces Rexx scripts can create flexible user interfaces to applications programmedin lower-level or compiled languages.

Portable applications Rexxs standardization and extensive cross-platform support make it a goodchoice for applications that must be ported across a range of systems. Its readability and ease ofmaintenance make it easy to implement whatever cross-platform enhancements may be desired.For example, while Rexx is the same across platforms, interfaces often vary. Standardizing thescripting language isolates changes to the interfaces.

Prototyping and exploratory programming Since Rexx supports quick development, it is ideal fordeveloping prototypes, whether those prototypes are throw-aways or revisable. Rexx is alsoespecially suitable for exploratory programming or other development projects apt to requiremajor revision.

Personal programming An easy-to-use scripting language offers the simplicity and the speedydevelopment essential to personal programming. PCs and handheld devices often require per-sonal programming.

Text processing Rexx provides outstanding text processing. Its a good choice for text process-ing applications such as dynamically building commands for programmable interfaces, refor-matting reports, text analysis, and the like.

Handheld devices Small devices require compact interpreters that are easy to program. Rexx isquite useful for PDAs, Palm Pilots, Pocket PCs and handheld PCs, and mobile and smartphones.

Migration vehicle Given its cross-platform strengths, Rexx can be used as a migration vehicleto transfer personnel skills and migrate legacy code to new platforms.

Macro programming Rexx provides a single macro language for the tools of the programmingenvironment: editors, text processors, applications, and other languages. Rexxs strengths instring processing play to this requirement, as does the fact it can easily be invoked as a set ofutility functions through its standardized application programming interface, or API.

Embeddable language ANSI Rexx is defined as a library which can be invoked from outsideapplications by its standard API. Rexx is thus a function library that can be employed as anembeddable utility from other languages or systems.

10

Chapter 1

05_579967 ch01.qxd 2/3/05 9:02 PM Page 10

Mathematical applications Rexx performs computations internally in decimal arithmetic, ratherthan in the binary or floating-point arithmetic of most programming languages. The result isthat Rexx always computes the same result regardless of the underlying platform. And, it givesprecision to 999999 decimal places! But Rexx is not suitable for all mathematical applications.Advanced math functions are external add-ins rather than built-in functions for most Rexxinterpreters, and Rexx performs calculations slowly compared to other languages.

What Rexx Doesnt DoThere are a few situations where Rexx may not be the best choice.

Rexx is not a systems programming language. If you need to code on the machine level, for example, towrite a device driver or other operating system component, Rexx is probably not a good choice. Whilethere are versions of Rexx that permit direct memory access and other low-level tasks, languages likeC/C++ or assembler are more suitable. Standard Rexx does not manipulate direct or relative addresses,change specific memory locations, or call PC interrupt vectors or BIOS service routines.

Rexx is a great tool to develop clear, readable code. But it cannot force you to do so; it cannot save youfrom yourself. Chapter 12 discusses Rexx with style and presents simple recommendations for writingclear, reliable code.

Scripting languages consume more processor cycles and memory than traditional compiled languages.This affects a few projects. An example is a heavily used transaction in a high-performance online trans-action processing (OLTP) system. The constant execution of the same transaction might make it worththe labor cost to develop it in a lower-level compiled language to optimize machine efficiency. Anotherexample is a heavily computational program in scientific research. Continual numeric calculation mightmake it worthwhile to optimize processor cycles through a computationally oriented compiler.

Our profession has reached the consensus that for most applications, scripting languages are plenty fastenough. Yet they are also much more productive. This is why scripting is one of the major softwaretrends of the decade.

If youre interested in reading further about the trend towards scripting, these authoritative sourcessummarize it. The last one listed is a formal study that compares productivity and resource usage forRexx, C, C++, Java, Perl, Python, and Tcl:

John Ousterhout, Scripting: Higher Level Programming for the 21st Century, IEEE Computer, March 1998.

David Barron, The World of Scripting Languages, NY: Wiley, 2000.

Lutz Prechelt, An Empirical Comparison of Seven Programming Languages, IEEE Computer (33:10), 2000.

Figure 1-2 summarizes the kinds of programming problems to which Rexx is best suited as well as thosefor which it may not be the best choice.

11

Introduction to Scripting and Rexx

05_579967 ch01.qxd 2/3/05 9:02 PM Page 11

Figure 1-2

Which Rexx?There are at least six free implementations of what we refer to as standard or classic Rexx. This is Rexx asdefined by the TRL-2 standard mentioned earlier. There are also two object-oriented supersets of classicprocedural Rexx. And, there is NetRexx, the free Rexx-like language that runs in a Java Virtual Machineand presents an alternative to Java for developing applets and applications. Which Rexx should you use?

The first half of this book teaches classic Rexx. It applies to any standard Rexx interpreter on any platform.Once you know standard Rexx you can easily pick up the extensions unique to any Rexx interpreter. Youcan also easily learn interface programming, how to use Rexx tools and packages, object-oriented Rexx,NetRexx, or any Rexx variant. After all, the whole point of Rexx is ease of learning!

This table summarizes the free Rexx interpreters.

Rexx Platforms Cost and DistributionInterpreter Licensing

Regina All platforms Free. Open source. GNU Binaries or SourceLibrary General Public License or Lesser General Public License (LGPL)

Rexx/imc Unix, Linux, Free. Copyrighted freeware. Binaries or SourceBSD No warranty, distributed as is.

Highest productivity Quick development Glue language Prototyping Systems administration OS extensions Portable applications Migrations off the mainframe Embedded programming Handheld programming Text processing Interactive development and debugging

Optimal excution speed is required

Systems-level programming

NoYes

When to Use Rexx

12

Chapter 1

05_579967 ch01.qxd 2/3/05 9:02 PM Page 12

Rexx Platforms Cost and DistributionInterpreter Licensing

Brexx Windows, Win CE, Freeware. Free for personal Binaries or SourceDOS (32- and and nonprofit use, fee for 16- bit), Linux, commercial use.Unix, Mac OS, Amiga, others

Reginald Windows Freeware. No warranty, Windows Installer distributed as is. Binaries

r4 Windows Freeware. Limited warranty. Binaries

Rexx for Palm OS Shareware. Free for personal BinariesPalm OS use, fee for commercial use.

Open Object Linux, Windows, Free. Distributed under the Binaries or SourceRexx (formally Solaris, AIX Common Public License. known as Previously developed and Object REXX supported by IBM. Today or IBM Object enhanced and maintained by REXX) the Rexx Language Association.

See Chapter 27 for full information.

roo! Windows Freeware. Limited warranty. Binaries

NetRexx Any platform Free. IBM License Agreement for Binariesrunning a Java IBM Employee-Written Software. Virtual Machine No warranty, distributed as is.(JVM)

All these interpreters meet the TRL-2 Rexx language standard. The single exception is NetRexx, which isbest termed a Rexx-like language. Any standard Rexx you have installed can be used for working withthe sample code in the first half of this book. This includes all the previously listed interpreters (exceptNetRexx), as well as standard Rexx interpreters bundled with mainframe or other operating systems.

To get you up and programming quickly, we defer closer consideration of the unique strengths of thevarious Rexx interpreters and the differences between them. If you need to know more right now, skipahead to Chapter 19. That chapter discusses the evolution of Rexx and the roles it plays as a prominentscripting language. It describes all the free Rexx interpreters listed above and presents the strengths ofeach. Chapters 20 through 30 then show how and where to download and install each Rexx product.They describe the unique features of each interpreter and demonstrate many of them in sample scripts.

If youre new to Rexx, we recommend starting with Regina Rexx. Regina Rexx is a great place to start forseveral reasons:

Popularity Regina is the most widely used free Rexx. Its large user community makes it easyto get help on public forums. More interfaces and tools are tested with Regina than any otherRexx implementation.

13

Introduction to Scripting and Rexx

05_579967 ch01.qxd 2/3/05 9:02 PM Page 13

Runs anywhere Rexx is a platform-independent language, and Regina proves the point. Reginaruns on almost any operating system including those in these families: Windows, Linux, Unix,BSD, 32-bit DOS, Mac OS, and Symbian/EPOC32. It also runs on many important second-tiersystems, including BeOS, OpenVMS, OpenEdition, Amiga OS, AROS, AtheOS/Syllable, QNX(QNX4/QNX6), OS/2, eCS, osFree, and other systems.

Meets all standards Regina meets all Rexx standards including the TRL-2 and ANSI-1996 standards.

Documentation Regina comes with complete documentation that precisely and fully explainsthe product.

Open source Regina is open source and distributed under the GNU Library General PublicLicense. Some Rexx interpreters are free but not open source, as shown in the preceding table.

The code examples in this book all conform to standard Rexx and were tested using Regina Rexx underWindows and /or Linux. Run these scripts under any standard Rexx in any environment. A few scriptsrequire a specific operating system. For example, those in Chapter 14 illustrate how to issue operatingsystem commands and therefore are system-specific. Other scripts later in the book use specific open-source interfaces, tools, or interpreters. Where we present examples that run only in certain environments,well point it out.

To get you ready for the rest of the book, the remainder of this chapter shows you how to download andinstall Regina under Windows, Linux, and Unix. You need only install Regina if you dont already haveaccess to a Rexx interpreter.

Downloading Regina RexxRegina Rexx can be freely downloaded from the SourceForge Web site at http://sourceforge.net.SourceForge is the hugely popular download site for free and open-source products. Find the Reginainterpreter at http://regina-rexx.sourceforge.net. Of course, Web addresses sometimes change.In this case, just enter the keywords Regina Rexx into any Internet search engine such as Google orYahoo! and the current download Web site will pop up.

Download sites list various files or downloads for different platforms. Regina is available for many operat-ing systems in either executable or source forms. Download file types include the self-extracting executable.exe for 32-bit Windows platforms, .zip files, .rpm files for the Red Hat Linux package manager, .gz or.tar.gz files for Linux, Unix, or BSD, and other file formats for other operating systems. Pick the appro-priate file type for your operating system and download that file. In the detailed instructions that follow,we downloaded the .exe file for Windows, and the .tar.gz and .rpm files for Linux and Unix.

Youll also see the product documentation at the Web site. This documentation includes the release notes,short memos that summarize the changes to Regina in each release. You would normally download thelatest official release of Regina. But if youre interested in the exact differences among different releases,the release notes describe them.

The Web site also offers the complete Regina documentation manual. This is a separate file available ineither .zip or .pdf formats. We highly recommend downloading the product documentation.

14

Chapter 1

05_579967 ch01.qxd 2/3/05 9:02 PM Page 14

Installing Regina varies slightly by the file type you download and the target operating system intowhich youre installing. In the sections that follow we describe typical installs under Windows, Linux,and Unix. These instructions enable any desktop user to install Regina and test the examples presentedin subsequent chapters.

Installing Regina under WindowsAssuming you download an .exe file for Windows, all you have to do to install Regina is to double-click on that file. The file is self-extracting. It automatically starts the Install Wizard to guide you ininstalling Regina. Installation is then the same as for any other Windows product.

After you double-click on the .exe file, the Install Wizard prompts you to agree to the licensing terms.After selecting a folder into which to install the product, you are asked which file extensions to associatewith Regina (.rexx, .rex, .rx, and .cmd). Minimally, be sure to associate Regina with its default exten-sion of .rexx. If the install process asks whether to install the Regina Stack Service, reply no. This isan advanced Regina feature that supports capabilities that go beyond standard Rexx.

Windows installation may provide slightly different prompts or questions across releases, but in all casesthe install process is quite simple and looks like what youre familiar from all other Windows products.

Test to make sure that the installation succeeded. Assuming that youve associated the file extensions ofthe Rexx source code files with the Regina interpreter, you can just double-click on a Rexx script to runit. Lets start by running a non-GUI Rexx script from the command-line prompt.

To get to the Windows command prompt, select Start | Run and then enter either command or cmd into theRun box (depending on your version of Windows) to get a command prompt window. Once at the com-mand prompt, change the current directory to the Regina directory that contains the demo programs. Forexample, if you installed Regina on the C: drive under the directory Regina, its demo programs are prob-ably under the directory Regina\demo. So, enter these commands into the command window:

c:cd \Regina\demo

Once in the directory where the source code of the Rexx program you want to run resides, just enter thescripts name to execute it. For example, lets benchmark your system by running the demo programused in the first table in this chapter, called rexxcps.rexx. You can compare your systems performanceto those listed in the first table. To run the program, enter:

rexxcps.rexx

Results from program execution appear on the command prompt screen. It is very unlikely youllencounter an error. If you do, the most common error message looks similar to this:

rexxcps.rexx is not recognized as an internal or external command, operableprogram or batch file

15

Introduction to Scripting and Rexx

05_579967 ch01.qxd 2/3/05 9:02 PM Page 15

This means that either you have not entered the correctly spelled name of the Rexx program at the com-mand prompt, or the demo program is not in the current or working directory. Check to ensure thatthe demo program resides in the current directory and that you entered its name accurately. Anotherpossibility is that you did not associate files with the extension of .rexx with Regina when installing theproduct. In this case, you need to establish the proper Windows file association between Regina and filesof type .rexx. Go to Windows file association panel to ensure this association exists. On most versionsof Windows, you get to the file association panel through the file Explorer, then access the options Tools| Folder Options | File Types. Or just enter the keywords associating files to Windows help tofind the proper panel.

When you enter only the name of the Rexx script to run to the command prompt, as in the precedingexample, you run the script implicitly. Double-clicking on the script file also executes it implicitly. Analternative way to run Regina Rexx scripts is to explicitly invoke the interpreter against the script youwish to run. From the directory in which the script resides, enter this command to the command line:

regina rexxcps.rexx

or

regina rexxcps

You should see the programs output on the command prompt screen. If you did not associate files oftype .rexx with Regina, you will have to explicitly invoke Regina on the Rexx script in order to run it.

Try creating your own first Rexx script. Enter this two-line script via the Notepad editor and save itunder filename testme.rexx:

/* a simple Rexx test program */say hello

From the same directory that the newly entered program resides in enter:

testme.rexx

or

regina testme

You should see the program output hello on the screen. The Rexx say instruction writes it to the display.

Windows installation is simple and automated. Problems are extremely rare. If you do experience aproblem, check that files of extension .rexx are associated with the Regina executable, and that thedirectory in which the Regina executable resides is in the Windows PATH environmental variable. If allelse fails, just reinstall the product. Regina includes an uninstaller you should run first, before tryingto reinstall it. The uninstall program is available from the Windows menu at Start | Programs |Regina Rexx, or in Reginas main installation directory under the filename uninstall.exe.

16

Chapter 1

05_579967 ch01.qxd 2/3/05 9:02 PM Page 16

Installing Regina under Linux and UnixThere are several ways to install Regina Rexx on Linux, Unix, or BSD systems. This section describes asimple, generic approach that will work for almost any Unix-derived operating system. Where slight dif-ferences exist, the Regina Install Notes that download with the product point them out. If you have theautomated-install tool called the Red Hat Package Manager available, you may wish to follow the alter-native install procedures in the section that follows entitled Installing Regina with Red Hat PackageManager. But we ask that you read this section first so that you understand how to test your install andrun Rexx scripts.

To install Regina under any Linux, Unix, or BSD family operating system, use the root user ID anddownload the source .tar.gz file into an empty directory. In this example, we downloaded the filenamed Regina-REXX.3.3.tar.gz into an empty directory we created named: /regina. Switch intothat directory so that it is your working directory:

cd /regina

Uncompress the file by entering the gzip command, naming the file you just downloaded as its operand:

gzip -d Regina-REXX-3.3.tar.gz

This produces an uncompressed archive or .tar file. In this example, this output file would be named:

Regina-REXX.3.3.tar

Extract all the files from the archive or .tar file into a subdirectory of the current directory by issuingthe tar command:

tar xvf Regina-REXX.3.3.tar # Most Linuxes and Unixes

or

tar -xvf Regina-REXX.3.3.tar # some OSs require a dash before the options

In this example, the files were automatically extracted from the archive file and placed into a directorynamed /regina/Regina-3.3.

Change your current directory to the directory to which the files were extracted and read the InstallNotes. They are usually in a file named INSTALL* or README.*. The filename may be either upper- orlowercase, but in any case it will be similar to one of these.

For example, these two commands would change to the proper directory and allow you to view theInstall Notes assuming they are in a file named INSTALL:

cd Regina-3.3more INSTALL

17

Introduction to Scripting and Rexx

05_579967 ch01.qxd 2/3/05 9:02 PM Page 17

Now, do what the Install Notes tell you to do, and you will have successfully installed Regina. If youlogged in as the root user ID to Linux or most Unixes, all you have to do to complete the install is enterthese two commands to the operating system:

./configuremake install

These commands configure and install Regina. Since they compile source code, they require a C com-piler to run. Almost all Linux, Unix, and BSD machines will have a C compiler present. In the rare eventthat your system does not have one installed, download a free compiler from any of several sites includ-ing www.gnu.org.

Now, test that the installation succeeded by running one of the Regina-provided demo scripts in thedemo subdirectory. Lets benchmark your system by running the benchmark program used in the firsttable of this chapter. You can compare your systems performance to the examples listed in the table.The program to run is called rexxcps.rexx. To run it, enter:

./regina demo/rexxcps.rexx

or

./regina demo/rexxcps

The characters ./ tell Linux to look for the interpreter program regina in the current directory. Youcan eliminate the need for these two characters by adding that directory to your PATH environmentalvariable. Then, you can enter:

regina demo/rexxcps

In the unlikely event you get a message similar to the following, you need to set an environmental vari-able so that the Regina interpreter can locate its library file. See the Reginas Install Notes for a simplesolution to this problem:

regina: error while loading shared libraries: libregina.so: cannot open shared object file: No such file or directory

Now, lets create our own first sample script. Access a text editor such as vi or emacs, and enter thesetwo lines into a file:

/* a simple Rexx test program */say hello

Save the file under the name testme.rexx. After exiting the editor, make the Rexx script file executable.To do this, change its permissions to executable with the operating systems chmod command:

chmod +x testme.rexx

Now you can run the script by this command and view its output. The script writes the single word,hello, to your display screen through Rexxs say instruction:

regina testme.rexx

18

Chapter 1

05_579967 ch01.qxd 2/3/05 9:02 PM Page 18

On Linux, Unix, and BSD platforms, it is common to code the first line of the Rexx script to tell the oper-ating system which interpreter should execute that script. This allows you to run the script implicitly, byspecifying only the name of the script to run to the operating systems command line:

testme.rexx

To set this up, the first line of the script must start with the characters #!, encoded starting in the firstposition of the first line. These two characters are then immediately followed by the fully qualified pathname of the Rexx interpreter executable. For example, for our version of Regina, the name of the exe-cutable was regina and it was installed it into the default directory named /usr/bin. The sample scriptwould then be entered like this:

#!/usr/bin/regina

/* a simple Rexx test program */say hello

Thats all there is to installing Regina under Linux, Unix, or BSD. Our example assumes a simple approach.We used the root user ID and left all Regina files in the subdirectory into which the archive extract com-mand (tar xvf) placed them. For a personal computer, this is all you need to do. On shared servers, pro-cedures can sometimes be more complicated. For example, you might want to install the product undersome user ID other than root, or you might be a systems administrator who must follow your organiza-tions product install standards. Read the Install Notes that download with Regina to handle these morecomplicated situations. Chapter 19 covers several more advanced aspects of Rexx installs in its section enti-tled Multiple Rexx Interpreters on One Computer. Chapters 20 through 30 address specific Rexx inter-preters and tell how to download and install them.

Installing Regina with Red Hat Package ManagerTheres also a simpler way to install Regina on many Linux and some Unix systems. As described here,this procedure works only for Intel- or clone-based computers and does not require a C compiler. TheRed Hat Package Manager, or RPM, is a tool that automates product installation. Check to see if you haveRPM available to you by entering this command to your operating systems command prompt. It lists allthe RPM packages or products installed on your computer:

rpm -qa

To install Regina using the RPM, log in as the root user ID and download the Regina file with the filenameextension .i386.rpm. Then enter the rpm command to the operating systems prompt to install Regina:

rpm ivv Regina-REXX-3.3-1.i386.rpm # install with feedback

The switches ivv tell the rpm command to install the product and issue verbose comments on what itdoes. These describe any errors (unlikely) as well as informational messages and the directories used forthe product installation. The name of the download file will vary slightly by release, of course. For moredetailed information on RPM installs, see Chapter 21.

19

Introduction to Scripting and Rexx

05_579967 ch01.qxd 2/3/05 9:02 PM Page 19

SummaryThis chapter lists the advantages of scripting in Rexx and suggests where Rexx is most useful. Given itspower, flexibility, portability, and ease of use, Rexx is suitable for addressing a wide range of program-ming problems. The only situations where Rexx does not apply are those oriented toward systems pro-gramming and programs that demand totally optimized machine utilization.

Rexx distinguishes itself among scripting languages by combining ease of use with power. Rexx usesspecific interpreter design techniques to achieve this combination. Rexx has simple syntax, minimalspecial variables, no default variables, a case-insensitive free-format combined with a small, easilylearned instruction set. Its many built-in functions, extensibility, and the ability to issue commands to theoperating system and other external interfaces give Rexx power while retaining ease of use.

Ease of use is important even to highly experienced computer professionals because it reduces errorrates and determines the life span of their code. Experienced developers leverage a quickly coded lan-guage like Rexx to achieve outstanding productivity.

The final part of this chapter showed how to download and install Regina Rexx under Windows, Linux,and Unix. This popular Rexx interpreter is a free, open-source product you can use to learn Rexx in thetutorial of the following chapters. Any other standard Rexx interpreter could be used as well. The nextseveral chapters get you quickly up and running Rexx scripts through an example-based tutorial.

*IBM Corporation estimates that there are up to one million Rexx users worldwide, as posted on theirWeb site on February 2004.

Test Your Understanding1. In what way is Rexx a higher-level language than compiled languages like C or C++ ? Whats a

glue language? Why is there an industry-wide trend towards scripting languages?

2. Are developers required to code Rexx instructions starting in any particular column? In upper-or lowercase?

3. If youre an expert programmer, why is ease of use still important?

4. What are names of the two object-oriented Rexx interpreters? Will standard or classic Rexxscripts run under these OO interpreters without alteration?

5. Does Rexx run on Palm Pilots? How about cel