USENET/GOOGLE groups: comp.lang.cobol
skip to the main content area of this page
Test the String2Num validation function, running as a COM component on our server...

The advent of Object Oriented COBOL compilers made it possible to wrap cobol code as objects. Specifically, a component based approach to COBOL (just as with any language) has many advantages. String2Num is a simple but very useful component. It is demoed here so you can see the way in which components allow functionality to be encapsulated and re-used over and over, sometimes for decades. Code which is constantly maintained, eventually has to be scrapped or rewritten; components generally don't.

What is this COMPONENT stuff all about? We've been writing modular COBOL for decades. Isn't this just a "re-invention" with a heap of wrapping overhead that nobody needs or wants?

No, there are advantages of the component based approach which are quite spectacular.

MicroSoft gave us OLE (Object Linking and embedding) which allowed objects to be linked and embedded into documents and Web pages, as well as desktop applications. Of course, COBOL couldn't play on this particular field because it wasn't Object Oriented. By the time COBOL BECAME object oriented, the OLE technology had evolved into the COMPONENT OBJECT MODEL (COM). COM objects can run anywhere... (not just in MS environments; they can be easily brokered by CORBA to the Linux, Apache, MySQL, Perl/PHP/Python (LAMP) environment also).

If you download the String2Num component being demonstrated here, you can run it on a web server, a client web page, or embedded into your own applications on the Windows desktop. You can use it ANYWHERE you need to be sure that something is numeric, even for inter-program communication. (You don't HAVE to invoke any methods that activate a user interface, and the component will not activate them by itself.)

String2Num is a piece of mainframe COBOL code, written for an IBM System 360 back in 1974. It was intended to ensure that data being input into 3270 (green screen) fields was numeric, when it was supposed to be.
Although the 3270 had attribute bytes that were supposed to ensure that only numeric data could be entered, in practice this was not foolproof, and using attributes like this meant that the system was tied to 3270 devices.

A more general means of checking numeric input was needed. Not just from screen data fields, but for inter-program communication and, indeed, anywhere that numeric data integrity needed to be established. The code was migrated to different platforms and ran on ICL 1900s, CDC Cyber70, and Honeywell mainframes.

With the advent and spread of PCs the code was ported to the IBM PC platform around 1985, using Micro Focus COBOL, where it performed with the same reliability it had shown on the mainframes. When OO COBOL became available, it was again ported to become a Class that could be instantiated anywhere it was needed. Finally, in a Fujitsu NetCOBOL for Windows incarnation, it became a COM component that can be run on the desktop or embedded into Web Pages.

Today, more than 40 years after it was first written, THE SAME CORE COBOL CODE has been wrapped to run with .NET InterOP services and is available as a C# Assembly. The demo you see here is the COM component running on our server as a C# code-behind page. The code has had an extra section added to handle floating point numbers in Scientific notation, some numeric field formats have been changed to suit the PC platform, but the rest of the component remains as the original.

Enjoy trying String2Num! If you like it and want to embed it in your own applications, you can obtain and use it for free, without limitation.(See"Download", below)

Here is the demo...

(operands on either side of the point that exceed the COBOL limitation of 18 digits may not break down correctly into the various formats, however, detection of being numeric will still function correctly. Embedded spaces in your string will be ignored.)

Validating that allegedly numeric data IS actually numeric...

SORRY! We are looking at COM use on the new site and this DEMO cannot work at the moment. The download below should work and you can get the component through that.

Input a string to be validated...

Select the component properties you want set (or leave blank for defaults)...

Currency symbol:   Decimal point symbol:
Numeric separator symbol:   Verbose error messages?:

Check out the results.

Here is the data returned in the buffer, from "ShowStuff" or "ShowError"...

(Remember, you don't HAVE to invoke these methods... most of the time it is enough to invoke "GetNumber" then check "ItsANumber". The other methods provide a consistent way to notify information. How you present the buffer provided is entirely up to you...)

When you hit "Try It!", the component's "GetNumber" Method is invoked and passed your test string. "GetNumber" returns and sets a Boolean property called "ItsANumber". (For COBOL this is represented as a 16 bit numeric which is all 0 or all 1.) If your input string is a number (it is allowed to have certain non-numeric symbols like CR/DR, +/-, $, etc.) then a Method of the component, called "ShowStuff" is invoked. This formats a buffer which shows the state of the component's properties. The inherent number is extracted into a series of useful formats which are all propertiers of the component and can be easily accessed. "ShowStuff" and "ShowError" do NOT write to the user interface; they simply format a buffer which you can access via the COM object.

If the string cannot be resolved to an inherent number, then a different Method called "ShowError" is invoked. "ShowError" also formats the same buffer. Depending on the setting of the "Verbose" property (FALSE = 0x0000, TRUE = 0xFFFF (-1)) the contents of this buffer will vary. You can flip the "Verbose" property with the check box provided, and see the difference. For this demo, "ShowStuff" is invoked if the string is a number and "ShowError" is invoked if it isn't, but this is all under application control. If you didn't want these methods, you simply wouldn't invoke them. The component will NEVER invoke any of its behaviours without being told to...

Download the component...

The download includes different versions of the String2Num component (The COM component and the C# .DLL, which you are seeing demonstrated here, a full Windows Help file describing the methods and properties of the component, and a White Paper called "Components 101", which explains the conceptual background and is aimed at COBOL people who are unfamiliar with OOP and components. The component, in any of its forms, is freeware and you can use it for any purpose, personal or commercial, that you see fit.

Back to TOP OF PAGE...