Wednesday, November 13, 2013

REXX ISPF Panels

REXX ISPF Panels

To Display a ISPF Screen using Rexx



REXX Code


ISPEXEC "CONTROL DISPLAY REFRESH"
ISPEXEC "LIBDEF ISPPLIB DATASET ID ('IBMUSER.FADO.PANELS')"
/* TO DISPLAY FIRST PANEL*/
ISPEXEC "DISPLAY PANEL(DB2P) CURSOR(DBS1)"

/* PANEL(DB2P) specifies the Panel name which is a member name
and CURSOR(DBS1) tell ISPF to place the cursor on that Field */


Basic Display

REXX CODE TO Execute



/*REXX*/
ISPEXEC CONTROL DISPLAY REFRESH
"ISPEXEC LIBDEF ISPPLIB DATASET ID ('IBMUSER.FADO.PANELS')"
/*panels location ex: IBMUSER.FADO.PANELS*/
TIM = ""
DAT = ""
"ISPEXEC VGET (TIM,DAT) PROFILE";
"ISPEXEC DISPLAY PANEL (PANL2)"
TIM = TIME()
DAT = DATE()
"ISPEXEC VPUT (TIM,DAT) PROFILE";
"ISPEXEC DISPLAY PANEL (PANEL2)"
/*PANEL2 is the panel PDS member name */
EXIT


Panel Code

PDS member PANEL2 contains this


)ATTR
% TYPE (TEXT) INTENS (HIGH) COLOR (GREEN) SKIP (ON)
# TYPE (TEXT) INTENS (HIGH) COLOR (YELLOW)
¢ TYPE (TEXT) INTENS (HIGH) COLOR (WHITE) CAPS (OFF)
_ TYPE (INPUT) INTENS (LOW) COLOR (GREEN) PAD (_)
$ TYPE (OUTPUT) INTENS (HIGH) COLOR (BLUE)
)BODY
*----------------------------------------------------------------------*
#WELCOME TO ELT TRAINEE PAGE
*----------------------------------------------------------------------*
TIME:$TIM             %
DATE:$DAT             %
ENTER YOUR NAME: _Z              %
ENTER YOUR AGE: _Z %
*----------------------------------------------------------------------*
)INIT
.ZVARS = '(NAME AGE)'
&NAME = ''
&AGE = ''
)PROC
)END


NAME and AGE fields are not used in this program they are dummy.


------------------------------------------------------------------------------

open dataset to edit in REXX ISPF

REXX CODE


/*REXX*/
ISPEXEC CONTROL DISPLAY REFRESH
"ISPEXEC LIBDEF ISPPLIB DATASET ID ('IBMUSER.FADO.PANELS')"
"ISPEXEC VERASE (DSNAME,DSMEMB) PROFILE";
"ISPEXEC DISPLAY PANEL (PANEL3)"
"ISPEXEC VGET (DSNAME,DSMEMB) PROFILE";
SAY DSMEMB
SAY DSNAME
IF DSMEMB = "" THEN
MIG_FILE1 = DSNAME
ELSE
MIG_FILE1 = DSNAME"("DSMEMB")"
CHKLIB = SYSDSN("'"MIG_FILE1"'") /* SEE IF DATA SET EXISTS */
IF CHKLIB <> 'OK' THEN DO /* DATA SET NOT FOUND */
SAY 'ERROR -' DSN 'NOT FOUND. CHECK NAME AND QUOTES.' /* ISSUE MSG*/
EXIT 12 /* EXIT RC=12 */
END
ADDRESS ISPEXEC "EDIT DATASET ('"MIG_FILE1"')"
EXIT


ISPF Panel Code

PDS member name PANEL3


)ATTR DEFAULT (%+_)
% TYPE (TEXT) INTENS (HIGH)
+ TYPE (TEXT) INTENS (LOW) SKIP (ON)
_ TYPE (INPUT) INTENS (HIGH) CAPS (ON) JUST(LEFT) COLOR(BLUE) PADC(_)
)BODY
+ A ISPF PANEL 1 - REXX TRAINING TO OPEN DATASET FOR EDITING
+ ----------------------------------------------------------------------
+
+ %ENTER THE DATASET NAME ==>_DSNAME                                   +
+
+ %ENTER THE DATASET MEMBER IF EXISTING ==>_DSMEMB  +
+
+ +PRESS ENTER TO CONTINUE,PF3 TO EXIT +
+
+
+
)INIT
VGET(DSNAME,DSMEMB)PROFILE
)PROC
VPUT(DSNAME,DSMEMB)PROFILE
)END




To Display Error Messages on ISPF Screen using Rexx

