Tuesday, February 23, 2016

THIS PROGRAM WILL COUNT THE NUMBER OF BYTES PRESENT IN A VALUE RANGE

/*                     REXX PROGRAM                             */

/*--------------------------------------------------------------*/

/*  THIS PROGRAM WILL COUNT THE NUMBER OF BYTES PRESENT IN      */

/*  A RANGE OF INPUT ( BOUNDED BY THE LINE COMMAND 'C' OR 'CC').*/

/*  THE OUTPUT WILL BE DISPLAYED ON THE UPPER RIGHT SIDE OF THE */

/*  SCREEN.         */

/*to run: ALTLIB ACT APPL(CLIST) DS('T01.E014806.CLIST')     */

/*ALLOC FI(SYSEXEC) DA('t01.e014806.clist') SHR REUSE*/

                                           

/*--------------------------------------------------------------*/

/* TRACE I*/

SUM   = 0

VALUE = 0

OCC_1_LVL   = 99

OCC_1_TIMES = 1

OCC_2_LVL   = 99

OCC_2_TIMES = 1

OCC_3_LVL   = 99

OCC_3_TIMES = 1

OCC_4_LVL   = 99

OCC_4_TIMES = 1

OCC_5_LVL   = 99

OCC_5_TIMES = 1

ADDRESS ISREDIT

   'ISREDIT MACRO NOPROCESS'

ADDRESS ISPEXEC

   'ISPEXEC CONTROL ERRORS RETURN'

ADDRESS ISREDIT

   'ISREDIT PROCESS RANGE C CC'

SELECT

  WHEN RC = 4 THEN

    DO

      ZEDSMSG = 'ENTER C OR CC'

      ZEDLMSG = 'ENTER A C OR CC ON LINE'

      ADDRESS ISPEXEC

         'ISPEXEC SETMSG MSG(ISRZ001)'

      EXIT 12

    END

  WHEN RC > 4 THEN

      EXIT RC

  OTHERWISE NOP

END

/* GET FIRST AND LAST LINE OF THE INPUT */

ADDRESS ISREDIT

  'ISREDIT (FIRST) = LINENUM .ZFRANGE'

  'ISREDIT (LAST)  = LINENUM .ZLRANGE'

PREV_REC = ''

DO LPTR = FIRST TO LAST

   ADDRESS ISREDIT

    'ISREDIT (REC) = LINE' LPTR

   /*   LINE IS COMMENTED OUT  */

   IF SUBSTR(REC,7,1) = '*' THEN

      DO

         ITERATE

      END

   /* OMIT LINE 1-7 AND 73-80 */

   REC = SUBSTR(REC,8,65)

   /* SAY 'REC =' REC  */

   WORD_CNT = WORDS(REC)

   IF WORD_CNT = 0 THEN

      ITERATE

   /*  THIS CHECKS IF LAST CHAR IN THE RECORD IS A PERIOD */

   IF SUBSTR(WORD(REC,WORD_CNT),WORDLENGTH(REC,WORD_CNT),1) ^= '.' THEN

      DO

         PREV_REC = PREV_REC || ' ' || REC

         ITERATE

      END

   ELSE

      DO

         REC = PREV_REC || ' ' || REC

         PREV_REC = ''

      END

   /*   GET LEVEL NUMBER               */

   LEVEL = WORD(REC,1)

   /* SAY 'LVL=' LEVEL */

   IF LEVEL = 88 THEN

      ITERATE

   CALL CLEAN_UP_OCCURS_ARRAY     /*  INITIALIZE OCCURS ARRAY IF   */

                                  /*  POSSIBLE DUE TO NEW LEVEL NO */

   /*   CHECK IF PART OF A REDEFINES   */

   IF REDEFINES_ACTIVE = 'YES' THEN

      DO

         IF LEVEL > REDEFINES_LEVEL THEN

            ITERATE

         ELSE

            REDEFINES_ACTIVE = 'NO'

      END

   /*   LINE IS A REDEFINES LINE */

   IF INDEX(REC,' REDEFINE ')  > 0,

   |  INDEX(REC,' REDEFINES ') > 0 THEN

      DO

         REDEFINES_ACTIVE = 'YES'

         REDEFINES_LEVEL = LEVEL

         ITERATE

      END

   /*   LINE IS AN OCCURS LINE */

   IF INDEX(REC,' OCCURS ') > 0,

   |  INDEX(REC,' OCCUR ')  > 0 THEN

      CALL SAVE_OCCURS_IN_ARRAY      /* INITIALIZE OCCURS ARRAY IF   */

                                     /* POSSIBLE DUE TO NEW LEVEL NO */

   /*   GET POSITION OF 'PIC'  */

   PIC_POS = WORDPOS(' PIC ',REC)

   IF  PIC_POS = 0 THEN

       /*   GET POSITION OF 'PICTURE'  */

       PIC_POS = WORDPOS(' PICTURE ',REC)

   IF PIC_POS = 0 THEN

      DO

         VALUE = 0

      END

   ELSE

      DO

         /*   GET VALUE AFTER 'PIC'  */

         PIC_VALUE_WORD = WORD(REC,PIC_POS + 1)

         VALUE = 0

         CALL PIC_VALUE

      END

