Re: Web Services and COBOL (Fairly long post, but I don't have time to write a proper article on it)




"James J. Gavan" <jgavandeletethis@xxxxxxx> wrote in message
news:qZi5i.214632$DE1.57499@xxxxxxxxxxxx
Pete Dashwood wrote:
Round of applause!!!

Really good stuff, Jimmy.

Some comments below...


Not sure how you are using "Procedural" here.Maybe MF have a specific
meaning for it.

Well you might not like it, but I would call your source 'Procedural' in
that it is a PROGRAM source as opposed to a CLASS source, although you are
still creating/accessing objects via invokes. I think the advantage of ALL
classes is the ability to do a 'round robin' between the various classes
because you can have an instance handle (object reference) to each. (My
comment was not based on Micro Focus - they are silent on the topic).

OK, that's fair enough.


I like what you did very much. I have reservations about trigger programs
but it works very well here.

Well of course the early M/F OO examples all did/and still have a Trigger
program. The main functions are :-

- Menu driven application - from the Trigger start the App(Business Logic)
and the Master Menu. Return handles from both to the Trigger which passes
them to the corresponding App and Menu instances

Yes, I've read Wil Price's book. :-)

Similar things can happen with Fujitsu. For example, you may have a .EXE
that invokes methods from a .DLL. (And, in my case at least, the .DLL is
usually a COM Server.)

Of course, by encapsulating functionality into a COM Server, you don't need
a Trigger; it can be dropped and used almost anywhere that supports OO, not
just COBOL. This gets over the old grizzle we've always had about Class
interoperability (or the lack of it) in COBOL. I have Java, C#, COBOL, and
ASP all using OO Class methods and properties that are written in COBOL.
COM empowers this; Web Services take it even further by making it global.
(In the World sense, not the programming sense... :-))

I don't think it really matters what you call it.


- call "apigui" which kick starts GUIing

This is the trigger for the Corrosion Testing application, which
illustrates above :-

*>--------------------ctbegin.cbl--------------------------

PROGRAM-ID. ctbegin.

CLASS-CONTROL. ctApplication is class "ctapp"
ctMenu is class "ctmenu"
EventManager is class "p2emgr"
Module is class "module"
.

*>--------------------------------------------------------------
OBJECT-STORAGE SECTION.
copy "\copylib\sqlResult.cpy" replacing ==(tag)== by ==01 ws==.
01 CtResourceID pic x(10) value z"ctres.dll".

01 os-App object reference.
01 os-Desktop object reference.
01 os-EventManager object reference.
01 os-Menu object reference.
01 os-Resource object reference.

PROCEDURE DIVISION.

call "apigui"
invoke EventManager "new" returning os-EventManager
invoke os-EventManager "initialize"
invoke os-EventManager "getDesktop" returning os-Desktop
invoke Module "newZ" using CtResourceID
returning os-Resource

invoke ctApplication "new" returning os-App
invoke ctMenu "new" using os-Desktop
returning os-Menu

invoke os-App "passHandles" using os-Desktop
os-Menu
os-Resource
invoke os-Menu "passHandles" using os-Desktop
os-EventManager
os-App
os-Resource
invoke os-Menu "createMenu"
invoke os-Menu "create"
invoke os-App "checkFiles" returning ws-SqlResult


if ResultOK
invoke os-Menu "show"
invoke os-EventManager "run"
End-if


STOP RUN.

*>--------------------------------------------------------------


Now if you look at current M/F Dialog System examples they all start with
a 'Procedural' which also tends to be the Business Logic. As it is
Procedural they use entry-points to get at different Sections to handle
results of different GUI events.

