rexx basics, macros & panels - training

33
REXX FUNDAMENTALS, MACROS & PANELS By Karthik Shyam Manoharan

Upload: saha24

Post on 27-Nov-2014

1.090 views

Category:

Documents


27 download

TRANSCRIPT

Page 1: REXX Basics, Macros & Panels - Training

REXXFUNDAMENTALS, MACROS & PANELS

By

Karthik Shyam Manoharan

Page 2: REXX Basics, Macros & Panels - Training

OUTLINEREXX Basics

Introduction to REXX Language Basics Control Structures Arrays File Handling & I/O Functions, String Manipulation

REXX EDIT MACROS & PANELS

EDIT Macro Basics ISREDIT Services Panel Definition & Basics REXX – Panel Interfacing

Page 3: REXX Basics, Macros & Panels - Training

REXX - Introduction REXX – Overview & Features

REstructured eXtended Executor Interpreted Procedural Language Convenient built-in functions Good debugging and parsing capabilities Easy interfacing with ISPF services & TSO Good for automation and custom built applications Resource intensive

Page 4: REXX Basics, Macros & Panels - Training

REXX – Language Basics Where to code a REXX program?

How to Run a REXX program? Through TSO EXEC command Concatenate the PDS with REXX to SYSEXEC or

SYSPROCEg: “TSO ALLOCATE DD(SYSPROC) DA('DEB6028.REXX.EXEC') SHR REU”

Type EX next to the member name Through JCL (IRXJCL)

Page 5: REXX Basics, Macros & Panels - Training

REXX – Language Basics No declaration needed! Data type decided only on the first assignment

A=“STR”B=124C=A; C=B; C=D

Arithmetic operators: ( + , - , > , < , = , \= , == ) Logical operators: ( & , | , && , /) Concatenation operators ( || , blank space ) SAY & PULL Statements

Page 6: REXX Basics, Macros & Panels - Training

REXX - Control Structures Conditional Statements

IF <condition> THEN DO<instructions>END

ELSEDO<instructions>END

SELECTWHEN <condition> THEN <instructions> WHEN <condition> THEN <instructions>OTHERWISE<instructions>

END

Page 7: REXX Basics, Macros & Panels - Training

REXX - Control Structures Looping Statements

DO <variable> = <start> TO <end> [STEP] <value><instructions>

END

DO WHILE <condition> <instructions>

END

DO UNTIL <condition> <instructions>

END

DO FOREVER <instructions>

END

Page 8: REXX Basics, Macros & Panels - Training

REXX - Control Structures Unconditional Control Transfer Statements

ITERATETransfers control to the top of the loop

LEAVEBreaks the loop and transfers control to the next statement outside the loop

EXIT <RC>Exits the program to the calling environment with the return code specified

CALL / RETURNFor calling subroutines within programCALL <LABEL><LABEL> :

<instructions><instructions>

RETURN

SIGNAL <LABEL>Transfers control to the specified label

Page 9: REXX Basics, Macros & Panels - Training

REXX - Arrays REXX Arrays – STEM fields

STEM basicsLength of the array is contained in <STEMNAME>.0

1 DIMENSIONAL: <STEMNAME>.<SUBSCRIPT>

2 DIMENSIONAL: <STEMNAME>.<SUBSCRIPT1>. <SUBSCRIPT2>

Example: MYARR.1 = 2, MYARR.2 = E, MYARR.3=“C”, MYARR.0 = 3

Length/Bounds need not be defined in the beginning Subscripts need not always be numerals Sparse arrays supported Group initialization allowed

Page 10: REXX Basics, Macros & Panels - Training

REXX – Sample Programs Sample REXX Code: To illustrate how easy it is to capture data from TSO

SYSUSID=USERID()SYSDATE = DATE()SAY “Name Please : ”PULL NAMEDO I = 1 TO 3 SAY “Hi!!! ” || NAME || “, your id is “ || SYSUSIDENDSAY “Today’s date is: “ SYSUSIDEXIT