/* SAY '#1' LEVEL OCC_1_LVL OCC_1_TIMES  */

/* SAY '#2' LEVEL OCC_2_LVL OCC_2_TIMES  */

/* SAY '#3' LEVEL OCC_3_LVL OCC_3_TIMES  */

/* SAY '#4' LEVEL OCC_4_LVL OCC_4_TIMES  */

/* SAY '#5' LEVEL OCC_5_LVL OCC_5_TIMES  */

   IF LEVEL > OCC_1_LVL,

    | (   LEVEL = OCC_1_LVL,

        & LPTR  = OCC_1_LINE ) THEN

      VALUE = VALUE * OCC_1_TIMES

   IF LEVEL > OCC_2_LVL,

    | (   LEVEL = OCC_2_LVL,

        & LPTR  = OCC_2_LINE ) THEN

      VALUE = VALUE * OCC_2_TIMES

   IF LEVEL > OCC_3_LVL,

    | (   LEVEL = OCC_3_LVL,

        & LPTR  = OCC_3_LINE ) THEN

      VALUE = VALUE * OCC_3_TIMES

   IF LEVEL > OCC_4_LVL,

    | (   LEVEL = OCC_4_LVL,

        & LPTR  = OCC_4_LINE ) THEN

      VALUE = VALUE * OCC_4_TIMES

   IF LEVEL > OCC_5_LVL,

    | (   LEVEL = OCC_5_LVL,

        & LPTR  = OCC_5_LINE ) THEN

      VALUE = VALUE * OCC_5_TIMES

/* SAY 'VALUE = ' VALUE */

   SUM = SUM + VALUE

END

/* SAY SUM */

ZEDSMSG = SUM || ' BYTE(S)'

ZEDLMSG = 'TOTAL NUMBER OF BYTE(S) IS' SUM

ADDRESS ISPEXEC

   'ISPEXEC SETMSG MSG(ISRZ001)'

EXIT

/*************************/

/*    END OF PROGRAM     */

/*************************/


/*************************/

/*  ROUTINE TO COUNT THE */

/*  PICTURE IN A LINE    */

/*************************/

