Alchemy Solutions
HomeMigrationsProductsServicesInformationNewsPartnerPricingAbout Us
Fujitsu COBOL NetCOBOL .net CICS
quicksearch  
spcer
 
Fujitsu COBOL NetCOBOL .net CICSDownload Fujitsu COBOL NetCOBOL .net CICS SupportFujitsu COBOL NetCOBOL .net CICSFujitsu COBOL NetCOBOL .net CICS
Fujitsu COBOL NetCOBOL .net CICS
Home > Information
 
Customer Stories
FAQ's
What COBOL for me?
Run-Time Licensing
White Papers
Reuse vs Rewrite
COBOL from .NET Dox
ASCII (ACP) to Unicode
with NetCOBOL for .NET
Moving Cobol to .NET
Web Services
COBOL/Microsoft .NET
Best of GUI
OO COBOL
COBOL 2000 (2002)
Recommended Books
Reviews
COBOL and VB on .NET
Learn COBOL in 24 hours
Mastering COBOL


F
ujitsu COBOL and Microsoft® Visual Basic®

Introduction
Mixed-language programming is essential in today's advanced computing solutions. Every language has its limitations. One language may have the tools to design elaborate user interfaces but lack in the ability to perform complex data manipulations and calculations easily. With mixed-language programming, the strengths of each language can be exploited; what one language lacks, the other can make up for.

Billions of Lines of COBOL Code
There are billions of lines of COBOL code in existence, with millions more created every year. The majority of enterprise-wide systems development is still done using COBOL.

With the combination of Microsoft Visual Basic and Fujitsu COBOL, programmers can quickly and easily access, reuse, and retarget existing COBOL programs to create sophisticated state-of-the-art Windows applications.

Visual Basic Integration
Fujitsu COBOL provides three methods to share applications and data with Visual Basic: Dynamic-Link Libraries (DLLs), Dynamic Data Exchange (DDE), and Object Linking and Embedding (OLE).

Fujitsu COBOL also provides support for Embedded Structured Query Language (ESQL), compatible with either Microsoft SQL Server, Oracle 7, or Sybase to allow access to data on remote servers. Thus, programmers are no longer restricted to accessing data sequentially. They can take advantage of SQL server's sophisticated relational database management system. Integrating the three languages, you can create distributed client-server applications with a sophisticated graphical user interface.

With support for Visual Basic and SQL Server, Fujitsu COBOL makes the possibility of downsizing large mainframe applications to Windows a reality.

COBOL DLL Interaction with Visual Basic
To access any COBOL routines from Visual Basic, you need to first declare the COBOL PROGRAM-ID or the COBOL ENTRY routine using the Basic Declare statement with the special Lib keyword to specify the path name of the COBOL DLL. These declarations can be made in the declaration section of any form module or in the global module. You can then call these routines from your Visual Basic code like any other function call.

When a Visual Basic program calls a COBOL routine, you should call JMPCINT2 before calling the first COBOL routine, and call JMPCINT3 after calling the last COBOL routine. JMPCINT2 is a subroutine that initializes the COBOL Run Time Environment and JMPCINT3 is a subroutine that terminates the COBOL Run Time Environment.

Visual Basic Declaration

Declare Sub MYCOBOL Lib "c:\mycobol.dll" (vbInteger as Integer, ByVal vbString as String)
Declare Sub JMPCINT2 Lib "c:\FSC\PCOBOL32\F3BIPRCT.DLL" ()
Declare Sub JMPCINT3 Lib "c:\FSC\PCOBOL32\F3BIPRCT.DLL" ()


Visual Basic Call

Sub Form_Click ( )
Dim vbInteger as Integer
Dim vbString as string * 15
Call JMPCINT2 ' Initialize COBOL Runtime Environment
Call MYCOBOL (vbInteger, vbString)
Call JMPCINT3 ' Terminate COBOL Runtime Environment
End Sub


COBOL Linkage and Procedure Division

Identification Division.
Program-ID. "MYCOBOL".
Data Division.
Linkage Section.
01 vbInteger pic s9(4) comp-5.
01 vbString pic x(15).
Procedure Division with STDCALL Linkage Using vbInteger, vbString.
move 100 to vbInteger
move "Fujitsu COBOL" to vbString
exit program.

Parameter Passing Between Visual Basic and Fujitsu COBOL
Visual Basic treats a COBOL DLL as a "black box." It only needs to know the COBOL program's LINKAGE SECTION parameter list to pass data to and from the COBOL DLL. Parameters can only be passed from Visual Basic to COBOL BY REFERENCE, except strings that must be passed using the ByVal keyword in the Declare statement. Passing parameters BY REFERENCE is the default in Visual Basic. Parameter names need not be the same between Visual Basic and COBOL, however, attribute, length, and number of corresponding data items, must be identical.

Visual Basic declarations must exactly match the COBOL parameter lists defined in the USING statement of the COBOL PROCEDURE DIVISION or ENTRY statements. No parameter checking is done because the two are separate compilation units.

Visual Basic incorporates a rich assortment of data types, some of which are currently not supported by Fujitsu COBOL. These data types include variable-length strings, Currency, Variants, and objects.

Visual Basic Strings
All strings passed between Visual Basic and COBOL must be declared as fixed-length strings and passed using the ByVal keyword in the Declare statement. To avoid possible memory corruption, ensure that all strings passed between Visual Basic and COBOL occupy the same size.

Dim vbString as string * 15 ' Equivalent to PIC X(15)

When passing parameters, associate the data types as follows:

Visual Basic COBOL
Type Name Storage Size PICTURE Clause
  Boolean (16-bit)

  2 Bytes

  S9(4) COMP-5
  Boolean (32-bit)   4 Bytes   S9(9) COMP-5
  Byte   1 Byte   X
  Double   8 Bytes   COMP-2
  Integer   2 Bytes   S9(4) COMP-5
  Long   4 Bytes   S9(9) COMP-5
  Single   4 Bytes   COMP-1
  String   1 Byte per Character   X(n)


Passing Arrays
Visual Basic and COBOL can pass numeric arrays. This works because numeric array data is always laid out sequentially in memory. A COBOL routine, if given the first element of an array, has access to all of its elements.

Returning Control and Terminating Programs
To return control from COBOL to Visual Basic, execute the EXIT PROGRAM statement. When the EXIT PROGRAM statement is executed, control returns immediately to the calling program.

Compiling and Linking the COBOL Programs
To build the COBOL DLL, you need to create a module definition file (.DEF) that lists the attributes of the DLL library. A proper DEF file will be automatically created by the COBOL Project Manager, included with Fujitsu COBOL, during the build process, or you can modify the following example below changing the MYCOBOL to match the COBOL PROGRAM-ID

Sample COBOL.DEF

LIBRARY "MYCOBOL"
EXPORTS MYCOBOL


 © 2003 - 2008 Alchemy Solutions Inc. All Rights Reserved.