#48 oorexx file allocation deallocation

Classes (8)

i'v used mainframe rexx quite a bit & I am trying to get used to & learn oorexx on windows, and would appreciate bit of guidance as to how to go about reading a file (text, doc or xcel) and then write it out to a new file. I had a quick look in the sample directory as well as the ref guide, but could not work out how to allocate & read a file, & then write it out to a new one.

Writing an object oriented rexx is a new concept to me and I am keen to learn it, it will come handy in automating a lot of repatative tasks in my DBA role.

I would also appreciate any guidance about what oorexx instructions i will need in order to connect to an Oracle database for example in order to pass a select statement , and then read in the result set back in my program.

Many thanks in advance to all the feedback & comments.

John Alexander


  • Mark Miesfeld

    Mark Miesfeld - 2011-02-05

    In general in ooRexx on Windows you don't need to think to much about allocating and deallocating a file. ooRexx and Windows take care of the details for you.

    Provided you have a file named edit.xml in the current directory you can simply do this:

    inFile = "edit.xml"
    outFile = "editCopy.xml"

    do while lines(inFile) <> 0
    line = linein(inFile)
    ret = lineout(outFile, line)

    return 0

    In the above, ooRexx will open the files when you first use them and close the files when the program exits.

    I would use the .Stream class to do this and since you are interested in learning the object part of ooRexx here's a simple example:

    input = .Stream~new("edit.xml")
    output = .Stream~new("editCopy.xml")

    lines = input~makeArray
    do i = 1 to lines~items

    return 0

    Again in the above, ooRexx takes care of opeing and closing the files.

    .Stream is the Stream class, which is a builtin class in ooRexx. The Rexx Reference doc that is installed when you install ooRexx on Windows documents the Stream class in chapter 5 The Builtin Classes, specifically in 5.2.4

    The makeArray() method returns an Array object. The Array class is also a builtin class.

    ooRexx has a handy construct in 'do over' which can be used like this to read the lines in the input file:

    input = .Stream~new("edit.xml")
    output = .Stream~new("editCopy.xml")

    do line over input

    return 0

    which is esentially the same program as the one before it.

    Finally, you would normally do at least a little bit of error checking. This code also explicitly opens and closes the files. I usually explicity open and close my files in any program that I'm going to keep for more than a few minutes.

    input = .Stream~new("edit.xml")
    output = .Stream~new("editCopy.xml")

    if input~open == "READY:" & output~open == "READY:" then do
    do line over input
    else do
    say "Some unexpected problem opening the files."


    return 0

    The Rexx Reference is relatively good documentation. I'd read over the doc on the Stream class, the Array class, and on the do instruction. Array is in the same Builtin Classes chapter, in the section on Collection classes. The A Appendix has stuff on using do.

  • john alexander

    john alexander - 2011-02-16

    Appreciate any comments/feedback for this request , i'v changed the priority from 5 to 6 .

    Many Thanks in advance


  • john alexander

    john alexander - 2011-02-26

    Hi Mark
    Really appreciate you taking the time to give me a few hints on using Oorexx , this will give me something to work with, as I had no idea where to strart with this at all!.

    Kind Regards
    John Alexander



Cancel  Add attachments

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks