REXX/400 Programmer’s Guide. Version 4
Дата: Август 1997
Источник: IBM
S/400 Advanced Series
Contents
Notices
Programming Interface Information
Trademarks
About REXX/400 Programmer’s Guide
Who Should Read This Book
What You Should Know before Reading This Book
What This Book Contains
Prerequisite and Related Information
Information Available on the World Wide Web
Chapter 1. Using REXX on the AS/400 System
Using REXX on the AS/400 System
Learning About ...
An Interpreted Language
Free Format
Variables Without Type
Built-in Functions
Parsing
How to Determine and Correct Programming Errors
REXX and Systems Application Architecture
Understanding the AS/400 System Security
Chapter 2. Writing and Running REXX Programs
Understanding the Parts of a REXX Program
Using Clauses
Understanding REXX Source Entry
Using REXX Source Type in Source Entry
Using REXX Programs as Source File Members
Understanding REXX as an Interpreted Language
Running REXX Programs
Using the Start REXX Procedure Command
Running REXX Programs by Using User-Defined Commands With REXX
Using the Program Development Manager (PDM) Work with Members
Option
Starting REXX from a Program
Using REXX Files
Using the Integrated Language Environment (ILE) Session Manager
Using the SAY and PULL Keyword Instructions
Using Interactive Mode
Using Batch Mode
Chapter 3. Using Variables
Understanding Variables and Constants
Using Constants
Using Variables
Using Compound Symbols
Stems and Tails
Derived Names
Arrays
Using Variables in Programs, Functions, and Subroutines
Using Special Variables
Using the SYMBOL Function
Using the PROCEDURE Instruction
Chapter 4. Using REXX Expressions
Using Terms and Operators
Using Arithmetic Operators
Using String Operators
Using Comparison Operators
Using Logical Operators
Using Function Calls as Expressions
Using Expressions in Instructions
Using Expressions as Commands
Chapter 5. Using REXX Instructions
Learning About Keyword Instructions
Using Structured Programming
Using Branches
Using Loops
Understanding Programming Style
Using the INTERPRET Instruction
Using a REXX Program Instead of a CL Program
Chapter 6. Using REXX Parsing Techniques
Understanding Parsing
Using the PARSE Instruction
Using Templates
Using Placeholders
Parsing Variables and Expressions
Using Special Parsing Techniques
Using Parsing in a Program
Parsing With Patterns
Using Literal Patterns
Using Positional Patterns
Using Variables in Patterns
Using String Functions
Managing Strings
Measuring Strings
Chapter 7. Understanding Commands and Command Environments
Understanding Commands
Understanding Clause Interpretation
Understanding Command Environments
Understanding Messages
Understanding Return Codes
Understanding the Error and Failure Conditions
Understanding CL Command Environment Conditions
Understanding CPICOMM and EXECSQL Command Environment Conditions 86
Understanding User-Defined Command Environment Conditions
Understanding the Control Language (CL) Command Environment
Chapter 8. Using REXX Functions and Subroutines
Understanding Functions and Subroutines
Understanding the Differences Between Functions and Subroutines
Using Internal Routines
Using External Routines
Understanding External Routines Written in REXX
Understanding External Routines Written in Other Languages
Accessing Parameters
Returning Results
Understanding the Function Search Order
Using REXX Built-in Functions
Using the ADDRESS Built-in Function
Using the DATE Built-in Function
Using the ERRORTEXT Built-in Function
Using the FORMAT Built-in Function
Using the MAX and MIN Built-in Functions
Using the SETMSGRC Built-in Function
Using the SOURCELINE Built-in Function
Using the TIME Built-in Function
Understanding Conversion Functions
Understanding Data Formats
Using Conversion Functions
Chapter 9. Using the REXX External Data Queue
Learning About the REXX External Data Queue
Using the REXX Queue Services on the AS/400 System
Starting Queuing Services
Understanding Queue Management Instructions
Using the PUSH Instruction
Using the QUEUE Instruction
Using the PULL Instruction
Using the Add REXX Buffer (ADDREXBUF) Command
Using the Remove REXX Buffer (RMVREXBUF) Command
Chapter 10. Determining Problems with REXX Programs
Using the TRACE Instruction and the TRACE Function
Using Interactive Tracing
Using Trace Settings
Interpreting Trace Results
Using the Trace REXX (TRCREX) Command
Chapter 11. Understanding Condition Trapping
Defining Conditions
Defining Condition Traps
Using Condition Trapping
Trapping Multiple Conditions
Appendix A. REXX Keywords
Appendix B. REXX Built-in Functions
Appendix C. Double-Byte Character Set Support
Appendix D. Operators and Order of Operations
Operators
Order of Operations
Contents
Appendix E. Sample REXX Programs
Appendix F. Sample REXX Programs for the AS/400 System
Appendix G. Communication Between REXX/400 and ILE/C
Calling an ILE/C Program From REXX
Calling ILE/C as an External Subroutine
Calling ILE/C as an External Function
Calling ILE/C as a Command Environment
Calling ILE/C with the CL CALL Command
Passing Parameters and Control to ILE/C
Calling External Subroutines and Functions
Calling a Command Environment
Using the CL CALL Command
Using the REXX External Data Queue
Receiving Parameters in an ILE/C Program
Calling ILE/C Programs as External Functions or Subroutines
Calling ILE/C Programs as Command Environments
Calling ILE/C Programs with the CL CALL Command
Receiving Parameters from the REXX External Data Queue
Returning Results and Return Codes from ILE/C Programs
Returning Results with the Variable Pool Interface
Returning Results from the CL Command Environment
Returning Results in the REXX External Data Queue
Example Using the REXX External Data Queue
Appendix H. Communication Between REXX/400 and Other Languages
Using the REXX External Data Queue API
Pushing Data from RPG into the Queue
Updating the File from the Queue by RPG
Pushing Data from COBOL into the Queue
Overriding STDIN and STDOUT
Appendix I. String Manipulation in REXX versus CL
Searching for a String Pattern
Extracting Words from a String
Concatenation with Numeric Variables
Glossary
Bibliography
Index
About REXX/400 Programmer’s Guide
This guide provides a wide-range discussion of programming with the IBM REXX for AS/400 system (also known as REXX/400). Its primary purpose is to provide useful programming information and examples to those who are new to REXX/400 and to provide those who have used REXX in other computing environments with information about the REXX/400 implementation.
This guide may refer to products that are announced, but are not yet available. In the back of this book is a glossary and an index. Use the glossary to find the meaning of an unfamiliar term. Use the index to look up a topic and to see on which pages the topic is covered.
Who Should Read This Book
This guide is intended for the AS/400 system or application programmer, who wants to learn how to use REXX on the AS/400. While using the control language (CL) with REXX is discussed, much of the material in this guide applies to the system in general and may be used by programmers of all high-level languages supported by the AS/400 system.
What You Should Know before Reading This Book
Before using this guide, you should be familiar with general programming concepts and terminology, and have a general understanding of OS/400 and the AS/400 system. For more information about REXX, the REXX/400 Reference provides detail on all REXX instructions, functions, input and output, parsing, and application interfaces.
What This Book Contains
You will be introduced to the REstructured eXtended eXecutor (REXX) language. In addition, you will learn about the following: Contents of a REXX program, rules of syntax and substitution, and the use of Variables How to write expressions, use conversations, enter AS/400 commands, control your program, and construct and design your REXX programs Examples of REXX programs.
Prerequisite and Related Information
For information about other AS/400 publications (except Advanced 36), see either of the following: The Publications Reference book, SC41-5003, in the AS/400 Softcopy Library.
The AS/400 Information Directory , a unique, multimedia interface to a searchable database that contains descriptions of titles available from IBM or from selected other publishers. The AS/400 Information Directory is shipped with the OS/400 operating system at no charge.
Chapter 1. Using REXX on the AS/400 System
Using REXX on the AS/400 System
As part of Operating System/400 (OS/400), REXX adds programming capabilities as a command processing language and an applications programming language. REXX, or the Restructured EXtended eXecutor language, is a procedural language for the Application System/400 (AS/400) system. REXX programs can reduce long, complex, or repetitious tasks to a single action. REXX provides both an alternative to using Control Language (CL) programs and away to expand CL.
- REXX provides a full set of structured programming instructions like DO...END and IF...THEN...ELSE. These instructions are discussed in Chapter 5, “Using REXX Instructions” on page 45.
- REXX can be used with other command environments it recognizes. These languages can be provided by the system, as CL is, or provided by the user within the rules which must be followed for REXX to find and recognize them. The interaction between REXX and CL is discussed in Chapter 7, “Understanding Commands and Command Environments” on page 79. User-defined interaction is discussed in the REXX/400 Reference
.
Learning About ...
REXX is different from most of the programming languages currently available for the AS/400 system. Some of these differences, as well as some of the functional characteristics of REXX, are described here.
An Interpreted Language
The REXX language is an interpreted language. When a REXX program runs, the language processor directly interprets each language statement. Languages that are not interpreted must be compiled into a program object before they are run.
Free Format
REXX has only a few rules about programming format. This allows freedom and flexibility in program format. A single instruction can span many lines or multiple instructions can be entered on a single line. Instructions can begin in any column. Spaces or entire lines can be skipped. Instructions can be typed in uppercase, lowercase, or mixed case. REXX does not require line numbering.
Variables Without Type
REXX regards all data as character strings. REXX does not require that variables or arrays be declared as strings or numbers, where CL requires (*CHAR) or (*DEC). REXX will perform arithmetic on any string that represents a valid number, including those in exponential formats. REXX variables are discussed in Chapter 3, “Using Variables” on page 17.
Built-in Functions
REXX supplies built-in functions that perform various processing, searching, and comparison operations for both text and numbers. Other built-in functions provide formatting capabilities and arithmetic calculations. The REXX functions are discussed in “Using REXX Built-in Functions” on page 104.
Parsing
REXX includes extensive capabilities for working with character strings. Parsing input lets you easily assign variables from different input sources and manage the flow of information through your REXX program. REXX parsing is discussed in Chapter 6, “Using REXX Parsing Techniques” on page 61.
How to Determine and Correct Programming Errors
When a REXX program contains an error, messages with meaningful explanations are shown on the display. In addition, the TRACE instruction provides a powerful tool for determining problems in your REXX program. A complete description of these tools is provided in Chapter 10, “Determining Problems with REXX Programs” on page 123.
REXX and Systems Application Architecture
REXX/400 is one of the programming languages included in the IBM Systems Application Architecture (SAA). SAA is a framework of standards and definitions intended to promote consistency among different IBM products. Programs written in REXX according to SAA specifications are portable to all other SAA computing environments including the VM, TSO/E or IBM Operating System/2 (OS/2) computing environment, as long as system-specific instructions, functions or commands are not used.
To learn more about working with REXX in SAA supported computing environments, see the SAA Common Programming Interface REXX Level 2 Reference.
REXX/400, referred to in this book as REXX, is the SAA implementation on the AS/400 system. Occasionally, in this book, you will see the term REXX/400 used. If you are familiar with REXX in other computing environments, you should note that this term identifies an option available only to REXX on the AS/400 system.
Understanding the AS/400 System Security
Security of REXX programs is managed at a source file level. For more information on AS/400 system security, see the Security – Reference book.
Полный текст книги в формате PDF можно скачать по этой ссылке.