Labels

Wednesday 1 January 2014

Functions in REXX

This are also called as Commands or Instructions which instruct the REXX compiler what are all the things to do.

Terminal input and output

Say - 'Say' Command is used to display output to the terminal/user.

Pull - 'Pull' command is used  to recieve input from the terminal/user. user has to Press 'Enter' once the user given the input.

Example:

SAY “ENTER YOUR AGE”
PULL AGE /*What ever the person types is converted
into upper case and stored in AGE */

PARSE PULL AGE /* Same as above, but input is not
converted to Uppercase */

SAY ‘ENTER YOUR FIRST AND LAST NAME ‘

PULL FNAME LNAME /*REXX assumes variables are
delimited by space */


Tip: Suppose if a user want to display the variable name as it is in the terminal then he should write the variable within single quotes.

For Example, consider the below program.

/* REXX */

Say A
A = Hello World
Say A
Say 'A'

Say A Statement in above code behaves differently.

First 'Say A' displays 'A' as 'A' doesn't contain any value.

Second 'Say A' displays as 'Hello World' as 'A' contains 'Hello World'.

Third 'Say 'A'' displays the word 'A'.

Variables in REXX

There is no variable declaration in REXX. Varaibles are declared on the fly the first time it appear in a statement.

For Example, consider the below program.

/* REXX */

Say A
A = Hello World
Say A

Say A Statement in above code behaves differently.

First 'Say A' displays 'A' as 'A' doesn't contain any value.

Second 'Say A' displays as 'Hello World' as 'A' contains 'Hello World'.

THE RULES FOR VARIABLE NAMES ARE
FIRST CHARACTER NOT 0-9 OR PERIOD.
REMAINING CHARACTERS ANYTHING EXCEPT BLANK.
CAN BE 250 CHARACTERS LONG
UPPER AND LOWER CASE CHARACTERS ASSUMED BE THE
SAME.

VARIABLES CAN ASSIGN THE VALUE USING SIMPLE
ASSIGNMENT STATEMENT OF THE FORM

<VARIABLE> = EXPRESSION

Variables can be used in arithmetic expression if they contain valid numeric value.

Explicit and Implicit Execution of REXX

After you have placed REXX instructions in a data set, you can run the exec
explicitly by using the EXEC command followed by the data set name

Explicit execution
= TSO EX ‘Q1.Q2.EXEC(HWORLD)’


or implicitly
by entering the member name. You can run an exec implicitly only if the PDS that
contains the exec was allocated to a system file (SYSEXEC OR SYSPROC) or it
is allocated to an application CLIST OR EXEC.


Implicit Execution
= TSO HWORLD

What is REXX and How to create a REXX Program?

REXX (Restructured EXtended eXecutor) is a powerful interactive
programming language that can execute system commands, such as TSO, ISPF
etc.
REXX is a procedural language that allows programs and algorithms to be written
in a clear and structured way. It is easy to use by experts and casual users alike.
REXX has been designed to make manipulation of the kinds of symbolic objects
people normally deal with such as words and numbers.

What we can do with REXX?

1. Request Input from the terminal/user.
2. Display output to the terminal/User.
3. Execute TSO Commands.
4. Read files.
5. Write files.

How to write a REXX Program?

Creating a REXX program is as simple as 1-2-3.

Here is sample program 'Hello World'.

1. open a PS file.

2. Write the below code and  save the file.

/*  REXX */
SAY 'HELLO WORLD'

Every REXX program should have word 'REXX' in it's first line.

3. Give 'EX' before the member name to execute the macro.