Rexx

0
27

Rexx – Overlook at

Rexx (Restructured-coloured-coloured-coloured Extended Executor) is styleed to be a scripting language. It’s goal is to develop scripting as easy, fast, reliable, and error-free as achievable. Many kind of kind of programming languages are styleed for compatibility with older languages, and are composed for specific auexpirences or platforms. Rexx ignores extraneous goals. It was styleed from day one to be powerful, yet easy to use.

Rexx was styleed and 1st implemented, in bumembly language, as an 'own-time' project between 20th March 1979 and the middle of 1982 by Mike Cowlishaw of IBM, preliminaryly as a scripting programming language to replace the languages EXEC and EXEC 2. It was styleed to be a macro or scripting language for any kind of kind of system. As such, Rexx is conpartred-coloured-coloured-coloured a precursor to Tcl and Python. Rexx was furthermore intended by it is creator to be a simplified and easier to belowstand version of the PL/I programming language.

Features of Rexx

Rexx as a programming language has the folloearng key features −

  • Simple syntax

  • The capability to rawaye commands to multiple environments

  • The capability to supinterface functions, procedures and commands bumociated with a specific invoking environment.

  • A built-in stack, with the capability to interoperate with the host stack if appropriate now presently there is one.

  • Small instruction set containing just 2 dozen instructions

  • Freeform syntax

  • Case-insensit downive tokens, including variable names

  • Charactionioner string basis

  • Dynamic data typing, no declarations

  • No reserved keywords, other than in local context

  • No include file facililinks

  • Arbitrary numerical precision

  • Decimal arithmetic, floating-stage

  • A rich selection of built-in functions, especially string and word procesperform

  • Automatic storage management

  • Crash protection

  • Content addressable data structures

  • Associative arrays

  • Straightforbattdelivered access to system commands and facililinks

  • Simple error-handling, and built-in tracing and debugger

  • Few artificial limitations

  • Simplified I/O facililinks

The awayicial websit downe for Rexx is www.oorexx.org

Official Websit downe Rex

Rexx – Environment

Try it Option Online

We have set up the Rexx Programming environment on-line, so thead wear you can compile and execute all the available examples on line. It gives you confidence in whead wear you are reading and enables you to verify the programs with various options. Feel free to modify any kind of kind of example and execute it on-line.

Try the folloearng example uperform our on-line compiler available at CodingGround.

/* Main program */ 
say "Hello World" 

For the majority of of the examples given in this particular particular tutorial, you will find a Try it option in our websit downe code sections at the top appropriate corner thead wear will consider you to the online compiler. So just develop use of it and enjoy your belowstanding.

Before you can start functioning on Rexx, you need to ensure thead wear you have a compallowey functional version of Rexx operatening on your system. This chapter will exordinary the installation of Rexx and it is subsequent configuration on a Windows machine to get started with Rexx.

Ensure the folloearng System requirements are met before proceeding with the installation.

System Requirements

Memory 2 GB RAM (recommended)
Disk Space No minimum requirement. Preferably to have enough storage to store the programs which will be developd uperform Rexx.
Operating System Version Rexx can be instaldelivered on Windows, Ubuntu/Debian, Mac OS X.

Downloading Rexx

To download Rexx, you ought to use the folloearng URL − /index.php?s=wwwoorexxorgdownload.html

This page has a variety of downloads for various versions of Rexx as shown in the folloearng screenshot.

Rexx Download

Click on the ‘ooRexx install files’ in the table with the minder of Relrelayve 4.2.0.

After this particular particular, you will be re-immediateed to the folloearng page.

ooRex Install Files

Click on the ooRexx-4.2.0.earndows.x86_64.exe to download the 64-bit version of the gentlebattlee. We will speak abaway regarding the installation of the gentlebattlee in the folloearng chapter.

Rexx – Installation

The folloearng steps will exordinary in detail how Rexx can be instaldelivered on a Windows system.

Step 1 − Launch the Installer downloaded in the earlayr section. After the installer starts, click on the Run button.

Launch the Installer

Step 2 − Click the next button on the folloearng screen to proceed with the installation.

Next Button

Step 3 − Click on the I Agree button to proceed.

I Agree

Step 4 − Accept the default components and then click on the next button.

Default Components

Step 5 − Choose the installation location and click on the Next button.

Installation Location

Step 6 − Accept the default processes which will be instaldelivered and click on the Next button.

Accept Default Processes

Step 7 − Choose the default file bumociations and click on the Next button.

Default File Associations

Step 8 − Click on the check packagees of send Rexx items to the executables and then click on the Next button as shown in the folloearng screenshot.

Check Boxes

Step 9 − In the next screen, select the editor for functioning with Rexx files. Keep the notepad as the default option. Also accept the default extension for every Rexx file.

Rexx Files

Step 10 − Accept the default settings on the folloearng screen thead wear comes up and click on the Next button to proceed further with the installation.

Default Settings

Step 11 − Finally click on the Install button to proceed with the installation.

Install Button

Step 12 − Once the installation is compallowe, you need to click on the Next button to proceed further.

Installation Compallowe

Step 13 − Click on the Finish button to compallowe the installation.

Finish Button

Rexx – Installation of Plugin-Ins

In this particular particular chapter, we will speak abaway on how to install plug-ins on popular IDE’s (Integrated Development Environment). Rexx as a programming language is furthermore available in popular IDE’s such as Eclipse. Let’s look at how we can get the required-coloured-coloured-coloured plugin’s in these IDE’s, so thead wear you have more choices in functioning with Rexx.

Installation in Eclipse

To develop a trouble-free installation of Rexx in Eclipse, you will need to adhere to the folloearng steps.

Step 1 − Open Eclipse and click on the Menu item, Help → Eclipse Marketplace as shown in the folloearng screenshot.

Eclipse Marketplace

Step 2 − In the next dialog package, enter Rexx in the reresearch criteria and click on the reresearch button.

Next Dialog Box

Once done, click the Install button.

Step 3 − Click on the Confirm button to further continue with the features installation.

Confirm Button

Step 4 − Eclipse will then download the necessary files to start away with the installation. Once done, Eclipse will ask for accepting the license concurments. Click on accepting the license concurments and then click on the Finish button as shown in the folloearng screenshot.

Relook at Licenses

Eclipse will then start installing the gentlebattlee in the background.

Step 5 − You will probably get a security battlening (as shown in the folloearng screenshot). Click on the OK button to proceed.

Security Warning

Step 6 − You will be prompted to restart Eclipse once the updates are instaldelivered. Click Yes to restart Eclipse.

Restart Eclipse

Rexx – Basic Syntax

In order to belowstand the fundamental syntax of Rexx, allow us 1st look at a easy Hello World program.

Example

/* Main program */ 
say "Hello World" 

One can see how easy the hello world program is. It is a easy script line which is used to execute the Hello World program.

The folloearng slimgs need to be noted abaway the above program −

  • The say command is used to awayput a value to the console.

  • The /* */ is used for comments in Rexx.

The awayput of the above program will be −

Hello World

General Form of a Statement

In Rexx, allow’s see a general form of a program. Take a look at the folloearng example.

/* Main program */ 
say add(5,6) 
exit 
add: 
parse arg a,b 
return a + b

The awayput of the above program will be −

11

Let’s go through whead wear we have belowstood from the above program −

  • Add is a function degreatd to add 2 numbers.

  • In the main program, the values of 5 and 6 is used as parameters to the add function.

  • The exit keyword is used to exit from the main program. This is used to variousiate the main program from the add function.

  • The add function is variousiated with the ‘:’ symbol.

  • The parse statement is used to parse the incoming arguments.

  • Finally, the return statement is used to return the sum of the numeric values.

Subrawayines and Functions

In Rexx, the code is normally divided into subrawayines and functions. Subrawayines and functions are used to variousiate the code into various logical devices. The key difference between subrawayines and functions is thead wear functions return a value whereas subrawayines don’t.

Below is a key difference example between a subrawayine and a function for an addition implementation −

Function Implementation

/* Main program */ 
say add(5,6) 
exit 
add: 
parse arg a,b 
return a + b

Subrawayine Implementation

/* Main program */ 
add(5,6) 
exit 
add: 
parse arg a,b 
say a + b

The awayput of both the programs will be the value 11.

Executing Commands

Rexx can be used as a manage language for a variety of command-based systems. The way thead wear Rexx executes commands in these systems is as follows. When Rexx encounters a program line which is neither an instruction nor an bumignment, it treats thead wear line as a string expression which is to be evaluated and then completeed to the environment.

An example is as follows −

Example

/* Main program */ 
parse arg command 
command "file1" 
command "file2" 
command "file3" 
exit 

Each of the 3 similar lines in this particular particular program is a string expression which adds the name of a file (contained in the string constants) to the name of a command (given as a parameter). The resulting string is completeed to the environment to be executed as a command. When the command has completeed, the variable "rc" is set to the exit code of the command.

The awayput of the above program is as follows −

*-* command "file1"                                        
   >>>   " file1" 
   +++   "RC(127)"
      
   5 *-* command "file2"
   >>>   " file2"
   +++   "RC(127)" 
      
   6 *-* command "file3"
   >>>   " file3"
   +++   "RC(127)" 

Keywords in Rexx

The free syntax of REXX implays thead wear some symbols are reserved for the language processor's use in particular contexts.

Wislim particular instructions, some symbols may be reserved to separate the parts of the instruction. These symbols are referred-coloured-coloured-coloured to as keywords. Examples of REXX keywords are the WHILE in a DO instruction, and the THEN (which actionions as a clause terminator in this particular particular case) folloearng an IF or WHEN clause.

Apart from these cases, only easy symbols thead wear are the 1st token in a clause and thead wear are not followed by an "=" or ":" are checked to see if they are instruction keywords. You can use the symbols freely elsewhere in clauses withaway their own being considern to be keywords.

Comments in Rexx

Comments are used to document your code. Single line comments are identified by uperform the /* */ at any kind of kind of posit downion in the line.

An example is as follows −

/* Main program */
/* Call the add function */
add(5,6)

/* Exit the main program */
exit add:

/* Parse the arguments completeed to the add function */ parse arg a,b
/* Display the added numeric values */
say a + b

Comments can furthermore be composed in between a code line as shown in the folloearng program −

/* Main program */ 
/* Call the add function */ 
add(5,6) 

/* Exit the main program */ 
exit 
add: 
parse /* Parse the arguments completeed to the add function */ arg a,b 

/* Display the added numeric values */ 
say a + b

The awayput of the above program will be −

11

You can furthermore have multiple lines in a comment as shown in the folloearng program −

/* Main program 
The below program is used to add numbers 
Call the add function */ 
add(5,6) 
exit 
add: 
parse arg a,b 
say a + b

The awayput of the above program will be −

11

Rexx – DataTypes

In any kind of kind of programming language, you need to use various variables to store various kinds of information. Variables are noslimg but reserved memory locations to store values. This means thead wear when you develop a variable you reserve some space in the memory to store the value bumociated with thead wear variable.

You may like to store information of various data kinds like String, Charactionioner, Wide Charactionioner, Integer, Floating Point, Boolean, etc. Based on the data kind of a variable, the operating system allocates memory and determines whead wear can be stored-coloured-coloured-coloured in the reserved memory.

Built-in Data Types

Rexx awayers a wide variety of built-in data kinds. Folloearng is a list of data kinds which are degreatd in Rexx.

  • Integer − A string of numerics thead wear does not contain a decimal stage or exponent identifier. The 1st charactionioner can be a plus (+) or minus (-) sign. The number thead wear is represented must be between -2147483648 and 2147483647, inclusive.

  • Big Integer − A string of numbers thead wear does not contain a decimal stage or an exponent identifier. The 1st charactionioner can be a plus (+) or minus (-) sign. The number thead wear is represented must be between -9223372036854775808 and 2147483648, inclusive, or between 2147483648 and 9223372036854775807.

  • Decimal − It will be from one of the folloearng formats −

    • A string of numerics thead wear contains a decimal stage but no exponent identifier. The p represents the precision and s represents the level of the decimal number thead wear the string represents. The 1st charactionioner can be a plus (+) or minus (-) sign.

    • A string of numerics thead wear does not contain a decimal stage or an exponent identifier. The 1st charactionioner can be a plus (+) or minus (-) sign. The number thead wear is represented is less than -9223372036854775808 or greater than 9223372036854775807.

  • Float − A string thead wear represents lots in scientific notation. The string consists of a series of numerics followed by an exponent identifier (an E or e followed by an optional plus (+) or minus (-) sign and a series of numerics). The string can start with a plus (+) or minus (-) sign.

  • String − A normal string of charactionioners.

