As the very first computer language I learned was COBOL, I have been always interested to learn about OO COBOL but never had the necessary time to research it.

Are there by any chance simple COBOL snippets that would demonstrate how to use OO COBOL to interact with Java (e.g. creating a Java object, invoking a simple method with arguments and fetch the returned value) and a comparable example for COBOL 6.4?

Maybe something like interacting with the Java runtime environment like this 
(in Java):

   import javax.script.*;

   class Test
   {
        public static void main (String args[])
        {
            ScriptEngineManager sem = new ScriptEngineManager();
            ScriptEngine        se  = sem.getEngineByName("rexx");
            String code   = "say 'Hello world from Rexx!';\n return 43";
            Object result = null;
            try
            {
                result=se.eval(code);
            }
            catch (ScriptException sexc)
            {
                System.err.println("Oops, ScriptException occurred: "+sexc);
            }
            System.out.println("script's result: "+result);
            System.exit(0);
        }
   }

 The above program actually works if BSF4ooRexx is installed and yields:

   G:\tmp\bsf4oorexx\cobol>java Test
   REXXout>Hello world from Rexx!
   script's result: 43

The documentation of the Java scripting framework's javax.script package can be found here: <https://docs.oracle.com/javase/8/docs/api/javax/script/package-summary.html> .

---

It would be really interesting to see how one would use OO COBOL and COBOL 6.4 to interact with the Java runtime environment and e.g. exploit the Java scripting framework.

---rony

P.S.: SOM has been a very interesting and exciting technology and I always have found it a little bit sad that it was abandoned. It was possible in the OS/2 days to subclass the WPS SOM folder class in Object REXX and add password access protection to it in about 15 lines of Object Rexx code, it was just great (and for many to this day unbelievable  how easy and how powerful that was).


On 29.05.2023 00:40, Tom Ross wrote:
Hi, While working on the earlier problems I had, I ran into the concepts=20
of COBOL Methods and Classes, and understand they can be used for Java=20
in addition to regular COBOL programs. The documentation does not=20
explain the "why" behind these or the "how" and "what", so I wonder if=20
anyone has any business case explanations of what these are or samples=20
of some COBOL-only implementations so I can see why I might want to use=20
them and how to do it?

I like to keep my COBOL current and if there is a way to use COBOL more=20
effectively, I hope you can help me understand this!

OO COBOL was added to COBOL to provide a way to communicate with Java, which
does not have programs that can be called.  Java has to run in the JVM, and
you INVOKE methods in CLASSes with Java, you do not CALL programs.  So, in
order to support this we created OO COBOL (the 2nd generation, 1st gen OO COBOL
was based on SOM if anyone remenber that in the late 1990s).  OO COBOL is only
for communicatiing for Java, unless you REALLY prefer OO programming.  The real
worl is not object oriented...we do no instantiate a customer object and then
invoke a 'send_a_bill' method on that object.  We procedurally decide that it
is time to send a cusotmer a bill and do it!

Haivng said that, we now have an easier way to allow COBOL to use Java code,
actually using the COBOL CALL statement, this new feature is available in
COBOL 6.4.  If you do not need to communicate with Java, I would not
recommend OO COBOL.  The promise of Object Oriented Programing in the 1990s
has not materialized.  Re-usable tested mehods that could be re-used to build
applications  it just not really happening!  One of my fellow IBMers left
IBM for a start up and was slinging Java all day, and found it much easier to
code new methods than to search through class libraries for pre-tested parts.

Having said all that, it was pointed out earlier that we have seample in the
COBOL Programing Guide for comunicating woith Java using OO COBOL.  OO COBOL
was not designed to be used in a pure COBOL application, so no examples of
that.

Cheers,
TomR              >> COBOL is the Language of the Future! <<

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email [email protected]  with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to