Test your REXX syntax:

Write a program to reverse the given number!

Page 11: REXX Basics, Macros & Panels - Training

REXX – File Handling & I/O Allocate dataset to read

“Alloc F(<ddname>) shr ds(‘dataset name’)” Read dataset using EXECIO – diskr

"EXECIO * DISKR <ddname> (STEM <stemname.>"

Write dataset using EXECIO – diskw "EXECIO * DISKW <ddname> (STEM <stemname.>"

Close the dataset "EXECIO 0 DISKR <ddname> (Finis"

Free the allocation “FREE F(<ddname>)

Page 12: REXX Basics, Macros & Panels - Training

REXX - Some Commonly Used String Functions PARSE

INSERT(' ','abcdef',3) -> 'abc def'

INDEX('abcdef','cd') -> 3

LASTPOS(' ','abc def ghi') -> 8

OVERLAY(' ','abcdef',3) -> 'ab def‚

REVERSE('XYZ ') -> ' ZYX‘

RIGHT('abc def',5) -> 'c def‘

STRIP(' ab c ') -> 'ab c'

Page 13: REXX Basics, Macros & Panels - Training

REXX – Some Commonly Used TSO Functions SYSDSN

SYSDSN(“MY.PDS(MEMNAME)") returns ‘OK’ if dataset is present

OUTTRAPOUTTRAP(‘<STEM.>’) “TSO command”OUTTRAP(‘OFF’)

In General any TSO command can be invoked in a REXX and its results can be captured in the program EG: LISTD ‘<MY.PDS(MEMNAME)>’ MEMBERSThe command needs to be given inside quotes in the REXX program and its result

can be trapped using OUTTRAP“LISTD ‘DEB6028.REXX.EXEC’ MEMBERS”

Page 14: REXX Basics, Macros & Panels - Training

REXX – Some Commonly Used TSO Functions MSG(‘ON’) or MSG(‘OFF’)

LISTDSI x = LISTDSI(work.exec) SAY 'Function code from LISTDSI is: ' x SAY 'The data set name is: ' sysdsname SAY 'The device unit on which the volume resides is:' sysunit SAY 'The record format is: ' sysrecfm SAY 'The logical record length is: ' syslrecl SAY 'The block size is: ' sysblksize SAY 'The allocation in space units is: ' sysalloc SAY 'Type of RACF protection is: ' sysracfa

Page 15: REXX Basics, Macros & Panels - Training

REXX –File I/O Sample Program A REXX program to read a sequential dataset

change all occurrences of strings “XYZ” to “ABC”“X1Y1Z1” to “A1B1C1”“X2Y2Z2” to “A2B2C2”

Write a REXX program to display the member names and number of members

Page 16: REXX Basics, Macros & Panels - Training

REXX – ISREDIT Macro Basics These are nothing but REXX routines that can be

invoked from the command line of the edit window ISREDIT Macros have access to the data shown in

the edit windows All ISPF edit commands can be used in the REXX

Programs Easy to code and uses very little resources when

compared to other kinds of REXX programs Is also suitable for REXX programs invoking ISPF

panels

Page 17: REXX Basics, Macros & Panels - Training

REXX – ISREDIT Macro Basics ADDRESS ISREDIT

To communicate with ISREDITADDRESS ISREDIT “<ISPF COMMAND>”Eg: ADDRESS ISREDIT "MACRO PROCESS"

“ISREDIT F ALL ‘STRING’ 2”

ADDRESS ISPEXEC To communicate with panel servicesADDRESS ISREDIT “<ISPF COMMAND>”Eg: ADDRESS ISPEXEC "CONTROL ERRORS RETURN"

“ISPEXEC SETMSG MSG(ISRZ001)"

ADDRESS TSO To communicate with TSO – By default this is set as the program is invoked from TSOEg: File allocation commands““ALLOCATE DD(SYSPROC) DA(‘DEB6028.REXX.EXEC’) SHR”

Page 18: REXX Basics, Macros & Panels - Training

REXX – Sample REXX Macro REXX program to find the string in the current cursor position

/* REXX */ ADDRESS ISREDIT "MACRO PROCESS" ADDRESS ISPEXEC "CONTROL ERRORS RETURN" MSG_STATUS=MSG('OFF') "ISREDIT RES " "ISREDIT (CROW,CCOL) = CURSOR" "ISREDIT (CURRLINE) = LINE .ZCSR" PARTSTR = SUBSTR(CURRLINE,CCOL) BLNKPOS = INDEX(PARTSTR,' ') FINSTR = SUBSTR(PARTSTR,1,BLNKPOS) "ISREDIT F NEXT '"FINSTR"' "

Page 19: REXX Basics, Macros & Panels - Training

REXX – Try it again using ISREDIT Macro A REXX program to read a sequential dataset

change all occurrences of strings “XYZ” to “ABC”“X1Y1Z1” to “A1B1C1”“X2Y2Z2” to “A2B2C2”

As you’ll find out, it’s a lot easier to code this requirement using edit macro. It takes up very little resource as the REXX macro is called from the command line, after opening the sequential dataset in edit/view mode

Page 20: REXX Basics, Macros & Panels - Training

REXX - ISREDIT Services Two kinds of ISREDIT commands

Those that can be issued only through macrosExamples:"ISREDIT (CURLINE)= LINE .ZCSR" "ISREDIT (LEND)= LINENUM .ZLAST"

Those that can be issued in the command line as well as macrosExamples:"ISREDIT RES" "ISREDIT F ALL ‘PROGRAM-ID‘ " "ISREDIT NUM ON STD COB"

Page 21: REXX Basics, Macros & Panels - Training

REXX – More EDIT Macros

This program removes COBOL comments in the edit window and stores the commented code in a file

This program reads the file and inserts the COBOL comments back into the program

CODIN.TXT

CODOUT.TXT

Page 22: REXX Basics, Macros & Panels - Training

REXX – ISPF Panel Definition Panel definition language is used to create ISPF

dialogs and panels They can be invoked from the ISPF dialog test

option for testing They can be displayed by REXX programs They consist of four main sections

)ATTR – Sets the attributes for the special characters )BODY – Skeleton of the actual panel is described here )PROC – Used for minimal processing, like I/P validation )END – Signifies end of the panel