Folloearng are some examples of how every data kind can be used. Again every data kind will be speak abawayed in detail in the subsequent chapters. This is just to get you up to speed with a short description of the above mentioned data kinds.

Integer

An example of how the number data kind can be used is shown in the folloearng program. This program shows the addition of 2 Integers.

Example

/* Main program 
The below program is used to add numbers 
Call the add function */ 
add(5,6)  

exit 
add:  

parse arg a,b 
say a + b 

The awayput of the above program will be −

11

Big Integer

The folloearng program shows the capcapability of Rexx to handle big integers. This program shows how to add 2 big integers.

Example

/* Main program 
The below program is used to add numbers 
Call the add function */ 
add(500000000000,6000000000000000000000)  

exit 
add:  

parse arg a,b 
say a + b

The awayput of the above program will be −

6.00000000E+21

Decimal

The folloearng program shows the capcapability of Rexx to handle decimal numbers. This program shows how to add 2 decimal numbers.

Example

/* Main program 
The below program is used to add numbers 
Call the add function */ 
add(5.5,6.6)  

exit 
add:  

parse arg a,b 
say a + b 

The awayput of the above program will be −

12.1 

Float

The folloearng example show cases how lots can work as a float.

Example

/* Main program 
The below program is used to add numbers 
Call the add function */ 
add(12E2,14E4)  

exit 
add:  

parse arg a,b 
say a + b

The awayput of the above program will be −

141200

String

An example of how the Tuple data kind can be used is shown in the folloearng program.

Here we are defining a Tuple P which has 3 terms. The tuple_size is an inbuilt function degreatd in Rexx which can be used to determine the size of the tuple.

Example

/* Main program */ 
display("hello")  

exit 
display:  

parse arg a 
say a

The awayput of the above program will be −

hello

Rexx – Variables

In Rexx, all variables are bound with the ‘=’ statement. Variable names are occasionally referred-coloured-coloured-coloured to as symbols. They may be composed of Letters, Digit is, and Charactionioners such as ‘. ! ? _’. A variable name you develop must not start with a digit or a period. A easy variable name does not include a period. A variable name thead wear includes a period is caldelivered a compound variable and represents an array or table.

The folloearng are the fundamental kinds of variables in Rexx which were furthermore exordinaryed in the previous chapter −

  • Integers − This is used to represent an integer or a float. An example for this particular particular is 10.

  • Big integers − This represents a big integer value.

  • Decimal − A decimal value is a string of numerics thead wear contains a decimal stage but no exponent identifier.

  • Float − A float value is a string thead wear represents lots in the scientific notation.

  • String − A series of charactionioners degreats a string in Rexx.

Different Types of Variable Functions

In this particular particular section, we will speak abaway regarding the various functions a variable can perform.

Variable Declarations

The general syntax of defining a variable is shown as follows −

var-name = var-value 

where

  • var-name − This is the name of the variable.

  • var-value − This is the value bound to the variable.

The folloearng program is an example of the variable declaration −

Example

/* Main program */ 
X = 40 
Y = 50 
Result = X + Y 
say Result

In the above example, we have 2 variables, one is X which is bound to the value 40 and the next is Y which is bound to the value of 50. Another variable caldelivered Result is bound to the addition of X and Y.

The awayput of the above program will be as follows −

90

Naming Variables

Variable names are occasionally referred-coloured-coloured-coloured to as symbols. They may be composed of Letters, Digit is, and Charactionioners such as ‘. ! ? _’ . A variable name you develop must not start with a digit or period.

If a variable has not yet been bumigned a value, it is referred-coloured-coloured-coloured to as unpreliminaryized. The value of an unpreliminaryized variable is the name of the variable it iself in uppercase allowters.

An example of an unbumigned variable is as follows −

Example

/* Main program */ 
unbumignedvalue 
say unbumignedvalue 

If you operate the above program you will get the folloearng awayput −

UNASSIGNEDVALUE: command not found
   2 *-* unbumignedvalue 
   >>>   "UNASSIGNEDVALUE" 
   +++   "RC(127)"
UNASSIGNEDVALUE

Variables can be bumigned values more than once. The below program shows how the value of X can be bumigned a value multiple times.

Example

/* Main program */ 
X = 40 
X = 50 
say X 

The awayput of the above program will be as follows −

50

Printing Variables

The values of variables are printed uperform the say command. Folloearng is an example of printing a variety number of variables.

Example

/* Main program */ 
X = 40 

/* Display an Integer */ 
say X 
Y = 50.5 

/* Display a Float */ 
say Y 
Z = "hello" 

/* Display a string */ 
say Z 

The awayput of the above program will be as follows −

40 
50.5 
hello 

Rexx – Operators

An operator is a symbol thead wear tells the compiler to perform specific maall of all of thematical or logical manipulations.

Rexx has various kinds of operators which are furthermore exordinaryed in detail as follows −

  • Arithmetic operators
  • Relational operators
  • Logical operators
  • Bitwise operators

Arithmetic Operators

The Rexx language supinterfaces the normal Arithmetic Operators as any kind of kind of the language. Folloearng are the Arithmetic Operators available in Rexx.

Show Example

Operator Description Example
+ Addition of 2 operands 1 + 2 will give 3
Subtractionions second operand from the 1st 1 – 2 will give -1
Multiplication of both operands 2 ∗ 2 will give 4
/ Division of numerator by denominator 2 / 2 will give 1
// Remainder of dividing the 1st number by the second 3 // 2 will give 1
% The div component will perform the division and return the integer component. 3 % 2 will give 1

Relational Operators

Relational Operators allow of the comparison of objects. Folloearng are the relational operators available in Rexx. In Rexx the true value is denoted by 1 and the false value is denoted by 0.

Show Example

Operator Description Example
== Tests the equality between 2 objects 2 = 2 will give 1
< Checks to see if the left object is less than the appropriate operand. 2 < 3 will give 1
=< Checks to see if the left object is less than or equal to the appropriate operand. 2 =< 3 will give 1
> Checks to see if the left object is greater than the appropriate operand. 3 > 2 will give 1
>= Checks to see if the left object is greater than or equal to the appropriate operand. 3 > 2 will give 1

Logical Operators

Logical Operators are used to evaluate Boolean expressions. Folloearng are the logical operators available in Rexx.

Show Example

Operator Description Example
& This is the logical “and” operator 1 or 1 will give 1
| This is the logical “or” operator 1 or 0 will give 1
This is the logical “not” operator will give 1
&& This is the logical exclusive “or” operator 1 && 0 will give 1

Bitwise Operators

Groovy provides four bitwise operators. Below are the bitwise operators available in Groovy

Show Example

Operator Description
bitand This is the bitwise “and” operator
bitor This is the bitwise “or” operator
bitxor This is the bitwise “xor” or Exclusive or operator

Operator Precedence

The folloearng table shows the Operator Precedence for the Rexx operators in order of descending priority of their own precedence.

Operators Precedence
Prefix operators + –
Addition and consider awayionion + –
Comparison operators = == > < >= <=
Logical AND &
Logical OR |
EXCLUSIVE OR &&

Rexx – Arrays

Arrays in any kind of kind of programming language allow you to group a list of values of the exactionion exaction same kind. The use of arrays is thead wear it allows you to construct a list of similar kind of values which are sortable, reresearchable and can be easily manipulated. Rexx furthermore allows one to degreat arrays. These arrays can be one dimensional or multidimensional.

Rexx arrays may be sparse. Thead wear is, not every array posit downion must have a value or actionionually be preliminaryized. There can be empty array posit downions, or slots, between those thead wear do contain data elements. Or arrays can be dense, in which consecutive array slots all contain data elements.

In many kind of kind of programming languages, you must be concerned with whead wear the subscript of the 1st encheck in a table is. Is the 1st numeric subscript 0 or 1? In Rexx, the 1st subscript is whead wearever you use! So, input the 1st array element into posit downion 0 or 1 as you prefer.

array_name.0 = ‘1st element’

or

array_name.1 = ‘1st element’

Let’s look at the various operations available for arrays.

Creating Arrays

Arrays are developd with the exactionion exaction same naming convention which is used for variables in Rexx.

The general syntax for creating arrays is as follows −

Arrayname.index = value 

where

  • Arrayname − This is the name provided to the array.

  • Index − This is the index posit downion in the array to refer to a specific element.

  • Value − This is the value bumigned to the index element in the array.

An example of an array declaration is as follows −

Example

/* Main program */ 
list.1 = 0 
list.2 = 0 
list.3 = 0

The folloearng stages needs to be noted abaway the above program −

  • The name of the array is given as list
  • There are 3 elements of the array which are preliminaryized to the value of 0.

Assigning Values to an Array Element

Values can be re-bumigned to array elements in the exactionion exaction same way as array elements are preliminaryized.

The folloearng program is an example of values which can be bumigned to various index values of an existing array.

/* Main program */ 
list.1 = 0 
list.2 = 0 
list.3 = 0 

/* Assigning brand brand new values to the array*/ 
list.1 = 10 
list.3 = 30 

Displaying Values of an Array

The values of an array can be displayed by referring to the index posit downion of the array element. The folloearng example shows to access various elements of the array.

Example

/* Main program */ 
list.1 = 0 
list.2 = 0 
list.3 = 0 

/* Assigning brand brand new values to the array*/ 
list.1 = 10 
list.3 = 30 
say list.1 
say list.2 
say list.3 

The awayput of the above program will be as follows −

10
0
30

Copying Arrays

All of the elements of an array can be copied onto one more array. The general syntax of this particular particular is as follows −

Nebattleray. = sourcearray. 

where

  • Nebattleray − This is the brand brand new array in which the elements need to be copied onto.

  • Sourcearray − This is the source array from which the elements need to be copied.

An example on how the copy operations for arrays can be carried away is shown in the folloearng program −

Example

/* Main program */ 
list.1 = 0 
list.2 = 0 
list.3 = 0 

/* Assigning brand brand new values to the array*/ 
list.1 = 10 
list.3 = 30 
listbrand brand new. = list. 

say listbrand brand new.1 
say listbrand brand new.2 
say listbrand brand new.3 

The awayput of the above program will be −

10
0
30

Iterating through array elements

Elements of an array can furthermore be iterated by uperform the iterative statements available in Rexx. An example on how this particular particular can be done is as follows −

Example

/* Main program */ 
list.1 = 10 
list.2 = 20 
list.3 = 30 

number_of_elements = 3 
do j = 1 to number_of_elements 
say list.j 
end 

The folloearng stageers need to be noted abaway the above program −

  • The do loop is used to iterate through the array elements.

  • The variable number_of_elements is used to store the number of elements in the array.

  • The variable j is used to iterate through every element of the array.

The awayput of the above program will be −

10
20
30

Two-dimensional Arrays

It was furthermore mentioned thead wear we can construct multi-dimensional arrays in Rexx. Let’s look at an example of how we can implement a 2-dimensional array.

Example

/* Main program */ 
list.1 = 10 
list.1.1 = 11 
list.1.2 = 12 

say list.1 
say list.1.1 
say list.1.2 

The awayput of the above program will be shown as follows −

10
11
12

The folloearng stage needs to be noted abaway the above program −

  • To develop a multidimensional array, we can use one more layer of indexing. So in our example, we used list.1.1 to develop one more internal array for the index value 1 of the list array.

Rexx – Loops

So far we have seen statements which have been executed one after the other in a sequential manner. Additionally, statements are provided in Rexx to alter the flow of manage in a program’s logic. They are then courseified into a flow of manage statements which we will study in detail.

A loop statement allows us to execute a statement or group of statements multiple times. The folloearng illustration is the general form of a loop statement in the majority of of the programming languages.

Loop

Let us speak abaway various loops supinterfaceed by Rexx.

S.No. Loop Type & Description
1 do loop

The do loop is used to execute lots of statements for a particular number of times. The number of times thead wear the statement needs to be executed is determined by the value completeed to the do loop.

2 do-while loop

The do-while statement is used to simulate the easy while loop which is present in other programming languages.

3 do-until loop

The do-until loop is a slight variation of the do while loop. This loop varies in the truthion thead wear is exit is when the condition being evaluated is false.

Controldelivered Repetition

The do loops can be catered-coloured-coloured-coloured to carry away a managedelivered repetition of statements.

Syntax

The general syntax of this particular particular sort of statement is as follows.

do index = start [to limit] [by increment] [for count] 
statement #1 
statement #2 
end 

The difference in this particular particular statement is thead wear appropriate now presently there is an index which is used to manage the number of times the loop is executed. Secondly, appropriate now presently there are parameters which state the value which the index ought to start with, where it ought to end and whead wear is the increment value.