ZEDLMSG = TEMPZTDS 'ERROR IN SELECTION'
ADDRESS ISPEXEC "SETMSG MSG(ISRZ000)"




REXX CODE to add two numbers using ISPF Panel

REXX Code


/*REXX*/
ISPEXEC CONTROL DISPLAY REFRESH
"ISPEXEC LIBDEF ISPPLIB DATASET ID ('IBMUSER.FADO.PANEL')"
DO FOREVER
 "ISPEXEC VERASE (INP1,INP2,OUT) PROFILE";
 "ISPEXEC DISPLAY PANEL (ADD)"
 CALL SUB
 "ISPEXEC VGET (INP1,INP2,OUT) PROFILE";
 IF INP1 = "" | INP2 = "" THEN DO
    ZEDLMSG = TEMPZTDS 'INVALID INPUTS'
    ADDRESS ISPEXEC "SETMSG MSG(ISRZ000)"
 END
 ELSE
    OUT = INP1 + INP2
 "ISPEXEC DISPLAY PANEL (ADD)"
 CALL SUB
END

SUB:
"ISPEXEC VGET (ZPFKEY) ASIS"
IF ZPFKEY = "PF03" THEN
   EXIT RC
RETURN


ISPF Panel Code
PDS (IBMUSER.FADO.PANEL) Member name (ADD)

)ATTR
! TYPE(TEXT) INTENS(HIGH) CAPS(ON) PAD(NULLS) COLOR(GREEN) SKIP(ON)
$ TYPE(TEXT) INTENS(HIGH) CAPS(ON) PAD(NULLS) COLOR(BLUE) SKIP(ON)
¢ TYPE(TEXT) INTENS(HIGH) CAPS(ON) PAD(NULLS) COLOR(WHITE) SKIP(ON)
# TYPE(INPUT) INTENS(LOW) CAPS(ON) PAD('_') COLOR(YELLOW)
+ TYPE(TEXT) INTENS(LOW) SKIP(ON)
)BODY
%COMMAND ===>_ZCMD
+-------------------------------------------------------------------
+ $                      SAMPLE PANEL
+-------------------------------------------------------------------
+
+
+
+! ENTER THE FIRST  NUMBER   : #INP1 +
+! ENTER THE SECOND NUMBER   : #INP2 +
+
+
+
+!             THE SUM IS : #OUT +
+
+
+
+
+------------------------------------------------------------------
+              ¢F3=END            ¢<ENTER>=CONTINUE
)INIT
)PROC
   VER (&INP1,NONBLANK)
VPUT( INP1,INP2,OUT) PROFILE
VGET( INP1,INP2,OUT) PROFILE
)END

Tuesday, June 4, 2013

Download links for Rexx tutorial. The two pdf are available in Google, These are not my creation.

Download1

Download2

Monday, October 29, 2012

REXX Basics

Rexx Basics

1) Rexx Hello World Program:

/*REXX*/
Say ‘Hello World!!!’




1a) Debugging Rexx Program
Write the line "Trace R" at starting of program
/*REXX*/
Trace r

similarly Trace E and few more can be used to debug




2) Comments in Rexx:

/* single line comment */
/* multi line
   comment */


3) Split a line in Rexx / line continuation in Rexx:

Say ‘Use comma’,
‘To split a line’


4) Rexx code to accept input

Pull Name
Pull Age
Pull Gender
Pull Phoneno

/* Name, Age, Gender, Phoneno are variables */
/* There is no need of seperate declaration of varialbe in Rexx compared to C or any other lang */



5) Arithmetic Operators in Rexx

+    Add
-    Subtract
*    Multiply
/    Divide
%    Divide and return a whole number without a remainder
//    Divide and return the whole number only
**    Raise a number to a whole number power
-    -number (Negate the number)
+    +number (Add the number to 0)


6) Comparison Operators in Rexx

==    Strictly Equal
=    Equal
\==    Not Strictly Equal
\=    Not Equal
<>    Not Equal
>    Greater than
<    Less than
> <    Greater than or less than
> =    Greater than or equal to
< =    Less than or equal to


7)Logical Operators in Rexx



&    AND
|    OR
&&    Exclusive OR
\    NOT



8)Concatenation Operators in Rexx

Say a b         /* output is "a b" */
Phoneno = 1234567890
Say "+91"Phoneno /* output is +911234567890 */
Say "+91 "Phoneno /* output is +91 1234567890 */
Say "+91" Phoneno /* output is +91 1234567890 */
Say "+91"||Phoneno /* output is +911234567890 */ /*pipe char to make sure there is no space in between*/



9)IF/THEN/ELSE in Rexx

/* single line IF */
IF condition THEN
   instructions

/* multi line IF */
IF condition THEN DO
   instructions
   instructions
   instructions