Page 23: REXX Basics, Macros & Panels - Training

REXX – ATTR SectionATTR – It defines the special characters and their attributes

)ATTR<SP.CHR> TYPE ([TEXT | INPUT]) INTENS ([LOW | HIGH]) COLOR

([GREEN | WHITE | RED …. ]) SKIP ([ON | OFF]) HILITE ([USCORE | REVERSE | BLINK]) CAPS ([ON | OFF])

Examples)ATTR# TYPE(TEXT) INTENS(LOW) SKIP(ON) CAPS(ON)_ TYPE(INPUT) INTENS(LOW) COLOR(WHITE) HILITE(USCORE)! TYPE(TEXT) INTENS(LOW) COLOR(RED)$ TYPE(TEXT) INTENS(HI) COLOR(PINK)

Page 24: REXX Basics, Macros & Panels - Training

REXX – BODY SectionBODY – It defines the skeleton of the panel

The special character says whether the line (or part of the line) is an output text line or an input line

The special characters also define a number of other elements controlling the display like color, intensity, effects etc

There are default characters which have certain preset characteristics ‘+’ : Says that the line should be just treated as a hi intensity

text and should be displayed as it is ‘_’ : Says that what follows the ‘_’ symbol is an input field

and can be used by REXX to access the values contained

The attributes of the default special characters can also be changed

