of 27 /27
REXX - Advanced Session II

REXX Advanced

Embed Size (px)



Text of REXX Advanced

REXX - Basics

REXX - Advanced Session II1COLLABERAContentsWhat is Host Environment ?What is Stack Stack Commands(PUSH,QUEUE,PULL)Functions (Built-in / Manual)SubroutinesSome External FunctionsHost Environment An environment for executing commands is called a host command environment.TSO - the environment in which TSO/E commands and TSO/E REXX commands execute in the TSO/E address spaceISPEXEC - the environment in which ISPF commands execute.ISREDIT - the environment in which ISPF/PDF EDIT commands execute.This environment can be set through ADDRESS command. Ex :- ADDRESS TSOSTACKAn expandable data structure to store the information.Manipulation of elements in the stack can be done through PULL,PUSH, QUEUE commands.

QUEUEPUSH puts one item of data on the top of the data stackSyntax : PUSH VAR1

QUEUEputs one item of data on the bottom of the data stackSyntax : QUEUE VAR1

PULLRemove one element from the top of the data stack.Syntax : PULL VAR1

FUNCTIONSBuilt-in functions These functions are built into the language processor

User-written functions These functions are written by an individual user

Built-in FunctionsArithmeticComparisonConversionFormattingString Manipulating MiscellaneousSome FunctionsLEFTPOS/INDEXINSERTREVERSESTRIPSUBSTRLENGTHWORDLEFTLEFTReturns a string of the specified length, truncated or padded on the right as needed.Syntax :LEFT(INPUT STREAM, Length)Example :-LEFT(COLLABERA,3) = COLPOSPOSReturns the character position of one string in another.Syntax :POS(,INPUT STREAM)Example :-POS(COL,COLLABERA) = 1POS(COLA,COLLABERA) = 0

INSERTINSERTReturns a character string after inserting one input string into another string after a specified character position.Syntax :INSERT(,INPUT STREAM,)Example :-INSERT( ,HICOLLABERA,2) = HI COLLABERA

REVERSEREVERSEReturns a character string, the characters of which are in reverse order (swapped end for end).Syntax :REVERSE(INPUT STREAM)Example :-REVERSE(COLLABERA) = AREBALLOC

SUBSTRSUBSTRReturns a portion of the input string beginning at a specified character position.Syntax :SUBSTR(INPUT STREAM,,)Example :-SUBSTR(COLLABERA,4,5) = LABER

WORDWORD Returns the nth word in the given input string.Syntax :WORD(INPUT STREAM, n)Example :-WORD(VALUE ACCELERATED, 1) = VALUE

STRIPSTRIPCuts off the spaces in the given input string.Will not cut the internal spacesSyntax :STRIP(INPUT STREAM)Example :-STRIP( COLLABERA ) = COLLABERA STRIP(HI COLLABERA) = HI COLLABERA

LENGTHLENGTHReturns the length of given input string.Counts the spaces also in the given string.Syntax :LENGTH(INPUT STREAM)Example :-LENGTH(COLLABERA) = 9LENGTH(HI SRI) = 6Miscellaneous FunctionsDATE Returns date in DD MON YYYY format (Ex :- 28 Aug 2011)TIME Returns time in HH:MM:SS format (Ex: 22:33:57 )TRACE - Used for debugging Ex : is used for line by line debug .USERID Returns user id of a particular user.TRANSLATE Translates the case (of the inbuilt-functions output like DATE).Manual functionSyntax :function(argument1, argument2,...)ORFunction ()

Example :-X=Function(argument1, argument2,...)

Example/*REXX*/Part1 = COLLABPart2 = ERAX = JOINFN ()Say XExit

JOINFN :Total = Part1||part2RETURN Total

SubroutineThe CALL instruction interrupts the flow of an exec by passing control to a sub routine.

The RETURN instruction returns control from a subroutine back to the calling exec and optionally returns a value.Example/*REXX*/Part1 = COLLABPart2 = ERACALL JOINFNSay TotalExit

JOINFN :Total = Part1||part2RETURN

SYSDSNChecks whether a dataset is cataloged or not.Returns OK if the dataset is cataloged.Syntax : SYSDSN(DATASET)

Example :-PULL DSNIf SYSDSN(DSN) = OK thenSay Valid datasetLISTDSLISTS the properties of a dataset.Syntax : LISTDS DATASET MEMBERSOutput :---RECFM-LRECL-BLKSIZE-DSORG FB 80 32720 PO--VOLUMES-- ARN015--MEMBERS-- LISTDSI SYSDSNLISTDSIReturns a function code and retrieves information about a dataset into pre-defined variables.Syntax : X = LISTDSI (DATASET)SYSDSNAME - Dataset NameSYSDSORG OrganizationSYSLRECL Record LengthSYSRECFM Record FormatSYSMSGLVL1 First Level MessageSYSMSGLVL2 Second level messageOUTTRAPTraps the output of a particular TSO command .Output will be trapped into the variable mentioned.It has to be set to OFF once trap is done.Syntax : X = OUTTRAP(OUT.) LISTDS DATASET MEMBERS X = OUTTRAP(OFF)Questions !! - Sriramachandra K