Re: CoBOL moved to OO

From: Judson McClendon (judmc_at_sunvaley0.com)
Date: 01/01/04


Date: Thu, 01 Jan 2004 11:25:21 GMT

Thanks for the code Jimmy, it's very interesting and I saved it for future
reference. :-)

But I have not communicated well. I am not seeking a program, module,
component, or any created thing, either OO, procedural or spaghetti
source code, or binary machine language. ;-) I can easily write source
code to do this programmatically. What I am asking for (with good
reason) is *a series of manual steps I can do at the keyboard* to
produce, using only the Windows GUI, the same effect as entering a
command similar to this from the command prompt:

    dir "d:\???0716*.*" /a/b >files.txt

(If the answer is "you can't do that", then don't bother reading further. :)

That particular wildcard is only an example, in use it would vary. In fact,
I believe it is essentially impossible to produce *any* 'text file consisting
of a list of file names' by using the Windows GUI and the keyboard alone
with no programming, wildcards or no. I can produce a graphic file, or a
printed listing of file names, by displaying them in an Explorer window,
pressing 'Print Screen', pasting the clipboard into a picture editor, then
printing or saving the image. One could, I suppose, use OCR to take the
image and convert to text, but that is extreme clunky, limited number of
file names and no wildcards. Creating a file of file names is a very useful
thing that I do quite a lot. Not in systems, where I would write code to do
it, but ad hoc from the keyboard when I am using the PC for various tasks.
I know of no way to do this, other than using the command prompt or
writing a program or using an already written program of some sort to do
the same thing. I made the comment initially as an example of when the
Windows GUI isn't sufficient. And in the same vein, I also suggested
another common and useful thing the Windows GUI cannot do, AFAIK.
To produce the same effect as entering a command similar to this from the
command prompt:

    ren *.txt *.doc

These examples of what (I believe) the Windows GUI simply cannot be
used to achieve (from the keyboard, without additional programming), are
such common and useful tasks that, if it CAN be done using the Windows
GUI, I would really like to know how. Others have asked me this same
question on several occasions, so I know I'm not the only one who could
use such a method.

The reason I ask here is that, when I mentioned these as insufficiencies
in the Windows GUI, Pete responded that it could be done, only I was
using different methods. I'm not challenging Pete's comments, but it
would be very useful to me if it can be done. So, can it be done, and
how? I would really, really like to know. :-)

Whew! Was I clear this time? :-)