Page 25: REXX Basics, Macros & Panels - Training

REXX – )BODY Example)BODY$ -------------------------- ALTERNATE 3.4 MENU V1.0 -------------- BY: KARTHIK%% COMMAND ==> _ZCMD%+ ENTER SELECTION NO!('0' TO EXIT)+===> _C#%%+ DSN@(1)_DSN1 # MODE (E/V/B) _M1#%%+ DSN@(2)_DSN2 # MODE (E/V/B) _M2#%%+ DSN@(3)_DSN3 # MODE (E/V/B) _M3#%% + DSN@(4)_DSN4 # MODE (E/V/B) _M4#%%+ DSN@(5)_DSN5 # MODE (E/V/B) _M5#

Page 26: REXX Basics, Macros & Panels - Training

REXX – ISPF Panel Definition )PROC – This section is mainly used for input

data validation. But it is advisable to handle validation in the program invoking the panel

)END – This just tells ISPF that the panel definition has come to an end

Page 27: REXX Basics, Macros & Panels - Training

REXX – Complete Panel Example)ATTR# TYPE(TEXT) INTENS(LOW) SKIP(ON) CAPS(ON))BODY%----------------------------- COBOL FILE I/O CODER ----------------------------%COMMAND : _ZCMD %+ NO OF I/P FILES USED ===> _IPFNUM # NO OF O/P FILES USED ===> _OTFNUM #+ PGM NAME: _PGMNAME #%% INPUT FILES - INFORMATION AREA%% SNO DDNAME - COPYBOOK - I/P RECORD NAME+ (1) _DDIF1 #- _CPIF1 # - _RCIF1 #+ (2) _DDIF2 #- _CPIF2 # - _RCIF2 #+ (3) _DDIF3 #- _CPIF3 # - _RCIF3 #+ (4) _DDIF4 #- _CPIF4 # - _RCIF4 #%% OUTPUT FILES - INFORMATION AREA%% SNO DDNAME - COPYBOOK - O/P RECORD NAME+ (1) _DDOF1 #- _CPOF1 # - _RCOF1 #+ (2) _DDOF2 #- _CPOF2 # - _RCOF2 #+ (3) _DDOF3 #- _CPOF3 # - _RCOF3 #+ (4) _DDOF4 #- _CPOF4 # - _RCOF4 #)END

Page 28: REXX Basics, Macros & Panels - Training

REXX – Panel Interfacing Set the panel library

Invoke the panel using the display command

Read the panel input fields directly and continue processing

Throw error messages if required

Page 29: REXX Basics, Macros & Panels - Training

REXX – Panel Interfacing Setting the panel library

ADDRESS ISPEXEC "LIBDEF ISPPLIB DATASET ID(‘<PANELS.PDS>')“

Invoking the panel libraryADDRESS ISPEXEC

"DISPLAY PANEL(<PANELNAME>)"

Note: <PANELNAME> is a member of <PANELS.PDS>

Page 30: REXX Basics, Macros & Panels - Training

REXX – Panel Interfacing Reading panel fields

Directly use the panel fields in the program

In the body, if the line below is coded+ PGM NAME: _PGMNAME #

In the REXX program you can directly get the value entered in the screen as shown belowMYREXXFIELD = PGMNAME

Page 31: REXX Basics, Macros & Panels - Training

REXX – Panel Interfacing Populating error messages in the top right end of the

screen Populate system field ZEDSMSG for short error messages Populate system field ZEDLMSG for long error messages Throw error messages on the panel using SETMSG

command

Example:ZEDSMSG = "NO IF FILES IS INVALID"ZEDLMSG = "NUMBER OF I/P OR O/P FILES INVALID"ADDRESS ISPEXEC "SETMSG MSG(ISRZ000)“

Page 32: REXX Basics, Macros & Panels - Training

REXX – Questions?

Page 33: REXX Basics, Macros & Panels - Training

Thank You