Restructured Exented Executor: Nagaraju Domala

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 43

REXX

Restructured EXented eXecutor


NAGARAJU DOMALA
Know more..

zJournal http://www.mainframezone.com/z-journal

IBM System z Magazine http://www.ibmsystemsmag.com/mainframe/

TSO Times http://www.tsotimes.com/index.html

zOS Newsletter http://www-03.ibm.com/systems/z/os/zos/bkserv/hot_topics.html


Day III

• Data Stack
• Stacking & Queuing Data
• Query Commands
• File Handling
• EXECIO
• Reading / Writing records
• Parsing techniques
• Lab Exercise

Nagaraju Domala
Data stack

 Place for storing variables temporarily

 Manipulated using PUSH and QUEUE

 Nolimits on the length and format of the data


items

 Theoreticallyno limit on the number of items to


be stacked - limited only by system considerations

Nagaraju Domala
Data stack

 PUSH works LIFO (Last-In-First-Out)


puts items to the top of the stack

 QUEUE works FIFO (First-In-First-Out)


puts items on the bottom of the stack

 In both cases, elements are removed by PULL

 QUEUED() gives the number of items put on a stack in a single


EXEC

Nagaraju Domala
PUSH
 used to place a new element on a REXX data stack
Syntax : PUSH {expression}
 Places the element on the top of the REXX data
stack
 The length of an element can be up to 16,777,215
 A null string of length zero is stacked if the
expression is omitted
 Stacks strings LIFO sequence

Nagaraju Domala
QUEUE
 Used to place a new element on the bottom of a REXX
data stack
Syntax : QUEUE { expression }
 stacks strings in FIFO sequence
 a null length string is stacked if expression is omitted
 The PULL instruction is used extract an element from
the top of the REXX data stack

Nagaraju Domala
NEWSTACK
 Used to create a new data stack in the REXX environment
 When this command is executed, the current data stack is
saved and a new stack is created and made the current stack
 When the stack is empty,the subsequent pull instruction
obtains input from the TSO terminal
 When the stack has data elements,the pull instruction gets
the input from the top of the stack

"NEWSTACK" /* creates new stack */


Push MSAT /* puts ‘MSAT’ in top of stack */
Push SATYAM /* puts ‘satyam’ over ‘MSAT’ */
pull data /* pulls data from the top of stack */
say ‘from the stack ‘ data /* displays ‘SATYAM’ */
pull data /* pulls data from top of stack */
say ‘from the stack ‘ data /* displays ‘MSAT’ */
pull data /* obtains input from tso terminal */

Nagaraju Domala
DELSTACK
• Used to delete the data stack that was created last in the REXX
environment
• When this command is executed the most recently created
stack is deleted and all elements on it are purged
• If there is any previous data stack, that is made available
“NEWSTACK” /* new stack is created */
push a /* ‘a’ is stored on top */
queue b /* ‘b’ is stored at the bottom */
“NEWSTACK” /* new stack is created */
push c /* ‘c’ is stored on top */
say queued() /* displays 1 */
“DELSTACK” /* deletes the current stack */
say queued() /* displays 2 */
“DELSTACK” /* deletes the stack */

Nagaraju Domala
QSTACK
 Used to determine the total number of data stacks
currently in existence
 The no of data stacks includes the original REXX data
stack, as well as those created via the NEWSTACK command
 If no additional stacks have been created via NEWSTACK ,
a 1 is returned is RC

"QSTACK" /* returns a 1 in RC */
"NEWSTACK" /* creates a new data stack*/
"NEWSTACK" /* creates another new data stack*/
"QSTACK" /* returns a 3 in RC */

Nagaraju Domala
FILE HANDLING IN REXX

Nagaraju Domala
EXECIO
 used to perform read and write operations against a
sequential dataset or a PDS member
 The data is either read from the data set and placed on
the data stack or into a list of variables, or written from
the data stack or a list of variables into the data set
 Syntax for read operations :

EXECIO {lines ¦ *} DISKR ddname {linenum}{ ( {{FINIS}} ¦ { STEM var


{FINIS} } {)} }
 Syntax for write operations :

EXECIO {lines ¦ *} DISKW ddname { ( {STEM var} {FINIS} {)} }