PIC_VALUE:

   VALUE = 0

   VALUE_IN_PAREN = 0

   DO W1 = 1 TO LENGTH(PIC_VALUE_WORD)

      /* SAY    SUBSTR(PIC_VALUE_WORD,W1,1)  */

      SELECT

        WHEN SUBSTR(PIC_VALUE_WORD,W1,1) = ' ' THEN

           ITERATE

        WHEN LOOK_FOR_CLOSE_PAREN = 'YES' THEN

           DO

              IF SUBSTR(PIC_VALUE_WORD,W1,1) ^= ')' THEN

                 ITERATE

              ELSE

                 DO

                    LOOK_FOR_CLOSE_PAREN = 'NO'

                    ITERATE

                 END

           END

        WHEN SUBSTR(PIC_VALUE_WORD,W1,1) = 'S' THEN

              DO

                ITERATE

              END

        WHEN SUBSTR(PIC_VALUE_WORD,W1,1) = 'V' THEN

              DO

                ITERATE

              END

        WHEN SUBSTR(PIC_VALUE_WORD,W1,1) = '(' THEN

           DO

             VALUE = VALUE - 1

             OPEN_PAREN_FOUND = 'YES'

             ITERATE

           END

        WHEN OPEN_PAREN_FOUND = 'YES' THEN

           DO

             RPAREN_POS = INDEX(PIC_VALUE_WORD,')',W1)

             VALUE_IN_PAREN = SUBSTR(PIC_VALUE_WORD,W1,RPAREN_POS - W1)

             VALUE = VALUE + VALUE_IN_PAREN

             OPEN_PAREN_FOUND = 'NO'

             LOOK_FOR_CLOSE_PAREN = 'YES'

             ITERATE

           END

        WHEN SUBSTR(PIC_VALUE_WORD,W1,1) = '.' THEN

           DO

              IF W1 = LENGTH(PIC_VALUE_WORD) THEN

                 DO

                    ITERATE

                 END

              ELSE

                VALUE = VALUE + 1

           END

      OTHERWISE VALUE = VALUE + 1

      END

   END

   /* SAY 'VALUE = ' || VALUE */

   IF SUBSTR(PIC_VALUE_WORD,1,1) = 'S',

    | SUBSTR(PIC_VALUE_WORD,1,1) = 'V',

    | SUBSTR(PIC_VALUE_WORD,1,1) = '9' THEN

      DO

         SELECT

            WHEN INDEX(REC,' COMP ')   > 0,        /* COMP OR COMP-4 */

             |   INDEX(REC,' COMP.')   > 0,

             |   INDEX(REC,' COMP-4 ') > 0,

             |   INDEX(REC,' COMP-4.') > 0 THEN

               DO

                  SELECT

                     WHEN VALUE <= 4 THEN

                        VALUE  = 2

                     WHEN VALUE <= 9 THEN

                        VALUE  = 4

                     OTHERWISE

                        VALUE  = 8

                  END

               END

            WHEN INDEX(REC,' COMP-3 ') > 0,        /* COMP-3 */

             |   INDEX(REC,' COMP-3.') > 0 THEN

               VALUE = (VALUE % 2) + 1

            WHEN INDEX(REC,' COMP-1 ') > 0,        /* COMP-1 */

             |   INDEX(REC,' COMP-1.') > 0 THEN

               VALUE = 4

            WHEN INDEX(REC,' COMP-2 ') > 0,        /* COMP-2 */

             |   INDEX(REC,' COMP-2.') > 0 THEN

               VALUE = 8

            OTHERWISE NOP

         END

      END

RETURN

/*   END OF PIC_VALUE ROUTINE     */


/*************************/

/*  ROUTINE TO CLEAN UP  */

/*  THE OCCURS ARRAY     */

/*************************/

CLEAN_UP_OCCURS_ARRAY:

   IF LEVEL <= OCC_1_LVL THEN

      DO

         OCC_1_LVL   = 99

         OCC_1_TIMES =  1

         OCC_1_LINE  =  0

      END

   IF LEVEL <= OCC_2_LVL THEN

      DO

         OCC_2_LVL   = 99

         OCC_2_TIMES =  1

         OCC_2_LINE  =  0

      END

   IF LEVEL <= OCC_3_LVL THEN

      DO

         OCC_3_LVL   = 99

         OCC_3_TIMES =  1

         OCC_3_LINE  =  0

      END

   IF LEVEL <= OCC_4_LVL THEN

      DO

         OCC_4_LVL   = 99

         OCC_4_TIMES =  1

         OCC_4_LINE  =  0

      END

   IF LEVEL <= OCC_5_LVL THEN

      DO

         OCC_5_LVL   = 99

         OCC_5_TIMES =  1

         OCC_5_LINE  =  0

      END

RETURN

/*   END OF CLEAN_UP_OCCURS_ARRAY ROUTINE     */


/*************************/

/*  ROUTINE TO SAVE IN   */

/*  OCCURS ARRAY         */

/*************************/