Flow Diagram

Let’s check away the flow diagram of this particular particular loop −

Controldelivered Repetition

From the above diagram you can clearly see thead wear the loop is executed based on the index value and how the index value is incremented.

The folloearng program is an example of the managedelivered repetition statement.

Example

/* Main program */ 
do i = 0 to 5 by 2 
   say "hello" 
end 

In the above program, the value of the count i is set to 0 1st. Then it is incremented in counts of 2 till the value is not greater than 5.

The awayput of the above code will be −

hello 
hello 
hello 

Rexx – Decision Making

Decision making structures require thead wear the programmer specify one or more conditions to be evaluated or checked by the program.

The folloearng diagram shows the general form of a typical decision-making structure found in the majority of of the programming languages.

Decision Making

There is a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

Let’s look at the various decision-making statements available in Rexx.

S.No. Statement & Description
1 If statement

The 1st decision-making statement is the if statement. An if statement consists of a Boolean expression followed by one or more statements.

2 If-else statement

The next decision-making statement is the if-else statement. An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

Nested If Statements

Sometimes appropriate now presently there is a requirement to have multiple if statements embedded inpart every other, as is achievable in other programming languages. In Rexx furthermore this particular particular is achievable.

Syntax

if (condition1) then 
   do 
      #statement1 
   end 
else 
   if (condition2) then 
      do 
      #statement2 
   end

Flow Diagram

The flow diagram of nested if statements is as follows −

Nested If Statement

Let’s consider an example of nested if statement −

Example

/* Main program */ 
i = 50 
if (i < 10) then 
   do 
      say "i is less than 10" 
   end 
else 
if (i < 7) then 
   do 
      say "i is less than 7" 
   end 
else 
   do 
      say "i is greater than 10" 
   end 

The awayput of the above program will be −

i is greater than 10 

Select Statements

Rexx awayers the select statement which can be used to execute expressions based on the awayput of the select statement.

Syntax

The general form of this particular particular statement is −

