Tuesday, July 21, 2009

REXX: Parsing a stream with a delimiter

PARSE VAR DSNAM QF1'.' QF2'.' QF3'.' QF4'.' QF5
Where DSNAM is a string with delimiter say 'ABCDE.DHIAH.KKKAL.ASAL.VVVV'
The delimiter here is '.' It could be '/' '-' etc
O/p:
QF1='ABCDE'
QF2='DHIAH'
QF3='KKKAL'
QF4='ASAL'
QF5='VVVV'

Listing datasets - ISPF command

Initialises the list of datasets for a criterion:
"ISPEXEC LMDINIT LISTID(IDVAR) LEVEL("LEVELVAR")"
Where IDVAR is a variable to be used by the system to assign a name to the list initialised. LEVELVAR is a variable which holds the selection criteria. Ex: NFSK00.ABC*.KQLFR
Retrieve the list initialised:
"ISPEXEC LMDLIST LISTID("IDVAR") OPTION(LIST) DATASET(DSVAR)"
Where DSVAR is a variable which holds the current dataset in the list
After retrieving the ID variable IDVAR has to be freed:
"ISPEXEC LMDLIST LISTID("IDVAR") OPTION(FREE)"

If the ID variable is used so many times, say in a loop, it is advisable to initialise the variables IDVAR and DSVAR.
DROP IDVAR
DROP DSVAR

REXX builtin function - WORDPOS

Returns the word position in a given string
WORDPOS(srch-str, str-srched,)
where
srch-str -> String to be searched
Str-srched -> String in which srch-str is searched for
Start pos -> start of search. This is optional and by default it is 0 i.e beginning of str-srched
Example:
WORDPOS('dog', 'barking dogs seldom bite')
--returns 2
WORDPOS('tide', 'time waits for none')
--returns 0
WORDPOS('be', 'To be or not to be',3)
--returns 6 since the search starts at 3rd word 'or'