SAVE_OCCURS_IN_ARRAY:

   OCCURS_WORD_POS = WORDPOS(' OCCURS ',REC)

   IF OCCURS_WORD_POS = 0 THEN

      OCCURS_WORD_POS = WORDPOS(' OCCUR ',REC)

   TIMES = WORD(REC,OCCURS_WORD_POS + 1)

   DO

      SELECT

         WHEN OCC_1_LVL = 99 THEN

            DO

               OCC_1_LVL   = LEVEL

               OCC_1_TIMES = TIMES

               OCC_1_LINE  = LPTR

            END

         WHEN OCC_2_LVL = 99 THEN

            DO

               OCC_2_LVL   = LEVEL

               OCC_2_TIMES = TIMES

               OCC_2_LINE  = LPTR

            END

         WHEN OCC_3_LVL = 99 THEN

            DO

               OCC_3_LVL   = LEVEL

               OCC_3_TIMES = TIMES

               OCC_3_LINE  = LPTR

            END

         WHEN OCC_4_LVL = 99 THEN

            DO

               OCC_4_LVL   = LEVEL

               OCC_4_TIMES = TIMES

               OCC_4_LINE  = LPTR

            END

         WHEN OCC_5_LVL = 99 THEN

            DO

               OCC_5_LVL   = LEVEL

               OCC_5_TIMES = TIMES

               OCC_5_LINE  = LPTR

            END

         OTHERWISE

            SAY 'ERROR ===> ARRAY EXCEEDED (MORE THAN 5)'

      END

   END

RETURN

/*   END OF SAVE_OCCURS_IN_ARRAY ROUTINE     */

Monday, August 27, 2012

File Handling In Rexx

File handling or Dataset Handling in REXX is done Using it's EXECIO function's.


To write a Dataset in Rexx

Write Link


To Read a Dataset in Rexx

Read Link


How To Write a Dataset In Rexx



Writing a file in REXX is a kind of a easy job . Generally we have to store all the lines which we want to WRITE in an array. And Once we are done with what we want to write in an array we can write it into a PS or member of PDS.



  • Initializing  (i.e Array.="") the array which we are going to write is a very good practice.
  • At times you end up with writing errors if we don't initialize the array.
  • You can load any number of arrays and write one array in one or more dataset by repeating the dataset syntax for various PS or PDS.
       

                      "ALLOC FI(LNAME) DA('MY.PS.WRITE') SHR"
                      "EXECIO * DISKW LNAME(STEM ARRAY. FINIS"

                      "FREE FI(LNAME)"


      • Where LNAME is the logical name of the dataset 'MY.PS.WRITE'.

      •  Finally it is a good practice to free the file you are writing.

      •  Now you could also write the same array into a different Dataset in the same REXX program.

                      "ALLOC FI(LNAME) DA('MY.PS.WRITE.NEW') SHR"
                      "EXECIO * DISKW LNAME(STEM ARRAY. FINIS"
                      "FREE FI(LNAME)"

Saturday, July 28, 2012

How To Read a Dataset In REXX


File handling is REXX is one of the most easiest thing to do. The file reading in rexx is done in a line by line reading format. For example this the below happens when a dataset in read in rexx


  • Each line of the Dataset is stored in each subscript in a array . For example array.1 will have the first line of the dataset and array.2 will have the second one and so on.
  • The total number of lines read will be available in array.0 variable which will be used to used to loop through the lines.
  • Below is the example how to read a dataset 'MY.PS.READ' into array.
           

                      "ALLOC FI(LNAME) DA('MY.PS.READ') SHR"
                      "EXECIO * DISKR LNAME(STEM ARRAY. FINIS"

                      "FREE FI(LNAME)"
      • Where LNAME is the logical name of the dataset 'MY.PS.READ'.

      •  Finally it is a good practice to free the file you are reading

      •  Now if you want to display all the contents within the array can use this code.

                            DO I=1 TO ARRAY.0
                                  SAY ARRAY.I
                                         END



<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33389906-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

Saturday, July 7, 2012

How To Create a Dataset In Rexx


Hi folks,

It becomes necessary for us to create dataset for many programming purpose.As creating a dataset using rexx is easy , I am just placing the code to create dataset in rexx.