END
-----------------------
IF condition THEN DO
   instructions
   instructions
END
ELSE
   instructions
-----------------------
IF condition THEN
   instructions
ELSE DO
   instructions
   instructions
END
-----------------------
IF condition THEN DO
   instructions
   instructions
END
ELSE DO
   instructions
   instructions
END
-----------------------
IF condition THEN DO
   instructions
   instructions
END
ELSE IF condition DO
   instructions
   instructions
END



10) Select Condition in Rexx

SELECT
    WHEN condition THEN instruction
    WHEN condition THEN instruction
    WHEN condition THEN instruction
.
.
.
    OTHERWISE
      instruction(s)
END



11) DO Loop in Rexx

Do 3
   Say "Number"
End

Do number = 1 to 10
   say "Number" number
End

Do Forever
   say "Loop is infinite"
End

Do While condition
   instructions
End

Do Until condition
   instructions
End




12) Exit a loop in Rexx

"Leave" & "Iterate" keywords

i = 0
Do Forever
   i = i + 1
   say "Loop is infinite"
   if i = 15 then
      Leave
End

i = 0
Do Forever
   i = i + 1
   say "Loop is infinite"
   if i = 15 then
      Iterate
End




13) Arrays in Rexx, Arrays are called as Stem in Rexx

Syntax : Name.
To set default value to all STEM variables use
Name. = "FADO"
All the stem variables will be initialised as FADO

Stem data starts from 1 but in arrays it starts from 0
Stem 0th contains the depth of the stem is valid to.
0th values is used in loops so you will know where the stem ends.

Name.1 = 1
Name.2 = 2

Name.0 = 2


If we dont know the number of items present in an stem we can use outtrap to set Name.0 by system

CALL OUTTRAP (‘Name.’)
“LISTC”

Multidimention stem

Name.1.1 = "Jack"
Name.1.2 = "John"
Name.1.1.1 = "Doe"



14) Subroutines in Rexx

Subroutines are called using CALL statement

CALL StrVal
Exit

StrVal:
Say "this is a subroutine"
Return


----------------------------------
/*REXX*/
Val1 = 5
Val2 = 3
CALL StrVal Val1 Val2
Say "Value returned from subroutine is stored in Result variable " Result
Parse Value Result with Var3 Var4 Var5
Exit

StrVal:
ARG Num1 Num2 /* parsing the input */
Say "this is a subroutine"
Say Num1
Say Num2
Num3 = Num1 + Num2
Num4 = Num1 - Num2
Num5 = Num1 * Num2
Return Num3 Num4 Num5
----------------------------------

The above code will work if this code is placed in a PDS or a PS

Or Place both the Main prog and the Subroutine StrVal in same PDS
but different member. Name the Subroutine member as StrVal
remove the first line StrVal as its of no use.

Rexx code to Create a PDS Member.

Rexx to Create a PDS Member.

FILE1 = 'USERMF.FADO.PDS(MEMBER1)'  

STEM1.1 = 1

STEM1.0 = 1 
 "ALLOC DA('"FILE1"') F(ABCD)  OLD REUSE"
 "EXECIO * DISKW ABCD (STEM STEM1. FINIS"
 "FREE F(ABCD)"
If RC <> 0 then Do
   say "Error in Allocating the PDS MEMBER" RC
End

/* Becarefull of the Quotes " and ' */

Rexx code to Create PDS (Partitioned Data Set)

Rexx to Create PDS (Partitioned Data Set).


FILE1 = 'USERMF.FADO.PDS'
ADDRESS TSO "ALLOCATE FI(ABCD) DA('"FILE1"') NEW TRACKS",
"REUSE SPACE(5,5) DIR(1) DSORG(PO) RECFM(F,B) LRECL(80) BLKSIZE(0)"
If RC <> 0 then Do
   say "Error in Allocating the PDS" RC
End

/* Becarefull of the Quotes " and ' */

REXX code to create a PS

Rexx to Create a PS dataset.

FILE1 = 'USERMF.FADO.PS'
ADDRESS TSO "ALLOCATE FI(ABCD) DA('"FILE1"') NEW TRACKS",
"REUSE SPACE(5,5) DIR(0) DSORG(PS) RECFM(F,B) LRECL(80) BLKSIZE(0)"
If RC <> 0 then Do
   say "Error in Allocating the PS" RC
End

/* Becarefull of the Quotes " and ' */

Sunday, October 21, 2012

REXX for Starters/Freshers - Hello World

1) Rexx Hello World Program:

/*REXX*/
Say ‘Hello World!!!’




Hello World Program Rexx code



To run a Rexx program type ex on the line command of the Rexx program



The output is displayed as show in the ISPF.