Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#48 oorexx file allocation deallocation

Windows
closed
Mark Miesfeld
Classes (8)
6
2012-08-14
2011-02-05
john alexander
No

Hi,
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.

Regards
John Alexander

Discussion

  • 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)
    end

    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
    output~lineout(lines[i])
    end

    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
    output~lineout(line)
    end

    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
    output~lineout(line)
    end
    end
    else do
    say "Some unexpected problem opening the files."
    end

    input~close
    output~close

    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

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

    Many Thanks in advance

    John

     
  • 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

     


Anonymous


Cancel   Add attachments