Nagaraju Domala
DISKR

 EXECIO DISKR for reading the dataset/member

 “EXECIO 0 DISKR mydd (OPEN” - just opens the dataset


 “EXECIO 25 DISKR myindd(FINIS”- reads 25 lines
 “EXECIO * DISKR myindd 100 (FINIS” - reads all the lines
 “EXECIO * DISKR myindd 100 (FINIS” - reads all lines
from line 100

 In all the above cases, the lines are read on to the STACK
 “EXECIO * DISKR myindd (STEM newvar.” - reads into a
stem of variables called newvar

Nagaraju Domala
DISKW

Options for DISKR also hold for DISKW

Writes to dataset/member

Can be written from stem/stack

Numerous other options available for


positioning, skipping, LIFO/FIFO etc.
Nagaraju Domala
EXECIO
/* Example - copy PDS member into another */

/* rexx*/
Address TSO
dsn = "'UADA012.REXX.SOURCE(LOOP)'"
out = "'UADA012.REXX.SOURCE(LOOPX)'"
"ALLOC DD(TEMP1) DA("dsn") SHR REUSE"
"ALLOC DD(TEMP2) DA("out") SHR REUSE"
'EXECIO * DISKR temp1(STEM DATA. FINIS'
'EXECIO * DISKW temp2(STEM DATA. FINIS'
SAY DATA.0
'EXECIO * DISKR temp2(STEM DATA. FINIS'
SAY DATA.0

Note : This example uses stem variable data to read the contents of input
file. The Number of lines read will be stored in data.0.

Nagaraju Domala
EXECIO
/* Example - copy PDS member into another and to a new PS */

/* REXX */
Address TSO
IN = "'UADA012.REXX.SOURCE(LOOP)'"
out = "'UADA012.REXX.SOURCE(LOOPX)'"
out2= "'UADA012.REXX.DAY2'"
"ALLOC DATASET("OUT2") DDNAME(OUT2) NEW LRECL(133) ",
"BLKSIZE(1330) RECFM(F,B)"
"ALLOC DD(TEMP1) DA("IN") SHR REUSE"
"ALLOC DD(TEMP2) DA("OUT") SHR REUSE"
'EXECIO * DISKR temp1(STEM DATA. FINIS'
'EXECIO * DISKW temp2(STEM DATA. FINIS'
'EXECIO * DISKW OUT2(STEM DATA. FINIS'
SAY DATA.0
'EXECIO * DISKR temp2(STEM DATA. FINIS'
SAY DATA.0
Note : This example uses stem variable data to read the contents of input file. The Number of
lines read will be stored in data.0.

Nagaraju Domala
Parsing Techniques

Nagaraju Domala
Parsing

 Separates data by comparing the data to a


template (or pattern of variable names)
 Separators in a template can be
blank,
string,
variable, or
number that represents column position

Nagaraju Domala
Parsing
 Blank - an example
 Each variable name gets one word of data in sequence
except for the last, which gets the remainder of the
data

PARSE VALUE ‘Value with Blanks.’ WITH v1 v2

v1 contains ‘Value’
v2 contains ‘ with Blanks.’

Nagaraju Domala
Parsing

Blank - another example

PARSE VALUE ‘Value with Extra Variables.’


WITH data1 data2 data3 data4 data5

data1 contains ‘Value’


data2 contains ‘with’
data3 contains ‘Extra’
data4 contains ‘Variables.’
data5 contains ‘’

Nagaraju Domala
Parsing
PARSE VAR InVar Out1Var Out2Var Out3Var

where:

InVar = String to be split


Out1Var = 1st word of InVar
Out2Var = 2nd word of InVar
Out3Var = All the Rest of InVar

Nagaraju Domala
Parsing

Substitution - an example

PARSE VALUE ‘Value with Periods in it.’ WITH v1 . v2 .

v1 contains ‘Value’
v2 contains ‘Periods’

the periods replace the words “with” and


“in it.”

Nagaraju Domala
Parsing
PARSE VAR InVar Out1Var . Out2Var

where:

InVar = String to be split


Out1Var = 1st word of InVar
. = Loose 2nd Word
Out3Var = All the Rest of InVar

Nagaraju Domala
Parsing
Separators - an example
phrase = ‘Dun , Bradstreet’

PARSE VAR phrase part1 ‘,’ part2

part1 contains ‘Dun ’


part2 contains ‘ Bradstreet’

Nagaraju Domala
Parsing
PARSE VAR InVar Out1Var "," Out2Var

where:

InVar = The Input Variable


Out1Var = Gets everything before first comma
"," = the pattern marker
Out2Var = Gets everything after first comma

Nagaraju Domala
Parsing
PARSE VAR InVar Out1Var (In2Var) Out2Var

where:

InVar = Contains the string to be split


In2Var = contains the pattern marker
Out1Var = gets everything before pattern marker
Out2Var = gets everything after pattern marker

Nagaraju Domala
Parsing

Absolute column position - an example


quote = ‘Dun & Bradstreet’
PARSE VAR quote part1 6 part2

part1 contains ‘Dun &’


part2 contains ‘ Bradstreet’

Nagaraju Domala
Parsing
Absolute column position - another example
quote = ‘Dun & Bradstreet’

PARSE VAR quote part1 5 part2 7 part3 1 part4

part1 contains ‘Dun ’


part2 contains ‘& ’
part3 contains ‘Bradstreet’
part4 contains ‘Dun & Bradstreet’

Nagaraju Domala
Parsing
Relative column position - an example
quote = ‘Dun & Bradstreet’

PARSE VAR quote part1 +5 part2 +5 part3

part1 contains ‘Dun &’


part2 contains ‘ Brad’
part3 contains ‘street’

Nagaraju Domala
Parsing
A = '123456789abcdefghij'

After: 'PARSE VAR A 3 B 8 C'


A = '12' B = '34567' C = '89abcdefghij'

After: 'PARSE VAR A 3 B +8 C'


A = '12' B = '3456789a' C = 'bcdefghij'

If Pos= '4' and Len= '6'


After: 'PARSE VAR A =(Pos) B +(Len) C'
A = '123' B = '456789'
Nagaraju Domala
Quiz
line1 = 'The merry wives of Windsor'

Parse Var line1 v1 v2 v3 v4 v5

Nagaraju Domala
Quiz
/* v1 receives "The" */
/* v2 receives "merry" */
/* v3 receives "wives" */
/* v4 receives "of" */
/* v5 receives "Windsor" */

Nagaraju Domala
Quiz
line1 = 'The merry wives of Windsor'

Parse Var line1 v1 v2 v3 v4

Nagaraju Domala
Parsing
/* v1 receives "The" */
/* v2 receives "merry" */
/* v3 receives "wives" */
/* v4 receives "of" */
/* v4 receives "of Windsor" */

Nagaraju Domala
Quiz
line1 = 'The merry wives of Windsor'

Parse Var line1 v1 v2 v3 v4 .

Nagaraju Domala
Quiz
/* v1 receives "The" */
/* v2 receives "merry" */
/* v3 receives "wives" */
/* v4 receives "of" */
/* "Windsor" is discarded */

Nagaraju Domala
Quiz
line1 = 'The merry wives of Windsor'

Parse Var line1 . v2 . v4 .

Nagaraju Domala
Quiz
/* "The" is discarded */
/* v2 receives "merry" */
/* "wives" is discarded */
/* v4 receives "of" */
/* "Windsor" is discarded */

Nagaraju Domala
Quiz
line1 = 'abcdefghijklmnopqrstuvwxyz'
Parse Var line1 1 v1 4 . 20 v2 22 . 26 v3

Nagaraju Domala
Quiz
/* v1 receives "abc" */
/* v2 receives "tu" */
/* v3 receives "z"" */

Nagaraju Domala
Quiz
line1 = '11:25:01'
Parse Var line1 hh ':' mm ':' ss

Nagaraju Domala
Quiz
/* hh receives "11" */
/* mm receives "25" */
/* ss receives "01" */

Nagaraju Domala
Lab Exercise III

 Writea REXX Program to read a dataset in the


following modes and print records on screen
 Read first N Records
 Read from Nth Record
 Write first 10 lines to another new dataset

 Write a REXX program to parse a COBOL program stored


in a PS and print following parameters :

 Program Name
 Author Name
 Compiled Date

Nagaraju Domala

You might also like