Showing posts with label File handling in rexx. Show all posts
Showing posts with label File handling in rexx. Show all posts

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>