REXX Tutorial

  • REXX Tutorial

REXX - Restructured Extended Executor.

REXX is a structured, high level programming language and it was designed by "Mike Cowlishaw" (IBM).

Sample REXX Program -

///*REXX*/
//SAY 'Welcome to REXX world!'

Keyword-
SAY - It is used to print the string on console. Its like DISPLAY in cobol.


How to execute REXX program in mainframe?

REXX program can be executed by two way,

1) EX command -
Use the command "EX" in front of the member of PDS having REXX program.

2) TSO "<REXX_PROGRAM_NAME>" -
In order to run the REXX program like TSO utility/command,
    i) Add your REXX program member to CLIST dataset
    (In many this library is "<your_id>.A.CLIST")
    ii) Then us the command TSO "<program_name>"


Sample REXX program to add two variables.

Lets see how to write a sample program which will do addition of two variables.
In this example input will be given by user dynamically and output (addition) will be displayed on concole.

/*REXX*/
SAY 'Input variable 1='
PULL a

SAY 'Input variable 2='
PULL b
c= a + b
SAY 'Addition is = ' c

PULL - Its like scanf in "C".

Console after program execution -
Input variable 1=
5

Input variable 2=
6
Addition is = 11


String handling in REXX.

In REXX programs, we can handle the string using inbuilt functions

1) LENGTH - It gives the length of given string.
Sample Program -

/*REXX*/
A = 'REXX'
B = LENGTH(A)
SAY 'Length of A is =' B

Console output -
Length of A is =4

2) WORD - It gives the number of words in the given string.
Sample Program -

/*REXX*/

X = 'Use of  String function in REXX'
Y = LENGTH(X)
SAY 'No of words in X are =' Y

Console output -
'No of words in X are =6

Use of IF-ELSE statement in REXX.

Lets see how to use the IF-ELSE statement in REXX,

/*REXX*/
A = 10
B = 12
IF A > B THEN
    SAY 'A is greater than B'
ELSE
    SAY 'B is greater than A'



Use of switching logic in REXX program.

In REXX program, we can add switch logic in order perform respective task.

Sample Program -

/*REXX*/
SAY 'Your Marks'
PULL A
SELECT
  WHEN A < 40
     SAY 'You are FAIL' 
  WHEN A > 40
     SAY 'You are PASS'
  OTHERWISE
     SAY 'Please enter the correct marks'
END

SELECT - It works like SWITCH.

Output Console -
50
You are PASS


© 2013 www.MainframeGuru.info