Rexx Programmer's Reference

Transcription

Rexx Programmer’s ReferenceHoward Fosdick

Rexx Programmer’s ReferenceHoward Fosdick

Rexx Programmer’s ReferencePublished byWiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256www.wiley.comCopyright 2005 by Wiley Publishing, Inc., Indianapolis, IndianaPublished simultaneously in CanadaISBN: 0-7645-7996-7Manufactured in the United States of America10 9 8 7 6 5 4 3 2 11MA/ST/QS/QV/INNo 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: brandreview@wiley.com.LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHORMAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, 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 SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL 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 RECOMMENDATIONS 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 contact 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 mentionedin this book.

About the AuthorHoward FosdickHoward Fosdick has performed DBA and systems support work as an independent consultant for 15years. He’s coded in Rexx for nearly two decades and has worked in most other major scripting languages. 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.”

CreditsSenior Acquisitions EditorProject CoordinatorDebra Williams CauleyErin SmithDevelopment EditorGraphics and Production SpecialistsEileen Bien CalabroJonelle BurnsCarrie FosterLauren GoddardDenny HagerJoyce HaugheyJennifer HeleineProduction EditorFelicia RobinsonTechnical ReviewerMark HesslingQuality Control TechniciansCopy EditorPublication ServicesEditorial ManagerJohn GreenoughLeeann HarneyJessica KramerCarl William PierceMary Beth WakefieldProofreading and IndexingVice President & Executive Group PublisherRichard SwadleyVice President and PublisherJoseph B. WikertTECHBOOKS Production Services

To Kate, my parents, and Phoebe Jane.

ForewordRexx 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.Cowlishaw’s 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 programming 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 language. It shows how to use the most popular implementations of Rexx and Rexx external function packages 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 GroßeCoosmann, 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. I’m 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/

AcknowledgmentsSpecial 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 helpfulness 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 theirsuggestions.I would like to give heartfelt thanks to María 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 , Stéphane Henault, Mark Hessling, Jack Hicks, IBM Corporation, René Vincent Jansen,Jaxo Inc., Kåre 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 writing 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 Ashley—IBM Corporation, project leader of the Mod Rexx project for scripts appearing in thechapter on Apache programming with Mod RexxLes Cottrell and the Stanford Linear Accelerator Laboratory—Authors of Rexx/CGI library for a scriptillustrating their Rexx/CGI libraryHenri Henault & Sons—Authors of the Internet/REXX HHNS WorkBench for a script and screen shotillustrating the Internet/REXX HHNS WorkBench.

AcknowledgmentsMark Hessling—Developer/maintainer of Regina Rexx and many open source Rexx tools for materialon Rexx/gd and the reference tables of Rexx/Tk functionsPatrick TJ McPhee—Developer of RexxXML for the example program appearing in the chapter onRexxXMLPierre 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

Contents at a GlanceForewordAcknowledgmentsIntroductionPart hapterChapterChapterChapter11: Introduction to Scripting and Rexx2: Language Basics3: Control Structures4: Arrays5: Input and Output6: String Manipulation7: Numbers, Calculations, and Conversions8: Subroutines, Functions, and Modularity9: Debugging and the Trace Facility10: Errors and Condition Trapping11: The External Data Queue, or “Stack”12: Rexx with Style13: Writing Portable Rexx14: Issuing System Commands15: Interfacing to Relational Databases16: Graphical User Interfaces17: Web Programming with CGI and Apache18: XML and Other InterfacesPart 26:27:28:Evolution and s and Embedded ProgrammingRexx for Palm OSr4 and Object-Oriented roo!Open Object RexxOpen Object Rexx Tutorial307331345359385421433447459475

Contents at a GlanceChapter 29: IBM Mainframe RexxChapter 30: NetRexxPart ppendixIndexxiv493515529A: ResourcesB: InstructionsC: FunctionsD: Regina Extended FunctionsE: Mainframe Extended FunctionsF: Rexx/SQL FunctionsG: Rexx/Tk FunctionsH: Tools, Interfaces, and PackagesI: Open Object Rexx: Classes and MethodsJ: Mod Rexx: Functions and Special VariablesK: NetRexx: Quick ReferenceL: Interpreter System InformationM: Answers to “Test Your Understanding” 7

ContentsForewordAcknowledgmentsIntroductionWho This Book Is ForWhat This Book CoversHow This Book Is StructuredWhat You Need to Use This BookConventionsSource ixxxiiixxxiiixxxivPart I1Chapter 1: Introduction to Scripting and Rexx3OverviewWhy Scripting?Why Rexx?Power and FlexibilityUniversalityTypical Rexx ApplicationsWhat Rexx Doesn’t DoWhich Rexx?Downloading Regina RexxInstalling Regina under WindowsInstalling Regina under Linux and UnixInstalling Regina with Red Hat Package ManagerSummaryTest Your UnderstandingChapter 2: Language BasicsOverviewA First Program3367891112141517192020212121

ContentsLanguage ElementsOperatorsSummaryTest Your UnderstandingChapter 3: Control StructuresOverviewStructured Programming in RexxIF StatementsDO StatementsA Sample ProgramSELECT StatementsCALL StatementsAnother Sample ProgramUnstructured Control InstructionsSummaryTest Your UnderstandingChapter 4: ArraysOverviewThe BasicsA Sample ProgramAssociative ArraysA Sample Associative Array ProgramCreating Data Structures Based on ArraysSummaryTest Your UnderstandingChapter 5: Input and OutputOverviewThe Conceptual I/O ModelLine-Oriented Standard I/OCharacter-Oriented Standard I/OConversational I/ORedirected I/OI/O IssuesSummaryTest Your 535457606163646567676769727575767777

ContentsChapter 6: String ManipulationOverviewConcatenation and ParsingA Sample ProgramString FunctionsThe Word-Oriented FunctionsThe Bit String Functions and ConversionsSummaryTest Your UnderstandingChapter 7: Numbers, Calculations, and ConversionsOverviewThe BasicsMore Numeric FunctionsConversionsA Sample ProgramSummaryTest Your UnderstandingChapter 8: Subroutines, Functions, and ModularityOverviewThe Building BlocksInternal Functions and SubroutinesPassing Parameters into a Script from the Command LinePassing Parameters into Subroutines and FunctionsA Sample ProgramThe Function Search OrderRecursionMore on ScopingAnother Sample ProgramSummaryTest Your UnderstandingChapter 9: Debugging and the Trace FacilityOverviewThe say InstructionThe trace InstructionReading Trace OutputThe trace 38139xvii

ContentsInteractive TracingSummaryTest Your UnderstandingChapter 10: Errors and Condition TrappingOverviewError TrappingHow to Trap ErrorsA Sample ProgramAn Improved ProgramSpecial Variablessignal versus callThe condition FunctionA Generic Error-Trap RoutineLimitationsSummaryTest Your UnderstandingChapter 11: The External Data Queue, or “Stack”OverviewWhat Is the Stack?An Example — Placing Data into the Stack and Retrieving ItAnother Example — The Stack for Interroutine CommunicationPractical

is 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 author shallbe liable for damages arising herefrom. the fact that an organization or website is referred to in this work as acitation and/or apotential source of further .