select 
when (condition#1) then 
statement#1 

when (condition#2) then 
statement#2 
otherwise 

defaultstatement 
end 

The general functioning of this particular particular statement is as follows −

  • The select statement has a range of when statements to evaluate various conditions.

  • Each when clause has a various condition which needs to be evaluated and the subsequent statement is executed.

  • The otherwise statement is used to operate any kind of kind of default statement if the previous when conditions do not evaluate to true.

Flow Diagram

The flow diagram of the select statement is as follows

Select Statement

The folloearng program is an example of the case statement in Rexx.

Example

/* Main program */ 
i = 50 
select 
when(i <= 5) then 
say "i is less than 5" 

when(i <= 10) then 
say "i is less than 10" 

otherwise 
say "i is greater than 10" 
end

The awayput of the above program would be −

i is greater than 10 

Rexx – Numbers

Rexx has the folloearng data kinds when it comes to numbers.

  • Integer − A string of numerics thead wear does not contain a decimal stage or exponent identifier. The 1st charactionioner can be a plus (+) or minus (-) sign. The number thead wear is represented must be between -2147483648 and 2147483647, inclusive.

  • Big Integer − A string of numbers thead wear does not contain a decimal stage or an exponent identifier. The 1st charactionioner can be a plus (+) or minus (-) sign. The number thead wear is represented must be between -9223372036854775808 and 2147483648, inclusive, or between 2147483648 and 9223372036854775807.

  • Decimal − One of the folloearng formats −

    • A string of numerics thead wear contains a decimal stage but no exponent identifier, where p represents the precision and s represents the level of the decimal number thead wear the string represents. The 1st charactionioner can be a plus (+) or minus (-) sign.

    • A string of numerics thead wear does not contain a decimal stage or an exponent identifier. The 1st charactionioner can be a plus (+) or minus (-) sign. The number thead wear is represented is less than -9223372036854775808 or greater than 9223372036854775807.

  • Float − A string thead wear represents lots in scientific notation. The string consists of a series of numerics followed by an exponent identifier (an E or e followed by an optional plus (+) or minus (-) sign and a series of numerics). The string can start with a plus (+) or minus (-) sign.

Let’s now look at the various methods available for numbers.

S.No. Methods available for Numbers
1 ABS

This method returns the absolute value of an input number.

2 MAX

This method returns the maximum value from a list of numbers.

3 MIN

This method returns the minimum value from a list of numbers.

4 RANDOM

This method returns a random generated number.

5 SIGN

Returns 1 if number is greater than 0, or 0 if the number is 0, or -1 if the number is less than 0.

6 TRUNC

This method toperatecates lots.

Rexx – Strings

Strings in Rexx are denoted by a sequence of charactionioners. The folloearng program is an example of strings −

/* Main program */ 
a = "This is a string" 
say a

The awayput of the above program is as follows −

This is a string 

Let’s speak abaway some methods which are available in Rexx for strings.

S.No. Methods available in Rexx for Strings
1 left

This method returns a particular number of charactionioners from the left of the string.

2 appropriate

This method returns a particular number of charactionioners from the appropriate of the string.

3 duration

This method returns the number of charactionioners in the string.

4 reverse

This method returns the charactionioners in a reverse format.

5 compare

This method compares 2 strings. Returns "0" if "string1" and "string2" are identical. Otherwise, it returns the posit downion of the 1st charactionioner thead wear does not fit.

6 copies

This method copies a string n number of times.

7 substr

This method gets a substring from a particular string.

8 pos

This method returns the posit downion of one string wislim one more.

9 delstr

This method deallowes a substring from wislim a string.

Rexx – Functions

The code in Rexx is normally divided into Functions and Subrawayines. Uperform functions helps in segregating the code into many kind of kind of more logical devices. Let’s look at these functions in detail.

Defining a Function

The syntax of a function declaration is as follows −

FunctionName: 
PARSE ARG arguement1, arguement2… arguementN 
Return value 

Where,

  • FunctionName − This is the name bumigned to the function.

  • PARSE ARG − These are keywords in Rexx which are used to mention thead wear parameters are being completeed onto the function.

  • arguement1, arguement2… arguementN − These are the arguments completeed to the function.

  • Return value − This is the value returned by the function.

The folloearng program is a easy example of how functions are used in Rexx.

/* Main program */ 
say add(5,6) 
exit 
add: 
PARSE ARG a,b 
return a + b 

The folloearng slimgs ought to be noted abaway the above program −

  • We are defining a function caldelivered add which accepts 2 parameters a and b.

  • The function uses the return statement to return the sum of a and b.

  • The exit statement has to be used to signify the end of the main program.

The awayput of the above program would be as follows −

11

Working with Arguments

In Rexx, appropriate now presently there are specific functions which can be made to work with arguments. Let’s look at a couple of such arguments.

arg

This method is used to return the number of arguments degreatd for the function.

Syntax

arg() 

Parameters − None

Return Value − This method returns the number of arguments degreatd for the function.

Example

/* Main program */ 
say add(5,6) 
exit 
add: 
PARSE ARG a,b 

say arg() 
return a + b 

Output − When we operate the above program we will get the folloearng result.

2 
11 

arg(index)

This method is used to return the value of the argument at the specific posit downion.

Syntax

arg(index)

Parameter

  • Index − Index posit downion of the argument to be returned.

Return Value − This method returns the value of the argument at the specific posit downion.

Example

/* Main program */ 
say add(5,6) 
exit 
add: 
PARSE ARG a,b 

say arg(1) 
return a + b 

Output − When we operate the above program we will get the folloearng result.

5 
11 

Recursive Functions

A recursive function or rawayine is one thead wear calls it iself. Any recursive function can be coded in a traditional non-recursive fashion (or iteratively), but occasionally recursion awayers a much better issue solution. Not all programming languages supinterface recursion; Rexx does.

Let’s see an example of the famous truthionorial program uperform recursive functions in Rexx.

/* Main program */ 
do n = 1 to 5 
say 'The truthionorial of' n 'is:' truthionorial( n ) 
end 
return  

/* Function to get truthionorial */ 
truthionorial : procedure 
n = arg(1) 
if n = 1 then 
return 1 
return n * truthionorial( n - 1 ) 

The awayput of the above program is as follows −

The truthionorial of 1 is: 1
The truthionorial of 2 is: 2 
The truthionorial of 3 is: 6 
The truthionorial of 3 is: 24 
The truthionorial of 3 is: 120 

Rexx – Stacks

The stack is occasionally caldelivered the external data queue, but we follow common usage and refer to it as the stack. It is a block of memory thead wear is logically external to Rexx. Instructions like push and queue place data into the stack, and instructions like draw and parse draw extractionion data from it. The queued built-in function reinterfaces how many kind of kind of items are in the stack.

Let’s consider a look at an example of a stack.

/* STACK: */
/* */ 
/* This program shows how to use the Rexx Stack as either a */ 

/* stack or a queue. */ 
do j = 1 to 3 
push ‘Stack: line #’ || j 

/* push 3 lines onto the stack */ 
end 
do j = 1 to queued() 

/* retrieve and display LIFO */ 
draw line 
say line 
end 
do j = 1 to 3 queue ‘Queue: line #’ || j 

/* queue 3 lines onto the stack */ 
end 
do queued() 

/* retrieve and display FIFO */ 
draw line 
say line 
end 
exit 0

The 1st do loop in the program places 3 lines of data onto the stack. It uses the push instruction to do this particular particular. We number the lines so thead wear when they are retrieved in the LIFO order their own order is apparent.

The items placed into the stack by the push instruction are retrieved in the LIFO order −

do j = 1 to 3 
push ‘Stack: line #’ || j /* push 3 lines onto the stack */ 
end

The next code block shows the use of the queued built-in function to discover the number of lines on the stack, as well as a loop to retrieve all the lines from the stack −

do j = 1 to queued()  /* retrieve and display LIFO */ 
draw line 
say line 
end

Since the 3 items were placed on the stack via push, they are retrieved in the LIFO order.

The awayput of the above program will be as follows.

STACK: LINE #3 
STACK: LINE #2 
STACK: LINE #1   

Rexx – File I/O

Rexx provides lots of methods when functioning with I/O. Rexx provides easier coursees to provide the folloearng functionalilinks for files.

  • Reading files
  • Writing to files
  • Seeing whether a file is a file or immediateory

The functions available in Rexx for File I/O are based on both line input and charactionioner input and we will be looking at the functions available for both in detail.

Let’s explore some of the file operations Rexx has to awayer. For the purposes of these examples, we are going to bumume thead wear appropriate now presently there is a file caldelivered NewFile.txt which contains the folloearng lines of text −

Example1

Example2

Example3

This file will be used for the read and write operations in the folloearng examples. Here we will speak abaway regarding how to read the contents on a file in various ways.

Reading the Contents of a File a Line at a Time

The general operations on files are carried away by uperform the methods available in the Rexx library it iself. The reading of files is the easyst of all operations in Rexx.

Let’s look at the function used to accomplish this particular particular.

linein

This method returns a line from the text file. The text file is the filename provided as the input parameter to the function.

Syntax

linein(filename) 

Parameter

  • filename − This is the name of the file from where the line needs to be read.

Return Value − This method returns one line of the file at a time.

Example

/* Main program */ 
line_str = linein(Example.txt) 
say line_str

The above code is reasonablely easy in the truthion thead wear the Example.txt file name is provided to the linein function. This function then reads a line of text and provides the result to the variable line_str.

Output − When we operate the above program we will get the folloearng result.

Example1

Reading the Contents of a File at One Time

In Rexx, reading all the contents of a file can be achieved with the help of the while statement. The while statement will read every line, one by one till the end of the file is reveryed.

An example on how this particular particular can be achieved is shown below.

/* Main program */ 
do while lines(Example.txt) > 0  
line_str = linein(Example.txt) 
say line_str 
end 

In the above program, the folloearng slimgs need to be noted −

  • The lines function reads the Example.txt file.

  • The while function is used to check if further lines exist in the Example.txt file.

  • For every line read from the file, the line_str variable holds the value of the current line. This is then sent to the console as awayput.

Output − When we operate the above program we will get the folloearng result.

Example1 
Example2 
Example3 

Writing Contents to a File

Just like reading of files, Rexx furthermore has the capability to write to files. Let’s look at the function which is used to accomplish this particular particular.

lineaway

This method writes a line to a file. The file to which the line needs to be composed to is provided as the parameter to the lineaway statement.

Syntax

lineaway(filename) 

Parameter

  • filename − This is the name of the file from where the line needs to be composed to.

Return Value − This method returns the status of the lineaway function. The value returned is 0 if the line was successcompallowey composed else the value of 1 will be returned.

Example

/* Main program */ 
away = lineaway(Example.txt,"Example4") 

Output − Whenever the above code is operate, the line “Example4” will be composed to the file Example.txt.

Rexx – Functions For Files

In this particular particular chapter, we will speak abaway regarding some of the other functions thead wear are available for files.

S.No. Functions for Files
1 Lines

This function returns either the value 1 or the number of lines left to read in an input stream. The filename is given as the input to the function.

2 stream

This function is used to check the status of a file. Sometimes it is required-coloured-coloured-coloured to check the status of a file before it is used. If the file is corrupt or not available, then no further operations can be performed on the file. So it develops more sense to 1st check the status of the file.

3 charin

This function is used to read one charactionioner at a time from a file. Sometimes programs require to read files charactionioner wise and hence this particular particular function can be used for this particular particular purpose.

4 chars

This function returns either 1 or the number of charactionioners left to read in the file it iself. The filename is mentioned as a parameter to the function.

5 charaway

This function is used to write one charactionioner at a time to a file. The filename is entered-coloured-coloured-coloured as a parameter to the function.

Rexx – Subrawayines

In any kind of kind of programming language, the entire program is broken into logical modules. This develops it easier to write code thead wear can be maintained easily. This is a fundamental requirement for any kind of kind of programming language.

In Rexx, modules can be composed uperform Subrawayines and functions. Let’s look at the subrawayines in detail.

Defining a Subrawayine

The syntax of a function declaration is as follows −

FunctionName: 
   Statement#1 
   Statement#2 
   …. 
   Statement#N

Where,

  • FunctionName − This is the name bumigned to the subrawayine.

  • Statement#1 .. Statement#N − These are the list of statements thead wear develop up the subrawayine.

The folloearng program is a easy example shoearng the use of subrawayines.

/* Main program */ 
call add 
exit 
add: 
a = 5 
b = 10 
c = a + b 
say c 

The folloearng slimgs ought to be noted abaway the above program −

  • We are defining a subrawayine caldelivered add.

  • The subrawayine does a easy add functionality.

  • The exit statement has to be used to signify the end of the main program.

The awayput of the above program would be as follows −

15

Working with Arguments

It is furthermore achievable to work with arguments in Rexx. The folloearng example shows how this particular particular can be achieved.

/* Main program */ 
call add 1,2 
exit 
add: 
PARSE ARG a,b 
c = a + b 
say c

The folloearng slimgs ought to be noted abaway the above program −

  • We are defining a subrawayine caldelivered add which considers on 2 parameters.

  • In the subrawayines, the 2 parameters are parsed uperform the PARSE and ARG keyword.

The awayput of the above program would be as follows −

3

Different Methods for Arguments

Let’s look at some other methods available for arguments.

arg

This method is used to return the number of arguments degreatd for the subrawayine.

Syntax

arg() 

Parameters − None

Return Value − This method returns the number of arguments degreatd for the subrawayine.

Example

/* Main program */ 
call add 1,2 
exit 
add: 
PARSE ARG a,b 

say arg() 
c = a + b 
say c 

When we operate the above program we will get the folloearng result.

2 
3 

arg(index)

This method is used to return the value of the argument at the specific posit downion.

Syntax

arg(index)

Parameters

  • Index − Index posit downion of the argument to be returned.

Return Value − This method returns the value of the argument at the specific posit downion.

Example

/* Main program */ 
call add 1,2 
exit 
add: 
PARSE ARG a,b 

say arg(1) 
c = a + b 
say c 

When we operate the above program we will get the folloearng result.

1 
3 

Rexx – Built-In Functions

Every programming language has some built-in functions thead wear help the programmer do some rawayine tasks. Rexx furthermore has a lot of built in functions.

Let’s look at all of these functions available in Rexx.

S.No. Functions available in Rexx
1 ADDRESS

This method returns the name of the environment in the which the Rexx commands are currently operatening in.

2 BEEP

This method produces a sound in the system at a particular frequency and duration.

3 DataType

This method returns the value of ‘NUM’ if the input is a valid number else it will return the value of ‘CHAR’. You can furthermore specify if you want to compare the input value to a NUM or CHAR value. In every case, the value returned will be either 1 or 0 depending on the result.

4 DATE

This method returns the local date in the folloearng format.

5 DIGITS

This method returns the current setting of NUMERIC DIGITS as degreatd in the current system.

6 ERRORTEXT

This method returns the Rexx error message bumociated with error number ‘errorno’. Plrelayve note thead wear the error number needs to be a value from 0 to 99. This is helpful in cases wherein your program returned an error code and you want to know whead wear the error code means.

7 FORM

This method returns the current setting of ‘NUMERIC FORM’ which is used to do maall of all of thematic calculations on the system.

8 TIME

This method returns the local time in the 24-hr clock format as shown in the folloearng program.

9 USERID

This method returns the current user id logged into the system.

10 XRANGE

This method returns the charactionioners in the range specified by the start and end charactionioner.

11 X2D

This method returns the decimal conversion of a hexstring value.

12 X2C

This method returns the charactionioner conversion of a hexstring value.

Rexx – System Commands

One of the biggest advantages in Rexx is the capability to develop re-usable scripts. Often in body organizations nowadays, having re-usable scripts is a big value add in saving time to do common repetitive tasks.

For example, technology teams in an IT body organization can have the need to have scripts which do common everyday tasks. These tasks can include interactionioning with the operating systems. These scripts can then be programmed to handle bad return codes or errors.

Rexx awayers a lot of system commands thead wear can be used to perform such repetitive tasks. Let’s look at some of the system commands available in Rexx.

dir

This is the normal immediateory listing command which is used in Windows.

Syntax

dir

Parameters

None

Return Value

This method returns the current immediateory listing on the system.

Example

/* Main program */ 
dir 

The awayput depends on the immediateory in the system.

The folloearng program is only an example.

Output

Volume in drive D is LENOVO 
Volume Serial Number is BAC9-9E3F  
Directory of D: 
04/06/2016  12:52 AM           268,205 100008676689.pdf 
10/20/2015  08:51 PM    <DIR>          data 
06/01/2016  10:23 AM                31 Example.txt 
10/28/2014  06:55 PM    <DIR>          Intel 
06/02/2016  11:15 AM                23 main.rexx 
12/22/2014  08:49 AM    <DIR>          PerfLogs  
12/13/2015  11:45 PM    <DIR>          Program Files 
12/24/2015  10:26 AM    <DIR>          Program Files (x86) 
07/17/2015  01:21 AM    <DIR>          Users 
12/23/2015  10:01 AM    <DIR>          Windows 
               3 File(s)        268,259 bytes 
               7 Dir(s)     202,567,680 bytes free 

Another example of the dir command is shown in the folloearng program. Only this particular particular time we are making use of the special rc variable. This variable is special in Rexx and gives you the status of the execution of system commands. If the value returned is 0, then thead wear means the command is executed successcompallowey. Else the error number will be given in the rc variable name.

Example

/* Main program */ 
dir 
if rc = 0 then 
   say 'The command executed successcompallowey' 
else 
   say 'The command faidelivered, The error code is =' rc 

When we operate the above program we will get the folloearng result.

Output

The command executed successcompallowey. 

Reimmediateion Commands

Rexx furthermore has the facility of uperform red-coloured-coloureimmediateion commands. The folloearng red-coloured-coloureimmediateion commands are available in Rexx.

  • < − This command is used to consider in the input which comes from a file.

  • > − This command is used to awayput the content to a file. If the file does exist, it will be over-composed.

  • >> − This is furthermore used to awayput the content to a file. But the awayput is added to the end of the file to preserve the existing content of the file.

Let’s look at an example of how we can use red-coloured-coloureimmediateion commands. In the folloearng example, we are uperform the sort command to sort a file caldelivered sortin.txt. The data from the file is sent to the sort command. The awayput of the sort command is then sent to the sortaway.txt file.

Example

/* Main program */ 
'sort <sortin.txt> sortaway.txt' 

Assume thead wear the file sortin.txt has the folloearng data.

Output

b 
c 
a

The file sortaway.txt will then have the folloearng data.

a 
b 
c 

The ADDRESS Function

This method is used to find away whead wear is the default environment used for the Input, Error and Output streams.

Syntax

ADDRESS(options) 

Parameters

  • Options for whead wear is the address of a particular system.

Return Value

This method returns the name of the environment for the Input, Error and Output streams.

Example

/* Main program */ 
say ADDRESS('I') 
say ADDRESS('O') 
say ADDRESS('E')

When we operate the above program we will get the folloearng result.

Output

INPUT NORMAL 
REPLACE NORMAL 
REPLACE NORMAL

Rexx – XML

XML is a interfaceable, open up source language thead wear allows programmers to develop applications thead wear can be read by other applications, regardless of the operating system and/or developmental language. This is one of the the majority of common languages used for exchanging data between applications.

Whead wear is XML?

The Extensible Markup Language XML is a markup language much like HTML or SGML. This is recommended by the World Wide Web Consortium and available as an open up standard. XML is extremely helpful for keeping track of small to medium amounts of data withaway requiring a SQL-based backbone.

For all our XML code examples, allow's use the folloearng easy XML file movies.xml for construction of the XML file and reading the file subsequently.

<collection shelf = "New Arrivals"> 
   <movie title = "Enemy Behind"> 
      <kind>War, Thriller</kind> 
      <format>DVD</format> 
      <yr>2003</yr> 
      <rating>PG</rating> 
      <stars>10</stars> 
      <description>Talk abaway a US-Japan battle</description> 
   </movie> 
   
   <movie title = "Transpreviouss"> 
      <kind>Anime, Science Fiction</kind> 
      <format>DVD</format> 
      <yr>1989</yr> 
      <rating>R</rating> 
      <stars>8</stars> 
      <description>A schientific fiction</description> 
   </movie> 
   
   <movie title = "Trigun"> 
      <kind>Anime, Action</kind> 
      <format>DVD</format> 
      <yr>1986</yr> 
      <rating>PG</rating> 
      <stars>10</stars> 
      <description>Vash the Stam pede!</description> 
   </movie> 
   
   <movie title = "Ishtar"> 
      <kind>Comedy</kind> 
      <format>VHS</format> 
      <yr>1987</yr> 
      <rating>PG</rating> 
      <stars>2</stars> 
      <description>Viewable bored-coloured-coloured-colouredom </description> 
   </movie> 
</collection>

Getting Started

By default, the xml functionality is not included in the Rexx interpreter. In order to work with XML in Rexx, the folloearng steps need to be followed.

Loading XML Functions

Once all the files in the above section have been downloaded and successcompallowey registered-coloured-coloured-coloured, the next step is to write the code to load the Rexx XML functions. This is done with the folloearng code.

rcc = rxfuncadd('XMLLoadFuncs', 'rexxxml', 'xmlloadfuncs') 

if rcc then do 
   say rxfuncerrmsg() 
   exit 1 
end 
call xmlloadfuncs

The folloearng slimgs can be noted abaway the above program −

  • The function rxfuncadd is used to load external libraries. The xmlloadfuncs function is used to load all the libraries in the rexxxml file into memory.

  • If the value of rcc<>0, then it would result in an error. For this particular particular , we can call the rxfuncerrmsg to give us more details on the error message.

  • We finally develop a call to xmlloadfuncs, so thead wear all xml related functionality can now be enabdelivered in the Rexx program.

Let’s look at the various methods available for XML in Rexx.

xmlVersion

This method returns the version of the XML and XSLT libraries used on the system.

Syntax

xmlVersion()

Parameters

None

Return Value

This method returns the version of the XML and XSLT libraries used on the system.

Example

rcc = rxfuncadd('XMLLoadFuncs', 'rexxxml', 'xmlloadfuncs') 

if rcc then do 
   say rxfuncerrmsg() 
   exit 1 
end 
call xmlloadfuncs 
say xmlVersion() 

When we operate above program we will get the folloearng result. This again depends on the version of the XML libraries being used on the system.

Output

1.0.0 20631 10126 

xmlParseXML

This function is used to parse the XML data sent to the function. The document tree is returned by the function.

Syntax

xmlParseXML(filename) 

Parameters

  • Filename − This is the name of the XML file which needs to be parsed.

Return Value

The document tree is returned by the function. Else returns 0, if appropriate now presently there is an error.

Example

rcc = rxfuncadd('XMLLoadFuncs', 'rexxxml', 'xmlloadfuncs') 

if rcc then do 
   say rxfuncerrmsg() 
   exit 1 
end 
call xmlloadfuncs 

say xmlVersion() 
sw = xmlParseXML('check.xml') 

Output

No general awayput.

xmlFindNode

This method evaluates the XPath expression completeed to it. This is used for parperform the document tree to result a nodeset which can be processed further.

Syntax

xmlParseXML(XPath,document) 

Parameters

  • XPath − This is the route of the node in the xml file.

  • document − This the XML document

Return Value

Evaluates XPath expression and returns result as a nodeset which can be used later on.

Example

rcc = rxfuncadd('XMLLoadFuncs', 'rexxxml', 'xmlloadfuncs') 

if rcc then do 
   say rxfuncerrmsg() 
   exit 1 
end 
call xmlloadfuncs

say xmlVersion() 
document = xmlParseXML('check.xml') 
nodeset = xmlFindNode('//movie', document) 
say xmlNodesetCount(nodeset)

When we operate above program we will get the folloearng result.

Output

4

The awayput shows the number of movie nodes in our xml list

xmlEvalExpression

The below method is used to Evaluate an XPath expression and return a string as a result.

Syntax

xmlParseXML(XPath,Node) 

Parameters

  • XPath − This is the route of the node in the xml file.

  • document − The specific node element.

Return Value

A string is returned based on the XPath expression sent to it.

Example

rcc = rxfuncadd('XMLLoadFuncs', 'rexxxml', 'xmlloadfuncs') 

if rcc then do 
   say rxfuncerrmsg() 
   exit 1 
end 
call xmlloadfuncs 

document = xmlParseXML('check.xml') 
nodeset = xmlFindNode('//movie', document) 
do j = 1 to xmlNodesetCount(nodeset) 
value = xmlEvalExpression('kind', xmlNodesetItem(nodeset, j)) 
say value 
end

When we operate above program we will get the folloearng result.

Output

War, Thriller 
Anime, Science Fiction 
Anime, Action 
Comedy 

Rexx – Regina

Regina is one more Rexx interpreter available to compile and operate Rexx programs. The awayicial sit downe for Regina is − www.regina-rexx.sourceforge.net/

Regina Rexx Interpreter

Some of the advantages of uperform Regina are as follows −

  • Regina can operate on any kind of kind of platform whether it be Windows, Linux or the Mac OS.

  • Regina works as per all available standards.

  • Regina has a big commdevicey folloearng and hence appropriate now presently there are a lot of forums and belowstanding material available for Regina.

  • Regina has a lot of tools available for writing and checking Rexx programs.

  • In Regina, you can operate commands which are not achievable in the default Rexx Interpreter. For example, if you include particular configuration settings, you can actionionually operate fundamental system level commands, which is not achievable in Rexx.

When you install Rexx via the installation documented in Chapter 2 – Rexx Environment, the Regina interpreter gets instaldelivered adurationy with it.

Now allow’s see some of the common methods available when uperform Regina. These functions are the extended functions which are not available via normal use.

To develop use of the extended functions, you need to include the folloearng line of code. This enables the use of Regina extended functions.

options arexx_bifs 

Secondly while operatening all Rexx programs, use the folloearng command.

regina main.rexx 

Where,

  • regina − This is the interpreter used for Rexx programs.

  • main.rexx − Your Rexx program

We will now speak abaway in detail the various functions of Regina Rexx Interpreter.

S.No. Functions of Regina Rexx Interpreter
1 b2c

This method is used to convert a binary value to a string value.

2 bitcomp

The method is used to compare 2 bit strings, bit by bit.

3 bittst

This method is used to indicate the state of the specified bit in the bit string.

4 find

This method is used to reresearch for the 1st occurrence of a string in one more string.

5 getenv

This method returns the value of an environment variable on the system.

6 getpid

This method is used to get the value of the current operatening process id.

7 hash

This method returns the hash attribute of a string as a decimal number. It furthermore updates the internal hash value of the string.

8 justify

This method is used to add justify or trim the value of a string based on the duration value.

9 putenv

This method is used to set the value of an environment variable.

10 immediateory

This method gets the value of the current immediateory on the system.

11 chdir

This method modifys the value of the current functioning immediateory on the system.

12 randu

This method returns a pseudo-random number between 0 and 1.

Rexx – Parperform

One of the the majority of powerful features of Rexx is it is capability to parse text values. You probably will not see this particular particular in any kind of kind of other programming languages.

The general format of the parse statement is as follows −

Syntax

PARSE {UPPER|LOWER|CASELESS} source {template} 

Where,

  • UPPER − The source is converted to upper case before parperform.

  • LOWER − The source is converted to lower case before parperform.

  • CASELESS − When this particular particular parameter is completeed, the caperform is ignored-coloured-coloured-coloured.

  • source − This is the source which needs to be parsed. There are many kind of kind of options available for this particular particular and can be any kind of kind of one of the folloearng −

    • ARG − The arguments for the program or procedure can be used as the source.

    • LINEIN − The next line input can be used as the source.

    • SOURCE − The source information of the program can be used as the source.

    • VAR name − The value of a variable name can be used as the source.

  • template − This parameter specifies how to parse the source. There are many kind of kind of options available for this particular particular. Some of all of all of them are mentioned below.

    • variable name − This is the value bumigned to the variable.

    • literal string − A literal string which can be used a pattern to split the preventerateg.

    • # − An absolute charactionioner posit downion wislim the source it iself. So if you specify a value of 5, the 5th charactionioner will be used.

    • +# − A relative charactionioner posit downion wislim the source it iself. So if you specify a value of 5, the 5th charactionioner will be used relatively.

Let’s look at a easy example of how parperform can be accomplished in Rexx.

Example

/* Main program */ 
parse value 'This is a Tutorial' with word1 word2 word3 word4 
say "'"word1"'" 
say "'"word2"'" 
say "'"word3"'" 
say "'"word4"'" 

The above program parses the words in the phrase. When a value consists of words thead wear are separated by only one space, and appropriate now presently there are no leading or trailing spaces, the value is easy to parse into a known number of words as follows.

The parse function is used in Rexx to consider a string value and then break all of all of them down into words. In the above example, the words are then split and then stored-coloured-coloured-coloured in the word variables.

The awayput of the above program would be as follows −

'This' 
'is' 
'a' 
'Tutorial' 

Another example of parperform is shown in the folloearng program. This time we are uperform a while clause to do the parperform.

Example

/* Main program */ 
phrase = 'This is a Tutorial' 

do while phrase <> '' 
   parse var phrase word phrase 
   say "'"word"'" 
   end 

The above program will give the folloearng awayput −

'This' 
'is' 
'a' 
'Tutorial' 

Posit downional Parperform

Rexx furthermore allows one to work with posit downional parperform. Let’s see an example of how we can achieve posit downional parperform with the parse statement.

Example

/* Main program */ 
checkString = "Doe       John M.   03/03/78  Mumbai              India"; 
parse var checkString name1 11 name2 21 birthday 31 town 51 councheck 
say name1 
say name2 
say birthday 
say town 
say councheck

From the above example, you can note thead wear adurationy with the variable name, we are furthermore specifying where the string ought to end. So for name1, we ought to end by the 11th charactionioner and then starting parperform name2.

The awayput of the above program will be as follows −

Doe 
John M. 
03/03/78 
Mumbai 
India

You can furthermore use relative posit downional parperform in this particular particular case.

Example

/* Main program */ 
checkString = "Doe       John M.   03/03/78  Mumbai              India"; 
parse var checkString name1 +10 name2 +10 birthday +10 town +20 councheck 
say name1 
say name2 
say birthday 
say town 
say councheck

The awayput of the above program will be as shown below.

Doe 
John M. 
03/03/78 
Mumbai 
India 

Rexx – Signals

In Rexx, the signal instruction is used generally for 2 purposes, which are −

  • One is to transfer manage to one more part of the program. This is normally like the go-to label which is used in other programming languages.

  • The other is to go to a specific trap label.

If the signal command is used in any kind of kind of of the folloearng instruction commands, the pending manage structures will automatically be deactionionivated.

  • if … then … else …

  • do … end

  • do i = 1 to n … end [and similar do loops]

  • select when … then … …etc. otherwise … end

The general syntax of the signal statement is shown as follows −

Syntax

signal labelName  
   
signal [ VALUE ] labelExpression 

Let’s look at an example of how to use the signal statement.

Example

/* Main program */ 
n = 100.45 

if  datakind( n, wholenumber ) then 
   signal msg 
   say 'This is a whole number' 
   return 0 
msg : 
   say 'This is an inappropriate number'

The awayput of the above program will be as shown below.

Output

This is an inappropriate number.

If you modify the value of the variable n to a whole number as shown in the folloearng program −

/* Main program */ 
n = 100 

if  datakind( n, wholenumber ) then 
   signal msg 
   say ' This is a whole number ' 
   return 0 
msg : 
   say ' This is an inappropriate number ' 

You will get the folloearng awayput −

This is a whole number

One can furthermore transfer to the value of the label as shown in the folloearng program −

/* Main program */ 
n = 1 

if  datakind( n, wholenumber ) then 
   signal msg 

if n < 1 | n > 3 then 
   signal msg  
   signal value n 
   3 : say 'This is the number 3' 
   2 : say ' This is the number 2' 
   1 : say ' This is the number 1' 
   return n 
msg : 
   say ' This is an inappropriate number ' 
   exit 99 

The awayput of the above program will be shown as follows −

This is the number 1

Trap Label Transfer Activation / Deactionionivation

As we have mentioned earlayr, the signal instruction can furthermore be used to transfer manage to a trap label.

The general syntax of the Trap label transfer is given as follows −

Syntax

signal ON conditionName [ NAME Label ] 
  
signal OFF conditionName

Where,

  • conditionName − This is the condition for which the signal ought to be either be turned on or away.

  • Label − The optional label to which the program ought to be diverted to.

Let’s see an example of uperform a trap label transfer.

Example

/* Main program */ 
signal on error 
signal on failure 
signal on syntax 
signal on novalue 
beep(1) 
signal away error 
signal away failure 
signal away syntax 
signal away novalue 
exit 0 
error: failure: syntax: novalue: 
say 'An error has occured-coloured-coloured-coloured' 

In the above example, we 1st turn the error signals on. We then add a statement which will result in an error. We then have the error trap label to display a custom error message.

The awayput of the above program will be as shown follows −

An error has occurred-coloured-coloured-coloured.

Rexx – Debugging

Debugging is an iminterfaceant feature in any kind of kind of programming language. It helps the developer to diagnose errors, find the underlying cause and then resolve all of all of them accordingly. In Rexx, the trace utility is used for debugging. The trace instruction can be implemented in 2 ways, one is the batch mode and the other is the interactionionive mode. Let’s look at how to implement both options.

Trace in Batch Mode

The trace command is used to give a detaidelivered level of every Rexx command which is executed.

The general syntax of the trace statement is shown as follows −

Syntax

trace [setting] 

Where the setting can be any kind of kind ofone of the folloearng options −

  • A − Traces all the commands.

  • C − Only traces the host commands which are sent to the operating system.

  • E − Only traces the host commands which are sent to the operating system which have resulted in an error.

  • F − Only traces the host commands which are sent to the operating system which have resulted in a failure.

  • I − This provides an intermediate level tracing of Rexx commands.

  • L − This option is if you want to label the tracing as it happens.

  • N − This is the default option in which no tracing happens.

Let’s consider a look at an example of the trace command.

Example

/* Main program */ 
trace A 

/* Main program */ 
n = 100.45 if datakind( n, wholenumber ) then signal msg 

say 'This is a whole number' 
return 0 

msg : 
   say ' This is an inappropriate number ' 

The awayput of the above program will be as follows −

5 *-* n = 100.45 if datakind( n, wholenumber ) then signal msg
   7 *-* say 'This is a whole number
This is a whole number                                                   
   8 *-* return 0

From the awayput, you can see thead wear an additional trace was added to the awayput of the program. The folloearng slimgs can be noted abaway the awayput −

  • The line number adurationy with the statement executed is added to the trace awayput.

  • Each line thead wear gets executed is shown in the trace awayput.

Trace Function

Trace can furthermore be enabdelivered with the help of the trace function. The general syntax and example are shown below.

Syntax

trace() 

The above function returns the current trace level.

Parameters

None

Return Value

The above function gives the current trace level.

Example

/* Main program */ 
say trace() 

/* Main program */ 
n = 100.45 if datakind( n, wholenumber ) then signal msg 

say 'This is a whole number' 
return 0 
msg : 

say 'This is an inappropriate number ' 

The awayput of the above program will be as follows.

N 
This is an inappropriate number 

The 1st line of N denotes thead wear the trace is set to Normal.

Setting Trace Value

The trace level can be set with the trace function. The general syntax and example are shown below.

Syntax

trace(journey_level) 

Parameters

  • trace_level − This is similar to the options available for setting the trace level.

Return Value

The above function gives the current trace level.

Example

/* Main program */ 
say trace() 
current_trace = trace('A') 
say current_trace 

/* Main program */ 
n = 100.45 if datakind( n, wholenumber ) then 
signal msg say 'This is a whole number' 
return 0 
msg : 
say ' This is an inappropriate number ' 

The awayput of the above program will be as follows −

N 
   4 *-* say current_trace 
N 
   6 *-* n = 100.45 
   7 *-* if  datakind( n, wholenumber ) then 
   8 *-* signal msg 
   12 *-* say 'This is an inappropriate number' 
'This is an inappropriate number' 

Interactionionive Tracing

Interactionionive tracing is wherein, tracing is carried away as the program operates. Just like in an IDE such as Visual Studio for .Net, in which you can add breakstages and see how every statement executes, similarly here furthermore you can see the program as every code line operates.

The general syntax is as follows −

Syntax

trace ?options 

Where, options are the exactionion exaction same for the trace command as shown below.

  • A − Traces all the commands

  • C − Only traces the host commands which are sent to the operating system.

  • E − Only traces the host commands which are sent to the operating system which have resulted in an error.

  • F − Only traces the host commands which are sent to the operating system which have resulted in a failure.

  • I − This provides an intermediate level tracing of Rexx commands.

  • L − This option is if you want to label the tracing as it happens.

  • N − This is the default option in which no tracing happens.

Let’s consider a look at an example of implementing actionionive tracing.

Example

/* Main program */ 
trace ?A

/* Main program */ 
n = 100.45 if datakind( n, wholenumber ) then 
signal msg 

say 'This is a whole number' 
return 0 
msg : say 'This is an inappropriate number' 

The awayput of the above program will be as shown in the folloearng program. The trace will end at every line of code; then you need to press the Enter button to move onto the next line of code.

   4 *-* n=100.45 
      +++ Interactionionive trace. "Trace Off" to end debug. ENTER to continue.  
   5 *-* if  datakind( n, wholenumber ) then  
   6 *-* signal msg 
   10 *-* say 'Inappropriate number , ought to be a whole number' 
Inappropriate number , ought to be a whole number

Rexx – Error Handling

Rexx has the capability to furthermore work on Error handling as in other programming languages.

The folloearng are some of the various error conditions thead wear are seen in Rexx.

  • ERROR − This actionionually is raised whenever a command which is sent to the operating system results in an error.

  • FAILURE − This actionionually is raised whenever a command which is sent to the operating system results in a failure.

  • HALT − This is normally raised whenever an operation is dependent on one more operation. An example is if an I/O operation is being halted for any kind of kind of reason.

  • NOVALUE − This actionionuallyt is raised when a value has not been bumigned to a variable.

  • NOTREADY − This is raised by any kind of kind of I/O device which is not ready to accept any kind of kind of operation.

  • SYNTAX − This actionionuallyt is raised if appropriate now presently there is any kind of kind of syntax error in the code.

  • LOSTDIGITS − This actionionuallyt is raised when an arithmetic operation results in a loss of digit is during the operation.

Trapping Errors

Errors are trapped with the help of the signal command. Let’s consider a look at the syntax and an example of this particular particular.

Syntax

signal on [Errorcondition]

Where,

  • Errorcondition − This is the error condition which is given above.

Example

Let’s consider a look at an example on this particular particular.

/* Main program */ 
signal on error 
signal on failure 
signal on syntax 
signal on novalue beep(1) 
signal away error 
signal away failure
signal away syntax 
signal away novalue 
exit 0 
error: failure: syntax: novalue: 
say 'An error has occured-coloured-coloured-coloured'

In the above example, we 1st turn the error signals on. We then add a statement which will result in an error. We then have the error trap label to display a custom error message.

The awayput of the above program will be as shown below.

An error has occurred-coloured-coloured-coloured.

An example of error codes is shown in the folloearng program.

/* Main program */ 
signal on error 
signal on failure 
signal on syntax 
signal on novalue beep(1) 
exit 0 
error: failure: syntax: novalue: 

say 'An error has occured-coloured-coloured-coloured' 
say rc 
say sigl 

The awayput of the above program will be as shown below.

An error has occured-coloured-coloured-coloured 
40 
6

Rexx – Object Oriented

When you install ooRexx as per the environment chapter, you will furthermore have the capability to work with coursees and objects. Plrelayve note thead wear all of the folloearng code needs to be operate in the ooRexx interpreter. The normal Rexx interpreter will not be able to operate this particular particular object oriented code.

Clbum and Method Declarations

A course is degreatd with the folloearng Syntax declaration.

Syntax

::course coursename 

where coursename is the name given to the course.

A method in a course is degreatd with the folloearng Syntax declaration.

Syntax

::method methodname 

Where methodname is the name given to the method.

A house in a course is degreatd with the below Syntax declaration.

Syntax

::attribute housename 

Where housename is the name given to the house.

Example

The folloearng is an example of a course in Rexx.

::course student 
::attribute StudentID 
::attribute StudentName 

The folloearng stages need to be noted abaway the above program.

  • The name of the course is student.
  • The course has 2 properlinks, StudentID and StudentName.

Getter and Setter Methods

The Getter and Setter methods are used to automatically set and get the values of the properlinks. In Rexx, when you declare a house with the attribute keyword, the getter and setter methods are already put in place.

Example

::course student 
::attribute StudentID 
::attribute StudentName 

In the above example, appropriate now presently there would be Getter and Setter methods for StudentId and StudentName.

An example of how they can be used is shown in the folloearng program.

/* Main program */ 
value = .student~brand brand new 
value~StudentID = 1 
value~StudentName = 'Joe' 
say value~StudentID 
say value~StudentName 

exit 0 
::course student 
::attribute StudentID 
::attribute StudentName 

The awayput of the above program will be as shown below.

1 
Joe 

Instance Methods

Objects can be developd from the course via the ~brand brand new operator. A method from the course can be caldelivered in the folloearng way.

Object~methodname 

Where methodname is the method which needs to be invoked from the course.

Example

The folloearng example shows how an object can be developd from a course and the respective method invoked.

/* Main program */ 
value = .student~brand brand new 
value~StudentID = 1 
value~StudentName = 'Joe' 
value~Marks1 = 10 
value~Marks2 = 20 
value~Marks3 = 30 
compallowe = value~Total(value~Marks1,value~Marks2,value~Marks3) 
say compallowe 

exit 0 
::course student 
::attribute StudentID 
::attribute StudentName 
::attribute Marks1 
::attribute Marks2 
::attribute Marks3 
::method 'Total' 
use arg a,b,c 
return (ABS(a) + ABS(b) + ABS(c)) 

The awayput of the above program will be as shown below.

60 

Creating Multiple Objects

One can furthermore develop multiple objects of a course. The folloearng example will show how this particular particular can be achieved.

In here we are creating 3 objects (st, st1 and st2) and calling their own instance members and instance methods accordingly.

Let’s consider a look at an example of how multiple objects can be developd.

Example

/* Main program */ 
st = .student~brand brand new 
st~StudentID = 1 
st~StudentName = 'Joe' 
st~Marks1 = 10 
st~Marks2 = 20 
st~Marks3 = 30 
compallowe = st~Total(st~Marks1,st~Marks2,st~Marks3) 
say compallowe  

st1  =  .student~brand brand new 
st1~StudentID = 2 
st1~StudentName = 'John' 
st1~Marks1 = 10 
st1~Marks2 = 20 
st1~Marks3 = 40 
compallowe = st1~Total(st1~Marks1,st1~Marks2,st1~Marks3) 
say compallowe  

st2  =  .student~brand brand new 
st2~StudentID = 3 
st2~StudentName = 'Mark' 
st2~Marks1 = 10 
st2~Marks2 = 20 
st2~Marks3 = 30 
compallowe = st2~Total(st2~Marks1,st2~Marks2,st2~Marks3) 
say compallowe  

exit 0 
::course student 
::attribute StudentID 
::attribute StudentName 
::attribute Marks1 
::attribute Marks2 
::attribute Marks3 
::method 'Total' 
use arg a,b,c 
return (ABS(a) + ABS(b) + ABS(c)) 

The awayput of the above program will be as shown below.

60 
70 
80 

Inheritance

Inheritance can be degreatd as the process where one course acquires the properlinks (methods and fields) of one more. With the use of inheritance, the information is made manageable in a hierarchical order.

The course which inherit is the properlinks of other is known as subcourse (derived course, kid course) and the course in whose properlinks are inherited is known as supercourse (base course, parent course).

Let’s see an example of inheritance in Rexx. In the folloearng example we are creating a course caldelivered Person. From appropriate now presently there we use the subcourse keyword to develop the Student course as a sub-course of Person.

Example

/* Main program */ 
st = .student~brand brand new 
st~StudentID = 1 
st~StudentName = 'Joe' 
st~Marks1 = 10 
st~Marks2 = 20 
st~Marks3 = 30 
say st~Total(st~Marks1,st~Marks2,st~Marks3)  

exit 0 
::course Person 
::course student subcourse Person 
::attribute StudentID 
::attribute StudentName 
::attribute Marks1 
::attribute Marks2 
::attribute Marks3 
::method 'Total' 
use arg a,b,c 
return (ABS(a) + ABS(b) + ABS(c)) 

The awayput of the above program will be as shown below.

60

Rexx – Portcapability

Portcapability is an iminterfaceant aspect in any kind of kind of programming language. As one knows, Rexx is available in a variety of operating systems such as Windows and Linux. So it need to be ensured-coloured-coloured-coloured thead wear when one develops a program on the Windows platform, thead wear it has the necessary precautions considern if the exactionion exaction same programs operates on a Linux platform.

Rexx has the capability to operate system level commands. There are commands which can be used to belowstand whead wear is the operating system on which it is operatening on. Based on the awayput it can then consider the appropriate actionionions to see whead wear are the commands thead wear can be operate on this particular particular operating system.

Example

The folloearng example shows how the parse functions are used to get the details of the operating system on which the program is operatening.

/* Main program */ 
parse version language level date month yr. 
parse source system invocation filename. 
language = translate(language) 

if pos('REGINA',language) = 0 then 
   say 'Error , the default interpreter is not Regina' language 
   say 'The Interpreter version/relrelayve date is:' date month yr 
   say 'The Language level is: ' level say 'The Operating System is'  

   select 
when system = 'WIN32' then 
   'ver'
when system = 'UNIX' | system = 'LINUX' then 
   'uname -a' 
   otherwise 
   say 'Unknown System:' system 
end 
if rc <> 0 then 
   say 'Error :' rc 

The awayput will vary depending on operating system. A sample awayput is given below.

The Interpreter version/relrelayve date: 5 Apr 2015 
The Language level is:  5.00 
The Operating System is 
Unknown System: WIN64 
Bad return code: RC 

Rexx – Extended Functions

Rexx provides lots of extended functions thead wear gives a wide variety of functionality, the majority of of all of all of them which allow you to interactionion with the Operating System. Let’s look at some of all of all of them in detail as exordinaryed below.

S.No. Extended Functions
1 b2c

This function converts a binary value to a string value.

2 bitclr

This function is used to toggle the specified bit in the binary string to 0.

3 bitcomp

This function is used to compare 2 binary strings starting with bit 0.

4 bufkind

This function is used to display the contents of the stack which is normally used in debugging purposes.

5 crypt

This function is used to encrypt a string.

6 fork

This function is used to spawn a brand brand new kid process on the system.

7 getpid

This function gets the id of the current operatening process.

8 hash

This function returns the hash value of a string.

Rexx – Instructions

Rexx provides lots of instructions thead wear gives a wide variety of functionality, the majority of of all of all of them which allow you to interactionion with the Operating System. Let’s look at some of all of all of them in detail.

S.No. Rexx Instructions
1 address

This function is used to display the current command environment.

2 drop

This function is used to unbumign a variable.

3 interpret

Interprets or executes the degreatd instruction.

4 nop

This function means to perform no operation. This command is normally used in if statements.

5 Pull

This is used to draw input from the stack or from the default stream.

6 push

This is used to push a value onto the Rexx stack.

Rexx – Implementations

The Rexx language has a lot of various implementations as we have already seen in the previous chapters. Each implementation has it is own functionality. Let’s look at the various implementations available for Rexx.

OoRexx

This is the object oriented version of Rexx. By default, the Rexx fundamental implementation is all based on procedures. But with ooRexx you can awayer greater flexibility by having an Object oriented approach to Rexx. By uperform ooRexx you can have much better re-use through creating re-usable coursees and objects.

The folloearng program is an example of a easy Rexx program which can be operate with the ooRexx implementer.

Example

/* Main program */ 
say ‘hello’ 

To operate this particular particular program, operate the folloearng command.

rexx main.rexx 

When you operate the above command, you will get the folloearng awayput.

hello

Netrexx

This is for all Java based developers as it provides a Java based alternative for the Rexx language. So all of the objects are based on the Java Object Model. The advantage of this particular particular framework is thead wear since Java is a widely popular language it becomes easier for developers to use this particular particular framework. So in this particular particular implementation, the Rexx code is converted to a Java program which can then be operate on any kind of kind of Java virtual machine.

The folloearng code is an example of a NetRexx program.

Create a file caldelivered main.nrx and place the folloearng code in the file.

/* Main program */ 
say ‘hello’

To compile the code operate the folloearng command −

NetRexxC main.nrx 

You will then get the folloearng awayput. NetRexxC is the compiler which converts the Rexx program to it is java equivalent.

java -cp ";;G:NetRexx-3.04GAlibNetRexxF.jar;." 
-Dnrx.compiler = ecj org.netrexx.process.NetRexxC  main.nrx 
NetRexx interfaceable processor 3.04 GA construct 4-20150630-1657 
Copyappropriate (c) RexxLA, 2011,2015.   All appropriates reserved. 
Parts Copyappropriate (c) IBM Corporation, 1995,2008. 
Program main.nrx 
Compilation of 'main.nrx' successful

You can now operate your java program uperform the folloearng java command.

java main 

When you operate the above command, you will get the folloearng awayput.

Hello

Brexx

This is a lightweight implementation of Rexx. This is a lighter package than the standard Rexx implementer. But it still has the compallowe functionality of Rexx.

The folloearng code is an example of a BRexx program.

/* Main program */ 
say ‘hello’

To operate the program, operate the folloearng command.

rexx32 main.rexx

When you operate the above command, you will get the folloearng awayput.

hello

Rexx – Netrexx

NetRexx is the java implementation of Rexx. In NetRexx, the implementer is used to convert the Rexx program to a java program which can then be operate on any kind of kind of Java virtual machine.

Setting up NetRexx

The 1st step in NetRexx is to set it up on the local machine. To do this particular particular, one needs to perform the folloearng steps −

Step 1 − Go to the NetRexx download sit downe − /index.php?s=httpwwwnetrexxorgdownloadsnsp

Netrexx

Download the NetRexx.3.04.GA file.

Step 2 − Ensure thead wear java is instaldelivered and operatening on your system. You can verify thead wear java is operatening by uperform the java–version command.

An example of the awayput is shown below.

H:>java -version 
java version "1.7.0_79" 
Java(TM) SE Runtime Environment (construct 1.7.0_79-b15) 
Java HotSpot(TM) Claynt VM (construct 24.79-b02, mixed mode, sharing) 

Step 3 − Unzip the contents of the Netrexx zipped file. Copy the files from the NetRexx3.04GAlib folder to your java installation/lib/etc folder.

Step 4 − Add the NetRexx-3.04GAbin route to the route variable on the system.

Running the First NetRexx Program

Create a file caldelivered main.nrx and place the folloearng code in the file.

/* Main program */ 
say ‘hello’ 

To compile the code operate the folloearng command.

NetRexxC main.nrx 

You will then get the folloearng awayput. NetRexxC is the compiler which converts the rexx program to it is java equivalent.

java -cp ";;G:NetRexx-3.04GAlibNetRexxF.jar;." 
-Dnrx.compiler = ecj org.netrexx.process.NetRexxC  main.nrx 
NetRexx interfaceable processor 3.04 GA construct 4-20150630-1657 
Copyappropriate (c) RexxLA, 2011,2015.   All appropriates reserved. 
Parts Copyappropriate (c) IBM Corporation, 1995,2008. 
Program main.nrx 
Compilation of 'main.nrx' successful

You can now operate your java program uperform the folloearng java command.

java main 

When you operate the above command, you will get the folloearng awayput.

Hello

Let us now speak abaway some of the special aspects of the Netrexx library.

Indexed Strings

In NetRexx, strings can become the indexes to arrays. An example is shown below.

Example

/* Main program */ 
value = 'unknown' 
value['a'] = 'b' 
c = 'a' 
say value[c] 

When we operate the above program, we will get the folloearng result.

Output

b

Multiple Indexes

In NetRexx, you can have multiple indexes for arrays. An example is shown below.

Example

/* Main program */ 
value = 'null' 
value['a', 'b'] = 1 
say value['a', 'b']

When we operate the above program we will get the folloearng result.

Output

1

S.No. Command & Description
1 ask Command

This command is used to read a line from the default input stream.

2 digit is Command

This command is used to display the current value of the digit is’ value.

3 form Command

This command is used to display the current value of the form value.

4 duration Command

This command is used to display the duration of a string value.

5 version Command

This command is used to return the current version of NetRexx being used.

6 trace Command

This command is used to return the current trace setting being used by NetRexx.

Rexx – Brexx

BRexx is a lighter weight implementation of Rexx. It still has a lot of functionality to awayer as part of the Rexx implementation.

Setting up BRexx

The 1st step in BRexx is to set it up on the local machine. To do this particular particular, one needs to perform the folloearng steps −

Step 1 − Go to the BRexx download sit downe − /index.php?s=httpftpgwdgdepublanguagesrexxbrexxhtmlrxhtml

BRexx

Go to the downloads section and download the product.

Step 2 − Unzip the contents of the Brexx zipped file.

Step 3 − Add the BRexxbin route to the route variable on the system.

Step 4 − Create a brand brand new variable caldelivered RXLIB and stage it to the lib folder in the Brexx folder.

Running the First BRexx Program

Create a file caldelivered main.rexx and place the folloearng code in the file.

/* Main program */ 
say ‘hello’ 

To operate the program, operate the folloearng command.

rexx32 main.rexx 

When you operate the above command, you will get the folloearng awayput.

hello

Let us now speak abaway some of the the majority of commonly used functions available in the BRexx library.

S.No. Functions available in the BRexx Library
1 acos Command

This command is used to get the arc-cosine conversion of lots.

2 cos Command

This command is used to get the cosine conversion of lots.

3 sin Command

This command is used to get the sine conversion of lots.

4 asin Command

This command is used to get the arc-sine conversion of lots.

5 tan Command

This command is used to get the tangent conversion of lots.

6 atan Command

This command is used to get the arc-tangent conversion of lots.

7 mkdir Command

This command is used to develop a immediateory in the current functioning immediateory.

8 rmdir Command

This command is used to remove a immediateory in the current functioning immediateory.

9 dir Command

This command is used to return the entire immediateory listing.

Rexx – Databases

Rexx has the capability to work with a variety of databases which are listed below.

  • HSQLDB
  • Oracle
  • SQL Server
  • MySQL
  • MongoDB

All the information for Rexx databases can be found once you click on the folloearng link − /index.php?s=httprexxsqlsourceforgenet

Databases

In our example, we are going to use MySQL DB as a sample. So the 1st step is to ensure to download the required-coloured-coloured-coloured drivers from the Rexx SQL sit downe so thead wear Rexx programs can work with SQL accordingly. So follow the subsequent steps to ensure thead wear Rexx programs can work with MySQL databases.

Step 1 − Go to the folloearng drivers download page from the Rexx sit downe − /index.php?s=httpssourceforgenetprojectsrexxsqlfilesrexxsql26

Step 2 − Download the MYSQL drivers – rxsql26B3_my_w32_ooRexx

Step 3 − Unzip the contents to the local machine.

Step 4 − Add the route of the unzipped folder to the route variable on your machine.

For all the subsequent examples, develop sure of the folloearng stageers are in place −

  • You have developd a database TESTDB.

  • You have developd a table EMPLOYEE in TESTDB.

  • This table has fields FIRST_NAME, LAST_NAME, AGE, SEX and INCOME.

  • User ID "checkuser" and completeword "check123" are set to access TESTDB.

  • Ensure you have downloaded the mysql jar file and added the file to your courseroute.

  • You have gone through MySQL tutorial

Database Connection

To establish a database interconnection, you 1st need to the Rexxsql DLL and then use the SQLConnect function to establish a interconnection to the database. The syntax and example of how this particular particular can be achieved is given below.

Syntax

SQLConnect(cname,username,completeword,dbname) 

Parameters

  • cname − This is the name to give to the interconnection.

  • username − The user name to connect to the database

  • completeword − The completeword to connect to the database

  • dbname − The database schema to connect to.

Return Value

A value equal to 0 will mean thead wear the database interconnection is successful.

Example

/* Main program */ 
Call RxFuncAdd 'SQLLoadFuncs', 'rexxsql', 'SQLLoadFuncs' 
Call SQLLoadFuncs 
say SQLConnect(c1,' checkuser ',' check123','checkdb')

The awayput of the above program would be as shown below.

0

Creating a Database Table

The next step after connecting to the database is to develop the tables in our database. The folloearng example shows how to develop a table in the database uperform Rexx. All of the commands in Rexx SQL are executed by uperform the SQLCommand function.

Syntax

SQLConnect(sname,statement)

Parameters

  • sname − This is the name to give to the statement to execute.

  • statement − This is the statement which needs to be executed against the database.

Return Value

A value equal to 0 will mean thead wear the command was successful.

Example

/* Main program */ 
Call RxFuncAdd 'SQLLoadFuncs', 'rexxsql', 'SQLLoadFuncs' 
Call SQLLoadFuncs 

if SQLConnect(c1,'checkuser','check123','checkdb') == 0 then say 'Connect Succedded' 
if SQLCommand(u1,"use checkdb") == 0 then say 'Changed database to checkdb' 
sqlstr = 'develop table employee (1st_name char(20) not null, final_name 
   char(20),age int, intimacy   
   char(1), income float)' 

if SQLCommand(c2,sqlstr) == 0 then say 'Employee table developd'

The awayput of the above program would be as shown below.

Connect Succedded 
Changed database to checkdb 
Employee table developd 

Operations on a Database Table

The folloearng kinds of operations are the majority of commonly performed on a database table.

S.No. Operation & Description
1 Insert Operation

It is required-coloured-coloured-coloured when you want to develop your records into a database table.

2 Read Operation

A READ Operation on any kind of kind of database means to fetch some helpful information from the database.

3 Update Operation

The UPDATE Operation on any kind of kind of database means to update one or more records, which are already available in the database.

4 Deallowe Operation

The DELETE operation is required-coloured-coloured-coloured when you want to deallowe some records from your database.

5 Cloperform a Connection

The folloearng command can be used to shut a interconnection to the database.

Performing Transactionionion

Transactionionions are a mechanism thead wear ensures data consistency. Transactionionions have the folloearng four properlinks −

  • Atomicity − Either a transactionionion compallowes or noslimg happens at all.

  • Consistency − A transactionionion must start in a consistent state and keep the system in a consistent state.

  • Isolation − Intermediate results of a transactionionion are not noticeable awaypart the current transactionionion.

  • Durcapability − Once a transactionionion was committed, the effects are persistent, actionionually after a system failure.

Here is a easy example of how to implement transactionionions.

Example

/* Main program */ 
Call RxFuncAdd 'SQLLoadFuncs', 'rexxsql', 'SQLLoadFuncs' 
Call SQLLoadFuncs 

if SQLConnect(c1,'checkuser','check123','checkdb') == 0 then say 'Connect Succedded' 
if SQLCommand(u1,"use checkdb") == 0 then say 'Changed database to checkdb' 
   sqlstr = "DELETE FROM EMPLOYEE WHERE AGE > 20" 

if SQLCommand(c2,sqlstr) == 0 then 
if sqlcommit() == 0 then say committed

The awayput of the above program would be as shown below.

Connect Succedded 
Changed database to checkdb 
COMMITTED

Commit Operation

The commit operation is whead wear tells the database to proceed amind with the operation and finalize all modifys to the database. In our above example, this particular particular is achieved by the folloearng command.

Sqlcommit() 

Rollback Operation

If you are not satisfied with one or more of the modifys and you want to revert back those modifys compallowely, then use rollback method. In our above example, this particular particular is achieved by the folloearng command.

SqlRollback() 

Rexx – Handheld & Embedded Programming

Handheld devices have come a durationy way and Rexx has a lot of ways in which it can operate on these devices. Rexx has supinterface for Pocket PC’s, Palm devices, PDA’s and other smart phone devices. The advantage of Rexx to work on these platforms is thead wear Rexx is very a small weight programming system which just operates in the span of a couple of kilobytes. Hence it becomes easier to operate Rexx programs on these devices.

Rexx on handheld devices can operate in the folloearng modes −

  • The 1st mode is the native node where it operates immediately on the operating system it iself. The advantage on operatening in this particular particular mode is thead wear it is faster since it operates immediately away the operating system.

  • The next mode is on top of the DOS or emulator program on top of the hand held device. The advantage of this particular particular mode is thead wear is can operate on any kind of kind of kind of operating system as durationy as the emulator operates on thead wear operating system.

The Rexx Interpreters for the various hand held devices categories are shown below.

  • Windows CE – Brexx
  • Palm OS – Rexx for Palm OS
  • Symbian OS – Regina

For the DOS emulator, the folloearng steps need to be carried away −

Step 1 − First is to download PocketDOS which is a popular DOS emulator. It is styleed to operate on many kind of kind of operating systems and has supinterface for common VGA screens and serial and parallel interfaces.

Step 2 − The next step is to download the BRexx files for 16-bit DOS to a Windows PC.

Step 3 − The final step is to use ActiveSync to sync the Rexx program to the handheld device.

There are some other commercial DOS based products available. XTM is a product which falls below this particular particular category. The features of this particular particular product are as follows −

  • Supinterface for the 80186 CPU and instruction set.

  • It kind of works away the BIOS code for much better performance.

  • It can provide emulation for the Math co-processor, version 8087 MPU

  • It provides access to the serial interfaces.

  • It supinterfaces a variety of languages such as English, French and German.

Rexx – Performance

One of the key aspects of any kind of kind of programming language is the performance of the application. Special practionionices need to be considern care of to ensure thead wear the application’s performance is not hampered-coloured-coloured-coloured. Let’s look at some of the conpartrations described in steps for much better belowstanding −

Step 1 − Try to red-coloured-coloured-coloureduce the number of instructions – In Rexx every instruction carries an overmind. So check to red-coloured-coloured-coloureduce the number of instructions in your program. An example of instructions thead wear can be red-coloured-colourestyleed is shown below.

Instead of uperform multiple if else statements one can use the parse statement. So like in the folloearng program, instead of having an if condition for every value, and getting the value of word1, word2, word3 and word4, use the parse statement.

/* Main program */  

parse value 'This is a Tutorial' with word1 word2 word3 word4 
say "'"word1"'" 
say "'"word2"'" 
say "'"word3"'" 
say "'"word4"'" 

Step 2 − Try to combine multiple statements into one statement. An example is shown below.

Suppose if you had the folloearng code which did the bumignment for – a and b and completeed it to a method caldelivered proc.

do i = 1 to 100 
a = 0 
b = 1 
call proc a,b 
end

You can easily replace the above given code with the folloearng code uperform the parse statement.

do i = 1 for 100 
parse value 0 1 with 
a, 
b, 
call proc a,b 
end 

Step 3 − Try to replace the do..to loop with the do..for loop wherever achievable. This is normally recommended when the manage variable is being iterated through a loop.

/* Main program */ 
do i = 1 to 10 
say i 
end 

The above program ought to be replaced by the folloearng program.

/* Main program */ 
do i = 1 for 10 
say i 
end

Step 4 − If achievable, remove the for condition from a do loop as shown in the folloearng program. If the manage variable is not required-coloured-coloured-coloured, then just put the end value in the do loop as shown below.

/* Main program */ 
do 10 
say hello 
end

Step 5 − In a select clause, whead wearever u feel is the best condition which will be evaluated needs to put 1st in the when clause. So in the folloearng example, if we know thead wear 1 is the the majority of regular option, we put the when 1 clause as the 1st clause in the select statement.

/* Main program */ 
select 
when 1 then say'1' 
when 2 then say'2' 
otherwise say '3' 
end 

Rexx – Best Programming Practionionices

Every programmer wants their own program to be the best when it comes to quality and efficiency. The folloearng are some of the best programing practionionices or hints when writing Rexx programs which can help one achieve these goals.

Hint 1

Use the address command before you issue any kind of kind of command to the operating system or command prompt. This will help you get the address space beforehand in memory and cause your program to operate more effectively.

An example of the address command is shown below.

Example

/* Main program */ 
address system dir 

The awayput of the command is as follows, but it could vary from system to system.

Volume in drive H is Apps 
Volume Serial Number is 8E66-AC3D  
Directory of H:  
06/30/2016  01:28 AM    <DIR>          Apps 
07/05/2016  03:40 AM               463 main.course 
07/07/2016  01:30 AM                46 main.nrx 
07/07/2016  01:42 AM                38 main.rexx 
3 File(s)            547 bytes 
Dir(s)  313,085,173,760 bytes free

Hint 2

Ensure all commands to the operating system are in upper case and in quotes wherever achievable.

An example for the exactionion exaction same is shown below.

Example

/* Main program */ 
options arexx_bifs 
say chdir('REXXML100') 
say immediateory()

When we operate the above program, we will get the folloearng result.

0 
D:rexxxml100 

Hint 3

Avoid creating big comment blocks as shown in the folloearng program.

Example

/******/ 
/* */ 
/* */ 
/* */ 
/******/ 
/* Main program */ 
address system dir

Hint 4

Use the Parse statement to bumign default values. An example for the exactionion exaction same is shown below.

Example

parse value 0 1 with 
a, 
b 

Hint 5

Use the "Left(var1,2)" statement wherever achievable instead of the “substr(var1,1,2)" statement.

Hint 6

Use the "Right(var1,2)" statement wherever achievable instead of the “substr(var1,duration(var1),2)" statement.

Rexx – Graphical User Interface

In order to use the graphic user interfaces available in Rexx, one needs to use 2 packages, one is caldelivered ActiveTcl and the other is the Rexxtk package. Adurationy with these 2 packages, one can style normal forms which can have buttons and other manages on the forms.

Environment Setup

The 1st slimg to do is the environment setup. Let’s go through the folloearng steps to have the environment in place.

Step 1 − Download the Activetcl package from the folloearng websit downe − /index.php?s=httpwwwactionionivestatecomactionionivetcl

Active State

Step 2 − The next step is to start the installation of ActiveTCl. Click on the Next button on the screen to proceed.

Installation of Active TCI

Step 3 − Accept the license Agreement and click on the Next button.

Accept License Agreement

Step 4 − Choose a location for the installation and click on the next button.

Location for Installation

Step 5 − Choose a location for the installation of the demo’s and click on the Next button.

Demo's

Step 6 − Click on the Next button to proceed with the installation.

Click Next

Step 7 − Click on the Finish button to compallowe the installation.

Click Finish

Step 8 − The next step is to download the Rexxtk gentlebattlee from the folloearng link − /index.php?s=httpssourceforgenetprojectsrexxtk

Step 9 − Double click the installer file from the link in the previous step to start the installation. Click on the next button to proceed.

Installer File

Step 10 − In the next screen, click on the Yes button to concur to the License Agreement.

Click Yes

Step 11 − In the next screen, select the location for the installation and click on the Next button.

Choose Location

Step 12 − Choose the Program folder location and click on the next button.

Program Folder Location

Once the installation is compallowe, we can now start with programming the GUI’s in Rexx.

Basic Program

Let’s see how we can style a easy fundamental program with Rexx in a graphical user interface format.

Example

/* Main program */ 
call RxFuncAdd 'TkLoadFuncs','rexxtk','TkLoadFuncs' 
call TkLoadFuncs 
do forever 
interpret 'Call' TkWait() 
end 
call TkDropFuncs 
exit 0 

The folloearng slimgs need to be noted abaway the above program −

  • The Rexxtk library and all of it is functions are loaded uperform the RxFuncAdd command.

  • The do forever loop will keep the earndow open up and will wait around around for the user input.

  • Once the user input is detected, the program will exit.

When the above program is executed, you will get the folloearng awayput.

Output

Creating Menus

Menus are developd with the help of the TkMenu and TkAdd functions. The syntax of these functions are given below.

Syntax

TkMenu(widgetname,options,0) 

Parameters

Widgetname − A name to give to the menu.

Options can be any kind of kind ofone of the folloearng −

  • selectcolour − if checkpackagees or radio buttons are used as menu options, then this particular particular option specifies the colour to select when any kind of kind of menu option is selected.

  • tearaway − This option is used for adding sub menus to the main menu.

  • title − The string thead wear needs to be used to give the earndow a title.

Return Value

A handle to the menu developd.

Example

/* Main program */ 
call RxFuncAdd 'TkLoadFuncs','rexxtk','TkLoadFuncs' 
call TkLoadFuncs 

menubar = TkMenu('.m1') 
filemenu = TkMenu('.m1.file','-tearaway', 0) 
call TkAdd menubar, 'cascade', '-label', 'File', '-menu', filemenu 
call TkAdd filemenu, 'command', '-label', 'Open...', '-rexx', 'getfile' 
call TkConfig '.', '-menu', menubar 

do forever 
interpret 'Call' TkWait() 
end 
call TkDropFuncs 
exit 0

The folloearng slimgs need to be noted abaway the above program −

  • The menubar is developd uperform the TkMenu function. The ‘tearaway’ parameter means thead wear we need to develop submenus which is going to be attached to the main menu.

  • We then add 2 menu options caldelivered File and Open uperform the TkAdd function.

When the above program is executed, you will get the folloearng awayput.

Output File

Rexx – Reginald

Reginald is one more Rexx interpreter which was developed by Jeff Glantt and has some customizations on how Rexx programs can be operate. In this particular particular section, we will see how to get Reginald setup and operate a couple of Rexx programs in it.

Environment Setup

The 1st step is the environment setup which is to download the Reginald files. This can be done from the folloearng websit downe link − /index.php?s=httpwwwmanmrknettutorialsrexxReginaldearn32rxusrw32htm

Reginald

Once the download is compallowe and you launch the installer, the next screen will allow you to select the install location.

Click the Install button to proceed.

Install Reginald

Once compallowe, we can now start to operate one sample program in the Reginald interpreter. Create a easy program as shown below.

/* Main program */ 
say 'Hello' 

Then operate the folloearng command −

RxLaunch.exe main.rexx 

You will then get the folloearng awayput. This program will now be operatening in the Reginald interpreter.

Reginald Interpreter

Other Functions Available

Apart from the normal Rexx commands, Reginald had some specific commands thead wear are tailor-made for the Windows operating system. DriveMap is one such command −

DriveMap

This function gives information on the drive.

Syntax

Drivemap(,options) 

Parameters

Options − These are a list of keywords which can be used to get various information on the drives of the local computer.

Return Value

A string value which has information on the drive.

Example

/* Main program */ 
say 'Drives on system : ' DriveMap(,'FIXED') 

If the above program is operate, you will get the folloearng awayput. This awayput depends from system to system.

List of disk drives :  C: D: 

Rexx – Web Programming

Rexx has the facility to work with web servers as well. The the majority of common being the apache web server. In order to use Rexxw with the Apache web server, you need to 1st download the Rexx modules from the folloearng link − /index.php?s=httpssourceforgenetprojectsmodrexxsourcetypred-coloured-coloureimmediate

Once done, develop sure to add the mod Rexx modules to the course route.

The folloearng lines need to be added and modified to the Apache configuration file.

The folloearng lines need to be added to the end of the appropriate −

  • httpd.conf LoadModule list.
  • LoadModule rexx_module modules/mod_rexx.dll

The folloearng lines ought to be added at the end of the http.conf file.

  • AddType application/x-httpd-rexx-script .rex .rexx
  • AddType application/x-httpd-rexx-rsp .rsp
  • Add these for REXX Server Page supinterface
  • RexxRspCompiler “c:/Program Files/Apache Group/Apache2/bin/rspcomp.rex”

Once the above modifys have been made, you need to shut down and restart your apache web server.

The above lines furthermore allow you to have Rexx based server pages just like Java server pages. You can add the Rexx code immediately to the html pages.

An example is shown below −

<p>The current date and time is 
   <?rexx 
      /* Inserting the rexx statement */ 
      say date() time() 
   ?>
</p>

When a Rexx based server page is operate, the folloearng slimgs are carried away −

  • First a temporary file is developd.

  • Then the Rexx Server compiler compiles the file into a Rexx program and places it in the temporary file.

  • The next step is to actionionually operate the Rexx program.

Finally, the temporary file is removed.

SHARE
Previous articleSix Sigma Introduction
Next articleTen

NO COMMENTS

LEAVE A REPLY