1.
REXX (Restructured Extended
Executor) - scripting language – TSO/CLIST/REXX.
Pgm - /*REXX*/ say "Hello World" - /* */ is used for comments
Pgm - /* REXX */ say add(5,6) exit add: parse arg
a,b return a + b à Output – 11
2.
Subroutines and
Functions - Functions return a value whereas subroutines
don’t.
a) Function - /* REXX */ say add(5,6) exit add: parse arg a,b
return a + b
b) Subroutine - /* REXX */ add(5,6) exit add: parse arg a,b say a +
b
c) Executing
Command - control language for a variety of command-based systems - /* REXX */
parse arg command "file1" command "file2" command
"file3" exit.
d) Keywords in
Rexx - WHILE in a DO instruction, THEN, IF or WHEN clause.
e) Comments in
Rexx - /* */
2. Data Types – Integer (5), Big Integer (5000000000), Decimal (5.5), Float (number
in scientific notation, 12E2), String (Hello).
3. Variables - var-name, var-value - /* REXX */ X = 40 Y = 50 Result = X + Y say
Result.
4. Operators - Arithmetic Operators (+ - *
/ // %), Relational Operators ( = <
> => <=), Logical Operators ( & \ &&), Bitwise Operators
(bitand / bitor / bitxor)
5. ARRAY - Allow you to group a list of values of the same type. array_name.0 =
‘first element’ or array_name.1 = ‘first element’ / Ex - /* REXX */ list.1 = 0
list.2 = 0 list.3 = 0.
Iterating through array elements – /*
REXX */ list.1 = 10 list.2 = 20 list.3 = 30 number_of_elements = 3 do j = 1 to
number_of_elements say list.j end.
Two-dimensional Arrays - /* Main program */ list.1 = 10
list.1.1 = 11 list.1.2 = 12 say list.1 say list.1.1 say list.1.2
6. LOOPS –
a) do loop - execute
a no of statement for certain no. of times.
b) do-while - execute
when condition being evaluated true,
c) do-until - execute
when condition being evaluated False.
Ex - /* Main program */ do i = 0 to 5 by 2 say
"hello" end.
7. Decision Making – IF END, IF-ELSE END, SELECT
Ex – /*
REXX */ i = 4 select when (i <= 5) then say "i is less than 5"
8. METHODS –
a)
NUMBERS (ABS, MAX, MIN, RANDOM, SIGN, TRUNC)
b)
STRING (left. Right, length, reverse, compare,
copies, substr, pos, delstr)
9. Function - FunctionName: PARSE ARG
arguement1, arguement2… arguementN Return value. Ex – /* REXX */ say add(5,6)
exit add: PARSE ARG a,b return a + b
a) Working with Arguments, arg( ) – return the count of arguments defined by function i.e in above example
‘2’. arg(index) – value of argument at specific position i.e. in above example
arg(1) is ‘5’.
b) Recursive Functions - one that
calls itself. Ex - /* REXX */ do n = 1 to 5 say 'The factorial of' n
'is:' factorial( n ) end return /*
Function to get factorial */ factorial : procedure n = arg(1) if n = 1 then
return 1 return n * factorial( n - 1 )
10. Stack –
a) External data queue, block of memory that is logically external to Rexx.
Instructions like push and queue place data into the stack.
b) Instructions like pull and parse pull extract data from it.
c) /* REXX */
/* 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
*/ pull 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 */
pull line say line end exit 0 – OUTPUT – STACK: LINE #3 STACK: LINE #2 STACK: LINE #1
11. FILE I/O –
a) Reading the Contents of a File a Line at a Time (linein) – Ex - /* REXX */ line_str = linein(Example.txt)
say line_str
OUTPUT – Example1 (here the file Example.txt
contain 3 records Example1 Example2 & Example3)
/* REXX */ do while lines(Example.txt) >
0 line_str = linein(Example.txt) say
line_str end
Output – Example1 Example2 Example3
b) Writing Contents to a File (lineout) –
/* REXX */ out =
lineout(Example.txt,"Example4")
Output – ‘Example4’ will be written to file
Example.txt
12. Functions For Files – Lines, stream, charin,
chars, charout
13. Subroutines – /* REXX */ call add 1,2 exit add: PARSE ARG a,b c = a + b say c. Different Methods for Arguments – arg( ) ,
arg(index)
14. Built-In Functions – ADDRESS, BEEP, DataType, DATE,
DIGITS, ERRORTEXT, FORM, TIME, USERID, XRANGE, X2D, X2C
15. System Commands –
a) dir – /*
Main program */ dir if rc = 0 then say 'The command executed successfully' else
say 'The command failed, The error code is =' rc (error number will be
given in the rc variable name)
b) Redirection Commands – < − to
take in the input which comes from a file, > −
to output the content to a file, >> − to output the content to a
file. But the output is added to the end of the file to preserve the existing
content of the file. Ex – /* REXX */ 'sort <sortin.txt> sortout.txt' –
Output – a b c (sort command to sort
a file called sortin.txt , data from the file is sent to the sort
command, output of the sort command is then sent to the sortout.txt file).
c) ADDRESS function -
default environment used for the Input, Error and Output streams – /* Main
program */ say ADDRESS('I') say ADDRESS('O') say ADDRESS('E')
16. Parsing – PARSE
{UPPER|LOWER|CASELESS} source {template}
a) SOURCE (ARG / LINEIN / SOURCE / VAR name)
b) Template ( variable-name / literal string)
Ex – /* REXX */ parse value 'This is a Tutorial'
with word1 word2 word3 word4 say "'"word1"'" say
"'"word2"'" say "'"word3"'" say
"'"word4"'"
Output - 'This' 'is' 'a' 'Tutorial' - (here word1
etc. are template and ‘This is a Tutorial’ is source)
c) Positional Parsing –
/* Main program */ testString = "Doe John M.
03/03/78 Mumbai India"; parse var testString name1 11 name2 21
birthday 31 town 51 country say name1 say name2 say birthday say town say
country.
output – Doe John M. 03/03/78 Mumbai India
17. Signals – /* REXX */ n = 100.45 if
\ datatype( n, wholenumber ) then
signal msg say 'This is a whole
number' return 0 msg : say 'This is an incorrect number' – Output
– This is an incorrect number.
18. Debugging - Trace in Batch Mode – trace [setting] (setting – A, C, E, F , I, L,
N)
/* Main program */ trace A /* Main program */ n =
100.45 if datatype( n, whole number ) then signal msg say 'This is a whole
number' return 0 msg : say ' This is
an incorrect number ' / Trace Function –
trace(), Trace Value -
trace(trace level), Interactive Tracing
- trace ?options - press the Enter button to move onto the next line of
code.
19. Error Handling – ERROR, FAILURE, HALT, NOVALUE, NOTREADY, SYNTAX,
LOSTDIGITS. Trapping Errors - signal on [Errorcondition].
/* 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' say rc say sigl
Output – An error has occurred 40 6
20. Extended Functions – b2c, bitclr, bitcomp, buftype, crypt, fork, getpid, hash.
21. Instructions – address, drop, interpret,
nop, pull, push
/*REXX*/
ADDRESS TSO "ALLOC F(INFILE) DSN('my.seq.dsn') SHR REU"
/* INFILE is a logical name for the file */
"EXECIO * DISKR INFILE ( FINIS STEM MYFILE."
/* MYFILE is the stem (array) that holds the data */
"FREE F(INFILE)" I = 1
/* MYFILE.0 will have the number of elements in the stem */
DO WHILE I <= MYFILE.0
SAY ' LINE ' I ' : ' MYFILE.I I = I + 1
END EXIT
No comments:
Post a Comment