Rexx Basics
1) Rexx Hello World Program:
/*REXX*/
Say ‘Hello World!!!’
1a) Debugging Rexx Program
Write the line "Trace R" at starting of program
/*REXX*/
Trace r
similarly Trace E and few more can be used to debug
2) Comments in Rexx:
/* single line comment */
/* multi line
comment */
3) Split a line in Rexx / line continuation in Rexx:
Say ‘Use comma’,
‘To split a line’
4) Rexx code to accept input
Pull Name
Pull Age
Pull Gender
Pull Phoneno
/* Name, Age, Gender, Phoneno are variables */
/* There is no need of seperate declaration of varialbe in Rexx compared to C or any other lang */
5) Arithmetic Operators in Rexx
+ Add
- Subtract
* Multiply
/ Divide
% Divide and return a whole number without a remainder
// Divide and return the whole number only
** Raise a number to a whole number power
- -number (Negate the number)
+ +number (Add the number to 0)
6) Comparison Operators in Rexx
== Strictly Equal
= Equal
\== Not Strictly Equal
\= Not Equal
<> Not Equal
> Greater than
< Less than
> < Greater than or less than
> = Greater than or equal to
< = Less than or equal to
7)Logical Operators in Rexx
& AND
| OR
&& Exclusive OR
\ NOT
8)Concatenation Operators in Rexx
Say a b /* output is "a b" */
Phoneno = 1234567890
Say "+91"Phoneno /* output is +911234567890 */
Say "+91 "Phoneno /* output is +91 1234567890 */
Say "+91" Phoneno /* output is +91 1234567890 */
Say "+91"||Phoneno /* output is +911234567890 */ /*pipe char to make sure there is no space in between*/
9)IF/THEN/ELSE in Rexx
/* single line IF */
IF condition THEN
instructions
/* multi line IF */
IF condition THEN DO
instructions
instructions
instructions
END
-----------------------
IF condition THEN DO
instructions
instructions
END
ELSE
instructions
-----------------------
IF condition THEN
instructions
ELSE DO
instructions
instructions
END
-----------------------
IF condition THEN DO
instructions
instructions
END
ELSE DO
instructions
instructions
END
-----------------------
IF condition THEN DO
instructions
instructions
END
ELSE IF condition DO
instructions
instructions
END
10) Select Condition in Rexx
SELECT
WHEN condition THEN instruction
WHEN condition THEN instruction
WHEN condition THEN instruction
.
.
.
OTHERWISE
instruction(s)
END
11) DO Loop in Rexx
Do 3
Say "Number"
End
Do number = 1 to 10
say "Number" number
End
Do Forever
say "Loop is infinite"
End
Do While condition
instructions
End
Do Until condition
instructions
End
12) Exit a loop in Rexx
"Leave" & "Iterate" keywords
i = 0
Do Forever
i = i + 1
say "Loop is infinite"
if i = 15 then
Leave
End
i = 0
Do Forever
i = i + 1
say "Loop is infinite"
if i = 15 then
Iterate
End
13) Arrays in Rexx, Arrays are called as Stem in Rexx
Syntax : Name.
To set default value to all STEM variables use
Name. = "FADO"
All the stem variables will be initialised as FADO
Stem data starts from 1 but in arrays it starts from 0
Stem 0th contains the depth of the stem is valid to.
0th values is used in loops so you will know where the stem ends.
Name.1 = 1
Name.2 = 2
Name.0 = 2
If we dont know the number of items present in an stem we can use outtrap to set Name.0 by system
CALL OUTTRAP (‘Name.’)
“LISTC”
Multidimention stem
Name.1.1 = "Jack"
Name.1.2 = "John"
Name.1.1.1 = "Doe"
14) Subroutines in Rexx
Subroutines are called using CALL statement
CALL StrVal
Exit
StrVal:
Say "this is a subroutine"
Return
----------------------------------
/*REXX*/
Val1 = 5
Val2 = 3
CALL StrVal Val1 Val2
Say "Value returned from subroutine is stored in Result variable " Result
Parse Value Result with Var3 Var4 Var5
Exit
StrVal:
ARG Num1 Num2 /* parsing the input */
Say "this is a subroutine"
Say Num1
Say Num2
Num3 = Num1 + Num2
Num4 = Num1 - Num2
Num5 = Num1 * Num2
Return Num3 Num4 Num5
----------------------------------
The above code will work if this code is placed in a PDS or a PS
Or Place both the Main prog and the Subroutine StrVal in same PDS
but different member. Name the Subroutine member as StrVal
remove the first line StrVal as its of no use.
No comments:
Post a Comment