What I'd like to do is place the code in a 'downloads' directory on the
server, along with my Fujitsu version and any other versions that people
offer (maybe Java, C#, AcuCOBOL... whatever). As soon as I have time,
I'll write an article about the whole process and place that there too,
so anyone can see the story on accessing the service (or, indeed, any web
service) from COBOL, or anything else. If you have no objection to this,
could you mail me a zip of the MF project containing your code?

No objections. I'll send you a zip.

Thanks.


Finally, what was the response like? The first one would be a bit longer
because the DB buffers have to be loaded. Also, I currently use a new
instance of the service each time it is invoked and that takes time. I'm
looking into that; it gets a bit tricky with DB connections and
connection scope...

Mere seconds. To keep it simple I'll have the SoapTrigger invoke my
DateTime Class, (which I'll also send), to get the Date/Time (pic x 21)
for start of Trigger and end of Trigger.

PS: Would you refer to your SoapTest.cbl as a standalone or would you
categorize it as a component ?

Definitely a standalone. It is really just a "harness" for testing the proxy
Class. However the web service, although being around 4000 lines of OO COBOL
code, I would consider to be a component. (I don't plan on maintaining this
code, once it has completed all of its testing.) I can't publish the code as
it is commercially sensitive, but I can tell you it has three main methods
in the Class, which are supported by other smaller methods:

(Note, I have no qualms about describing these methods publicly, because
they cannot be accessed directly. Using a web service you decide what will
be exposed and what won't...)

1. ParseOnly.

This deals with stripping a free format address into words, and attempting
to locate what is a street, a locality or lobby, a region, and a postcode.
In my naivety I figured a COBOL UNSTRING would be the caper... I crashed and
burned :-) Here's the code that sets the input buffer up so it CAN be
unstrung into words...

*
* Prepare the data buffer...
* Get all words, separated by a single space
*
move zero to ws-return
move spaces to stored-inrec
move 1 to K
perform
varying J
from 1
by 1
until J > function STORED-CHAR-LENGTH (ws-buffer)
if NOT (ws-buffer (J:1) ALPHABETIC OR ws-buffer (J:1)
NUMERIC)
AND NOT (ws-buffer (J:1) = '&'
OR ws-buffer (J:1) = '-'
OR ws-buffer (J:1) = '/'
OR (ws-buffer (J:1) = "'"
AND ws-buffer (J + 2:1) NOT = space))
move space to ws-buffer (J:1)
if ws-buffer (J:1) = space AND
Function UPPER-CASE (ws-buffer (J + 1:2)) = "S
"
move ws-buffer (J + 1:2) to ws-buffer (J:2)
end-if
*> removes punctuation and line breaks
*> but allows &,-, ' (not apostrophe) and /
*> must allow "O'Neill" but not "Neil's"
end-if
if ws-buffer (J:1) NOT = space
move ws-buffer (J:1) to stored-inrec (K:1)
add 1 to K
set expecting-space to TRUE
else
if expecting-space
move ws-buffer (J:1) to stored-inrec (K:1)
add 1 to K
set NOT-expecting-space to TRUE
end-if
end-if
end-perform
*
* stored-inrec should now be a string of words separated by one
space...
*

(nothing is ever as easy as you think... :-) Today, I would write this in C#
using Regular Expressions, but the COBOL above serves well.)

2. FIB - Fill in the blanks

This makes sure that any missing address elements are located and validated
if they can be.

3. FormatAddress.

Places a correctly formatted address (in compliance with NZPO requirements)
into the returned buffer. It is constructed from the decomposed elements
provided by FIB.

So, 3 Major methods, 4000 lines of COBOL code, but the web service exposes
only one method (ValidateNZaddress). This is a method of the service itself
(which is also a Class and gets its own object instantiated). The service is
written in C# but it can use the COBOL Class because the COBOL Class is a
COM server. (So objects from almost ANY environment (including DotNET) can
invoke it).

This is my point about components. Encapsulating functionality into a COM
component (or a Web Service) means you have, in effect, "future proofed" it.
As long as you need that functionality, it is available, anywhere you want
it, any time you want it, as "pluggable" functionality.

Pete.



.



Relevant Pages

  • Confessions of an "OO Foreigner"
    ... in COBOL or any other programming language/tool). ... to translate and actually THINKING in that language. ... have been correct about - even though I lost) was the very "INVOKE" statement ... OBJECT-REFERENCE if "invoke" is the correct word at all. ...
    (comp.lang.cobol)
  • Re: Web Services and COBOL (Fairly long post, but I dont have time to write a proper article on it)
    ... Web Service is a great prerequisite for automated client-side code ... is there anyone who could provide NetExpress Cobol ... As we are accessing a COM server (The SOAP Component) you need the above MF ...
    (comp.lang.cobol)
  • Re: Batch Process Calling a Web Service
    ... Batch Process Calling a Web Service ... tell your Java programmers to write an Java Client for the Web Service. ... Then create a COBOL wrapper for that Java program with Enterprise COBOL. ...
    (bit.listserv.ibm-main)
  • Batch Process Calling a Web Service
    ... *;a batch job, most likely an Enterprise COBOL batch program,=20 ... application the web service connects with outside of the mainframe world ... You can use batch COBOL to invoke Java methods to do this (and take ...
    (bit.listserv.ibm-main)
  • Re: Confessions of an "OO Foreigner"
    ... > in COBOL or any other programming language/tool). ... > to translate and actually THINKING in that language. ... > - Is INVOKE really the correct verb? ... when the High Priests of COBOL guarded the Holy Source Code and made ...
    (comp.lang.cobol)