-- 
Judson McClendon      judmc@sunvaley0.com (remove zero)
Sun Valley Systems     http://sunvaley.com
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."
"James J. Gavan" <jjgavan@shaw.ca> wrote:
>
> Judson McClendon wrote:
>
> > "Peter E.C. Dashwood" <dashwood@enternet.co.nz> wrote:
> > >
> > > "Judson McClendon" <judmc@sunvaley0.com> wrote:
> > > > Pete, this isn't a challenge. If you know how to do this, please tell me,
> > > > I could really use the technique. :-)
> > >
> > > I do know how to do it, and anyone who is familiar with the use of OO
> > > components and controls could work out how to do it in a few minutes. It can
> > > be done by combining standard Windows components on a standard Windows Form.
> > >
> > > For my own part, I would then wrap the result as a component and the
> > > functionality can then be deployed in Windows applications or on Web Pages
> > > using OO web scripting (ASP, f'r'instance).
> > >
> > > You are expecting to see a block of procedural code that you can use.
> >
> > No, I was expecting a series of steps. I was referring to the Windows
> > GUI, not the Windows API. :-)  Here is the exchange:
> >
> > Pete:
> > > Jud:
> > > > Windows GUI interface
> > > > is nice in many ways, but clunky in others, requiring a console interface
> > > > for things such as creating a text file listing all files named "???0716*.*"
> > > > on partition "D:".
> > >
> > > This can be done with a GUI interface; it is just that the way you choose to
> > > do it is more familiar to you.
> >
> > Perhaps we were just mis-communicating. Doing this in a program is
> > no problem. But I have been unable to find a way to do it using the
> > Windows GUI without reverting to the commend prompt. It's trivially
> > easy using the command prompt:
> >
> >     dir "d:\???0716*.*" /a/b >files.txt
> >
> > If you can do this ad hoc from the GUI, I will be truly impressed. :-)
> >
> > Here's another one. You can do this file by file in the GUI, but if there
> > are lots of files, it is a pain:
> >
> >     ren *.txt *.doc
> >
> > Try this. In a WinXP Explorer window select several (disposable!) files,
> > press F2, and change the name of one. I'm not sure what they are trying to
> > do, but I haven't found it useful. :-)
>
> Well the obvious thing with your Drive D search would be to tell you - "Do your own
> homework" <G>.
>
> Anyway, just this once you get lucky, because it's something I had written a while
> back - you have to RESEARCH tools  based on current NEED - so unfair to expect Pete
> to pull a rabbit out of his hat when he doesn't have a current need..
>
> I'm glad you clarified your original search Drive D using a wildcard to :-
>
>     dir "d:\???0716*.*" /a/b >files.txt
>     ren *.txt *.doc
>
> Read below - you can achieve both the above.
>
> Using the Demo GUI samples create a dialog with an entry field for your wildcard,
> (including your drive D), and a Listbox, (Ordered not Sorted) if you want to to
> display the result of the "search". Depending on what you want - single or
> multi-select  from the Listbox and use Pushbuttons for your choices, 'Copy",
> "Delete", 'Rename" etc.
>
> Alternatively write the collection elements to your text file with a Callback (see
> below). Note the following code does NOT use GUIs - that's for you to do as
> described above.
>
> I've written an OO trigger program to get you started : -
>
> *>--------------- startwildcard.cbl--------------------------
>
> Program-id. StartWildcard.
>
> Class-control.          Filenames2  is class "filenam2"
>                         .
>
> WORKING-STORAGE SECTION.
> 01 charx                    pic x.
> 01 ws-length                pic x(4) comp-5.
> 01 Pathname pic x(18) value "C:\ucs\1-bin\*.bak".
>
> *>***** substitute your wildcards as appropriate
>
> *> OBJECTS
> 01 os-Filenames         object reference value null.
> 01 os-SortedCollection  object reference value null.
>
> Procedure Division.
>
> compute ws-Length = function length (Pathname)
>
> *> 1 - Do the Delete first
>
> invoke FileNames2 "new" returning os-Filenames
> invoke os-FileNames "deleteUsingWildcard"
>        using ws-Length, Pathname
>
> *> 2 - return a list of filenames
>
> inspect Pathname replacing all "bak" by "cpy"
> invoke os-FileNames "getFilenamesWithWildcard"
>        using ws-Length, Pathname
>        returning os-SortedCollection
>
> if os-SortedCollection <> null
>    invoke os-SortedCollection "display"
>    *> gives you a DOS text window with names wrapped around -
>    *> useful for testing only
>
> else display "No files found"
> End-if
>
> accept charx
> invoke os-Filenames "finalizeObjects"
>
> if os-SortedCollection <> null
>    invoke os-SortedCollection "deepfinalize"
>    returning os-SortedCollection
> End-if
>
> STOP RUN.
> *>-----------------------------------------------------------
>
> *>------------------ filenam2.cbl --------------------------
>
> *> Some Notes on what's going on :-
>
> *> Although I'm using both Ordered and Sorted Collections I
> *> make no reference to the first in Class-control. It is the M/F
> *> class 'Filename' that establishes a link to Ordered
> *> Collection. I now have within this class (Filename2)
> *> the properties/methods for an OrderedCollection.
> *> The SortedCollection class is listed so that I can invoke to
> *> create a SortedCollection and then fill it with elements
> *> from the OrderedCollection.
> *>
> *> When deleting files I could use "perform varying n from 1
> *> by 1 until n > CollectionSize'; instead I use Callbacks.
>
> *> Callbacks can be used with collecions, GUI classes or the
> *> ExceptionManager. When used with collections there are four
> *> method names that allow selectivity :-
>
> *> invoke aCollection "do" using Methodname(obj ref)
> *>                    "select"
> *>                    "reject"
> *>                    "collect"
>
> *> Having created a reference to a callback method (which could
> *> be generated in another class), I then 'invoke
> *> aCollection "do" using Methodname'. Alredy knowing the
> *> size of the collection (elements) the Callback iterates
> *> through each element. If I want to 'break out of the
> *> callback' :-
>
> *>      if this is not condition I want
> *>           invoke aCollection "quitIteration"
> *>           EXIT METHOD
> *>      end-if
> *>
> *> The "quitIteration" is triggerd on the CollectionObject,
> *> NOT the callback method
> *>
> *> I'm using Collections 'ofReferences'. In the case of
> *> method "getFilenamesUsingWildcard" the elements in the collec-
> *> tion are objects for displaying in a Listbox - the altenative
> *> is to 'translate' them to text 'strings', if you wanted
> *> to include a set of files to be zipped.
>
> *>--------------------------------------------------------------
>
> Class-id.       FileNames2
>                 inherits from Base.
>
> Class-control.  FileNames2           is class "filenam2"
>
>                 Callback             is class "callback"
>                 CharacterArray       is class "chararry"
>                 FileName             is class "filename"
>                 SortedCollection     is class "srtdclln"
> .
>
> *> Coded as a separate class so that more methods can be
> *> added later
>
> *>--------------------------------------------------------------
> FACTORY.
> *>--------------------------------------------------------------
> Method-id. "new".
> *>--------------------------------------------------------------
> Linkage Section.
> 01 lnk-self                     object reference.
> Procedure Division returning lnk-self.
>   invoke super "new" returning lnk-self
> End Method "new".
> *>-------------------------------------------------------------
> END FACTORY.
> *>-------------------------------------------------------------
> OBJECT.
> *>--------------------------------------------------------------
> WORKING-STORAGE SECTION.
> 01 charx                    pic x.
> 01 ws-length                pic x(4) comp-5.
> 01 ws-size                  pic x(4) comp-5.
> 01 ws-WildCardName.
>    05 pic x occurs 1 to 100 depending on ws-length.
>
> *> OBJECTS
>
> 01 os-CallbackDefaultSort      object reference value null.
> 01 os-CallbackDeleteFile       object reference value null.
> 01 os-SortedCollection         object reference value null.
> 01 os-TempCollection           object reference value null.
>
> *> NOTE : Methods are listed in alphabetical order
>
> *>-------------------------------------------------------------
> Method-id. "CallbackDefaultSort".
> *>-------------------------------------------------------------
> Local-storage section.
> 01 ls-bytes                  pic x(4) comp-5.
> 01 ls-string                 object reference.
> 01 ls-text1                  pic x(100).
> 01 ls-text2                  pic x(100).
>
> Linkage Section.
> 01 lnk-Element                      object reference.
>
> Procedure Division using lnk-Element.
>
>    invoke lnk-element "sizeinbytes" returning ls-bytes
>    invoke lnk-element "getValue"    returning ls-text1
>    move ls-text1(1:ls-bytes)        to ls-text2
>    invoke CharacterArray "withLengthValue"
>           using     ls-bytes, ls-text2
>           returning ls-string
>    invoke os-SortedCollection "add" using ls-string
>
> *> Rather than above coding - you would have thought the
> *> following would work - but it doesn't !
>
> *>   invoke os-SortedCollection "add" using lnk-element
>
> *> When querying lnk-element with the Animator it shows
> *> 'search criteria' used with the wildcard ????
>
> End Method "CallbackDefaultSort".
> *>-------------------------------------------------------------
> Method-id. "CallbackDeleteFile".
> *>-------------------------------------------------------------
> Local-storage section.
> 01 ls-filename                      pic x(100).
> 01 ls-StatusCode                    pic x(4) comp-5.
> Linkage Section.
> 01 lnk-Element                      object reference.
> Procedure Division using lnk-Element.
>
> invoke lnk-Element "getValueZ" returning ls-filename
> call "CBL_DELETE_FILE" using     ls-filename
>                        returning ls-StatusCode
>
> *> I could check the ls-StatusCode and as necessary do a
> *> "quiteIteration"
>
> End Method "CallbackDeleteFile".
> *>-------------------------------------------------------------
> Method-id. "checkFiles".
> *>-------------------------------------------------------------
> Local-storage section.
> 01 ls-size                          pic x(4) comp-5.
> 01 ls-string                        object reference.
>
> Procedure Division.
>
> invoke CharacterArray "withLengthValue"
>         using     ws-length
>                   ws-WildCardName
>         returning ls-string
>
> invoke FileName "expandwildcards"
>        using     ls-string
>        returning os-TempCollection
>
> invoke os-TempCollection "size" returning ws-size
>
> if   ws-size <> zeroes
>      display "This is the Ordered Collection"
>      invoke os-TempCollection "display"
>      accept charx
>
>      invoke SortedCollection "ofReferences"
>          using     ws-size
>          returning os-SortedCollection
>      invoke Callback "new"
>          using     self "CallbackDefaultSort "
>          returning os-CallbackDefaultSort
>      invoke os-TempCollection "do" using os-CallbackDefaultSort
>
> *>   As yet the next line doesn't work - it was another attempt at
> *>  a shortcut
> *>   invoke os-SortedCollection "addAll" using os-TempCollection
>      display "This is the Sorted Collection"
>      invoke os-SortedCollection "display"
>      accept charx
>
> End-if
>
> *> Invoking the collections to 'display' is really only useful
> *> to test - all you get is a wrap-around in a DOS text window
>
> End Method "checkFiles".
> *>-------------------------------------------------------------
> Method-id. "deleteUsingWildcard".
> *>-------------------------------------------------------------
> Linkage section.
> 01 lnk-length                pic x(4) comp-5.
> 01 lnk-WildCardName.
>    05 pic x occurs 1 to 100 depending on lnk-length.
>
> Procedure Division using lnk-length lnk-WildCardName.
>
> move lnk-length       to ws-Length
> move lnk-WildcardName to ws-WildcardName
> invoke self "checkFiles"
>
> if   ws-size <> zeroes
>      invoke Callback "new"
>             using     self "CallbackDeleteFile "
>             returning os-CallbackDeleteFile
>      invoke os-SortedCollection "do"
>             using os-CallbackDeleteFile
> End-if
>
> End Method "deleteUsingWildcard".
> *>---------------------------------------------------------------
> Method-id. "finalizeObjects".
> *>-------------------------------------------------------------
> *> os-CallbackDefaultSort
> *> os-CallbackDeleteFile
> *> os-SortedCollection........finalized in Business Logic
> *> os-TempCollection
>
>
> if os-CallbackDefaultSort <> null
>    invoke os-CallbackDefaultSort "finalize"
>    returning os-CallbackDefaultSort
> End-if
>
> if os-CallbackDeleteFile <> null
>    invoke os-CallbackDeleteFile "finalize"
>    returning os-CallbackDeleteFile
> End-if
>
>
> if os-TempCollection <> null
>    invoke os-TempCollection "finalize"
>    returning os-TempCollection
> End-if
>
> End Method "finalizeObjects".
> *>-------------------------------------------------------------
> Method-id. "getFilenamesWithWildcard".
> *>-------------------------------------------------------------
> Linkage section.
> 01 lnk-length                pic x(4) comp-5.
> 01 lnk-WildCardName.
>    05 pic x occurs 1 to 100 depending on lnk-length.
> 01 lnk-SortedCollection      object reference.
>
> Procedure Division using     lnk-length
>                              lnk-WildCardName
>                    returning lnk-SortedCollection.
>
>  move lnk-Length       to ws-Length
>  move lnk-WildcardName to ws-WildcardName
>  invoke self "checkFiles"
>
>  if ws-Size <> zeroes
>     set lnk-SortedCollection to os-SortedCollection
>
>  else set lnk-SortedCollection to null
>  End-if
>
> End Method "getFilenamesWithWildcard".
> *>---------------------------------------------------------------
>
> End OBJECT.
> End CLASS FileNames2.
>
> *>--------------------------------------------------------------
>
> I made minor changes to the above and would have liked to write the conversion from
> Ordered to Sorted Collectiuon in shorthand - whichever I tried, didn't work. Doesn't
> mean the M/F support classes don't work - just that yours truly hasn't got the hang
> of it. So we are back to the researching of new tools - and I'll be making some
> queries in Answer Exchange to resolve my gaffes.
>
> To finish, using one of BIll's pet phrases, "And having said that.....".,  I think I
> would be likely to have more luck in converting you to Catholicisim than converting
> you from Procedural to OO COBOL !!!
>
> Jimmy, Calgary AB