Due to Security issues we are often allowed to create datasets only starting with the our TSO sign on ID. Thats's the reason why i have created the dataset with the TSO logon id and then i have later altered to the Dataset name which we actually wanted.

/*************** REXX at REXXPROGRAMMING.BLOGSPOT.COM***************/
USER_ID = USERID()
ACTUAL_PDS_NAME ='ACTUAL.PDS,NAME'
PDS_NAME_TO_ALTERED= USER_ID||".PDS.NAME "
   "ALLOCATE DATASET('"PDS_NAME_TO_ALTERED"') CATALOG LRECL (80),           BLKSIZE(27920) RECFM(F B) DSORG(PO) TRACKS SPACE(1 5) DIR(30)"

         "ALTER '"
PDS_NAME_TO_ALTERED "' NEWNAME('"ACTUAL_PDS_NAME"')"


EXIT.


This Should result in Creating a Dataset Named 'userid(tso id).pds.name' and altered to 'actual.pds.name'



<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33389906-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

How To Check If a Dataset Already Exist In REXX Programming


Folks,

       At times we are in need to know if few datasets already exist in HOST.It's a very easy piece of code that would help us to know if dataset exist or not.


/***************REXX AT REXXPROGRAMMING.BLOGSPOT.COM***************/

 IF SYSDSN("dataset.name") = "OK" THEN
    DO
            SAY "DATASET EXISTING"
    END
   ELSE
   DO

SAY "DATASET DOES NOT EXIST"

END
EXIT

where 'dataset,name' is the dataset to be checked for existence.



<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33389906-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

Monday, June 25, 2012

Rexx Program To Display a ISPF PANEL




hi folks,


This a sample piece of Code how to display a ISPF Panel Using Rexx.


/******************* REXX AT REXXPROGRAMMING.BLOGSPOT.COM*************************/
 ADDRESS ISPEXEC                                                     
 "LIBDEF ISPPLIB DATASET ID('YOUR.PANELPDS.NAME')"  


ADDRESS ISPEXEC                
 "DISPLAY PANEL(PANELNAME)"
EXIT


Where PANELNAME is the member inside YOUR.PANELPDS.NAME.

How To Call ISPF Panels From REXX PROGRAM



Hi folks,


      Create a panel and keep it in a separate PDS which is called 'ISPF PANEL LIBRARY'

In the Rexx program add the library using this piece of code


/*************** Rexx At REXXPROGRAMMING.BLOGSPOT.COM***************/

"ispexec libdef ispplib library id (PANEL.PDS.NAME)"

After this you can call using

"ispexec display panel(PANEL.MEMBER.NAME)"


Exit


Where


PANEL.PDS.NAME              - Is the PDS name where the panel actually exist
PANEL.MEMBER.NAME    - The member name  inside PANEL.PDS.NAME






Friday, February 24, 2012

Differences Between Mainframe rexx and Regina Rexx

There is Not much differences between Regina rexx and mainframe rexx, A person able to program any one of the rexx program could manage both and use both the forms uniformly.


Both the forms has its own advantages. Mainframe rexx has more powerful tools than Regina rexx. Take for example it can submit jcl's, Create or delete  PS,PDS and could execute any TSO command . In future posts i will be explaining all the possible commands in both Regina and mainframe rexx.

Thursday, February 23, 2012

Rexx Programming Basics

Hi Folks,


              To start from the scratch . Rexx programming is done to basically automate few regular and frequent operations on data. Not restricting to Main Frame it can be used to create tools for any language. A simple example would be if there is a need to change a pin code starting with 145 to 551 which is repeated a 1000 times in your data. You can write a Rexx tool to change everything in seconds. But there's lot interesting in Rexx to do. One of the foremost thing to note in rexx is there is no kind of a syntax , data type declaration in Rexx. So its easy to learn learn. So common lets REXX!!!




Rexx Language is NOT case sensitive.Rexx Programming is mostly used in conversions , SQL Query generation with a set of input's you have. To write a set of mathematical instructions and execute it for all the data you. Going forward I will Post basic Program's in Rexx. And the various places you can use rexx and benefit using this very easy programming language.