00 COBOL2 AM - Micro Focus

1y ago
10 Views
2 Downloads
6.59 MB
232 Pages
Last View : 1m ago
Last Download : 5m ago
Upload by : Duke Fulford
Transcription

VisualCOBOL NEW APPLICATION MODERNIZATION TOOLSFOR THE JAVA DEVELOPER00 COBOL2 AM.indb 14/19/21 5:08 PM

Copyright 2021 by Micro Focus. All rights reserved.No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by anymeans, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted un-derSections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission ofthe Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright ClearanceCenter, Inc. 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests toMicro Focus for permission should be addressed to the Legal Department, Micro Focus, 700 King Farm Blvd,Suite 125, Rockville, MD 20850, (301) 838-5000, fax (301) 838-5034.Micro Focus, Net Express, Server Express, Visual COBOL, COBOL Server, and Micro Focus Server are eitherregistered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Otherproduct and company names mentioned herein may be the trademarks of their respective owners.The example companies, organizations, products, domain names, e-mail addresses, logos, people, places,and events depicted herein are fictitious. No association with any real company, organization, product, domainname, e-mail address, logo, person, place, or event is intended or should be inferred.The book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Micro Focus, Box Twelve Press, nor theirresellers or distributors will be held liable for any damages caused or alleged to be caused either directly orindirectly by this book.This document is provided “as-is”. Information and views expressed in this document, including URL and otherInternet Web site references, may change without notice. Some examples depicted herein are provided forillustration only and are fictitious. No real association or connection is intended or should be inferred.ISBN: 978-0-578-79047-3This book was set in Akzidenz-Grotesk by Box Twelve Press.00 COBOL2 AM.indb 24/19/21 5:08 PM

Contents at a GlanceCHAPTER 1Introduction1CHAPTER 2Visual COBOL and Eclipse5CHAPTER 3What is Visual COBOL for JVM?19CHAPTER 4A Short Guide to Procedural COBOL29CHAPTER 5An Example Application41CHAPTER 6A COBOL-Based REST Service67CHAPTER 7Automated Testing99CHAPTER 8User Interface Modernization127CHAPTER 9Containerizing COBOL Applications155C H A P T E R 10COBOL and Microservices00 COBOL2 AM.indb 31854/19/21 5:08 PM

00 COBOL2 AM.indb 44/19/21 5:08 PM

ContentsCHAPTER 1Introduction1What Is Visual COBOL for JVM?. 1Why Have We Written This Book?. 2Who Is This Book For?. 2Prerequisites. 3Downloading the Examples. 4Summary. 4CHAPTER 2Visual COBOL and Eclipse5Hello World. 5Creating COBOL JVM Projects in Eclipse. 7Using Maven with Visual COBOL. 10Summary. 18CHAPTER 3What is Visual COBOL for JVM?19COBOL Dialects. 19What is Managed Code?.20COBOL Source Formats. 21The Visual COBOL Object Model.23Summary.27CHAPTER 4A Short Guide to Procedural COBOL29COBOL Applications.30Structure of a COBOL program. 31Procedure Division.34Copybooks.38Summary.4000 COBOL2 AM.indb 54/19/21 5:08 PM

vi ContentsCHAPTER 5An Example Application41Introducing the Example.41Generating Example Data.59Calling COBOL from Java. 61Summary.66CHAPTER 6A COBOL-Based REST Service67The Application.67The Interoperation Layer.70The MonthlyInterest Class.85Creating a REST Interface .88Summary.97CHAPTER 7Automated Testing99Strategies for Testing.99Introducing MFUnit. 101Testing the BusinessRules Layer.107Testing the Interoperation Layer.117Testing the Application End-to-End.120Summary.126CHAPTER 8User Interface Modernization127UI Choices .127The Credit Service UI Application.130Getting Started with React.135Summary.15400 COBOL2 AM.indb 64/19/21 5:08 PM

Contents   viiCHAPTER 9Containerizing COBOL Applications155Containerizing Applications for the Cloud.155Changing from ISAM to a Database . 161Running the Revised CreditService Application. 173Containerizing the CreditService. 175Summary .183C H A P T E R 10COBOL and Microservices185Why Do I Need a Platform? .185Kubernetes.187Serverless Computing.199Index00 COBOL2 AM.indb 72114/19/21 5:08 PM

DedicationThis book is dedicated to my Mum for being an inspiration and to my wife and daughter for theirpatience through all the weekends I missed with them while I wrote this.AcknowledgementsThis book would not have been possible without the expert help and assistance of the followingpeople: The Micro Focus COBOL development team that builds and delivers such brilliant software Robert Sales, the father of Visual COBOL Mark Conway for being an advocate for these books Ed Airey for leading the project Scot Nielsen for assistance and advice The technical reviewers who checked the examples and kept me honest: Stephen Gennard,Guy Sofer, and Sezgin HalibovBox Twelve Press for editorial and publishing supportAbout the AuthorPaul Kelly has worked at Micro Focus for more than 20 years. Paul worked on VisualCOBOL for 10 years, initially on Visual Studio development, and later on Eclipse,before helping to develop a cloud-based SaaS offering. In 2017, Paul wrote VisualCOBOL: A Developer’s Guide to Modern COBOL. In his spare time, Paul plays theguitar and experiments with different ways of making coffee.00 COBOL2 AM.indb 84/19/21 5:08 PM

CHAPTER 1IntroductionThis chapter outlines the purpose of this book and its intended audience.What Is Visual COBOL for JVM?Visual COBOL for JVM is COBOL compiled to Java bytecode. Putting COBOL on theJVM (Java Virtual Machine) enables object-oriented extensions to COBOL so that you cancode classes, objects, and methods, just as you can with Java. But you can also compileexisting procedural COBOL code and run it on the JVM, too.Visual COBOL does not convert COBOL source to Java source; it compiles COBOLsource directly to JVM bytecode, so that all the intellectual assets in your COBOL sourcecode base are retained. This is a unique feature of Visual COBOL for JVM—there are translators that will convert your code from procedural COBOL to Java, but machine-translatedcode is harder to work with in the future than the original human-authored source.Once COBOL source is compiled for the JVM, you can easily integrate legacy code withnewer environments. For example, you can run COBOL code directly on an applicationserver, and use it as the back end to REST services provided by Java. The Java and theCOBOL can interoperate directly because they are both running on the same JVM. Youcan also step seamlessly between one language and the other when you are debugging.COBOL is one of several languages that are able to run on the JVM, although COBOLcan also be compiled as .NET code or native code. (When you compile to native code,the Visual COBOL extensions to the language are not available.)You can use the Visual COBOL syntax to extend your legacy code and provide modernAPIs to access it, using a language that produces artifacts easily consumed from Java,while being able to interoperate with the record structures that are found in COBOLbusiness applications.100 COBOL2 AM.indb 14/19/21 5:08 PM

2IntroductionChapter 4 explains the platform in more depth.Why Have We Written This Book?Micro Focus decided to follow up to Visual COBOL—A Developer’s Guide to ModernCOBOL with a deeper dive into some topics. This book focuses solely on Visual COBOLfor JVM as we are looking at different ways of deploying applications, something that isplatform specific.You don’t have to read Visual COBOL—A Developer’s Guide to Modern COBOL beforereading this book—but you might find it useful to have it around as a reference, particularlyif you are not familiar with Visual COBOL. There is some overlap between this book andthe other one, but whereas the developer’s guide focuses attention on the Visual COBOLlanguage, this book looks more closely at the practical issues of deploying COBOL applications on JVM platforms.Who Is This Book For?The primary audience for this book is Java developers who need to work with a legacyCOBOL application. We’ve assumed knowledge of Java and the JVM, and familiaritywith OO concepts. We’ve provided an introduction to the new syntax in Visual COBOLthat enables object-orientation and also to the way data structures are defined in legacyprocedural COBOL programs. This should be enough to understand the examples in thisbook and will help you with other legacy code you have to work with.But it is not intended as a detailed primer on the COBOL language. If you want to learnmore about Visual COBOL, Visual COBOL—A Developer’s Guide to Modern COBOLprovides much more detail about the syntax that enables you to write classes and interfacesusing a simplified and straightforward COBOL dialect. And there are many books availablefrom which you can learn the traditional COBOL syntax used to create many line-of-businessapplications.COBOL programmers who need to migrate existing applications to new platforms willalso find a lot of helpful information in this book. However, if you don’t have any backgroundwith object-oriented concepts or Visual COBOL, I’d recommend that you work throughsome of the examples in Visual COBOL—A Developer’s Guide to Modern COBOL first.Visual COBOL—A Developer’s Guide to Modern COBOLSince I’ve mentioned Visual COBOL—A Developer’s Guide to Modern COBOL manytimes in this introduction, you might be wondering what it is and where you can get it. Itwas written by the same author as this book, and provides tutorial and reference information00 COBOL2 AM.indb 24/19/21 5:08 PM

Prerequisites   3on the Visual COBOL syntax, using worked examples. It also covers Visual COBOL for.NET—yes, you can compile exactly the same sources to either .NET or JVM, enablingcross-platform programming if required.It is available as a free e-book from Micro Focus, or as a printed copy from Amazon (justsearch for Visual COBOL on the Amazon website). To get the free download from MicroFocus, go to ook/.PrerequisitesTo be able to run the examples in this book, you will need Visual COBOL for Eclipse. Thisincludes an Eclipse IDE with plug-ins that enable background parse, syntax assistance,compiling, and debugging of your COBOL code. This product is available for Windowsand several Linux distributions, including SUSE and Red Hat. Not all Visual COBOLproducts include the Eclipse IDE—some are designed as server-only products, and thereis also a line of products known as the Visual COBOL Development Hub, which providescommand-line tools such as the compiler, but which can also be driven remotely from aVisual COBOL Eclipse on another machine.Go to https://www.microfocus.com/products/visual-cobol/ for an introduction to therange of Visual COBOL products. In addition to commercially licensed products fromMicro Focus, you can also download Visual COBOL Personal Edition, which is free fornoncommercial use (see obolpersonal-edition/overview).The examples have been compiled, built, and run using Visual COBOL 4.0. You can useearlier product releases, but be aware that there might be particular syntax that will not always work with earlier versions of the product. The object-oriented features of the languageare always evolving to make the language more productive. Backward compatibility isimportant to Micro Focus, so older code can always be compiled with later product versions,even if later code can’t always be compiled with earlier product versions.You will also need a JDK installed. The JDK version depends on the Visual COBOLproduct you are using, but at the time of writing, Visual COBOL 4.0 has a prerequisite ofOracle JDK 8—download and install the latest version of JDK 8 on your Visual COBOLmachine.You can run most of the examples on Windows or Linux; we have tested them onWindows and SUSE Enterprise Linux Desktop 12, service pack 2. Visual COBOL itself istested on a wider number of platforms—at the time of writing, you can see the whole listat ech-specs/.00 COBOL2 AM.indb 34/19/21 5:08 PM

4IntroductionDownloading the ExamplesAll of the examples are available online and supplied with Eclipse project files so thatyou can import them directly into an Eclipse workspace. Some projects are used in morethan one chapter—we would recommend that you use a separate workspace to run theexamples from each chapter. To download them, go to a-developers-book.SummaryThis book is a primer to practical techniques for using Visual COBOL for JVM to buildapplications that extend existing COBOL code using modern frameworks such as Spring. Itis aimed primarily at Java developers, but COBOL developers who have an understandingof Java and OO will also find it very useful.For a comprehensive guide to the Visual COBOL language itself, see the sister bookVisual COBOL—A Developer’s Guide to Modern COBOL. You can get the free e-bookfrom ook/. Or you can get a printedcopy from Amazon (just search for Visual COBOL on the Amazon website).00 COBOL2 AM.indb 44/19/21 5:08 PM

CHAPTER 2Visual COBOL and EclipseThis chapter is a short “getting started” for readers who haven’t used Visual COBOL before,but it also explains the use of Maven with Visual COBOL (something not yet covered inMicro Focus documentation). In this chapter, you’ll learn about: Creating and running “Hello World” in Visual COBOL Creating COBOL JVM projects in Eclipse Turning COBOL components into Maven dependencies so that they can beconsumed more easily from JavaIf you haven’t already done it, install a Java Development Kit (JDK) and Visual COBOLfor Eclipse product (see the “Prerequisites” section in Chapter 1).Hello WorldThe simplest Hello World we can write with Micro Focus COBOL is shown in Listing 2-1.Before running any of the examples in this book, you must ensure youhave a compatible Java Development Kit (JDK) installed as explained in the“Prerequisites” section of Chapter 1. On Linux, the PATH and JAVA HOMEenvironment variables must point to your Java installation before you runcobsetenv as described in the following steps.Listing 2-1 Hello Worlddisplay “Hello World”500 COBOL2 AM.indb 54/19/21 5:08 PM

6Visual COBOL and EclipseTo run this program:1.Create a text file called HelloWorldProcedural.cbl, and enter the code shown inListing 2-1. Start the text in column 8 or later (different COBOL source formatsare explained in the “COBOL Syntax and Source Formats” section in Chapter 3).2.If you are running Visual COBOL on Windows, open a Visual COBOL commandprompt (this is part of the Visual COBOL menu group). If you are running VisualCOBOL on Linux, open a command prompt and run. cobsetenvin the Visual COBOL bin directory (usually /opt/microfocus/VisualCOBOL/bin)before proceeding.Change directory to the location where you created the file, and enter thecompile command for Windows or Linux:Windows:cobol HelloWorldProcedural.cbl jvmgen;Linux:cob –j HelloWorldProcedural.cblThe compiler creates the file HelloWorldProcedural.class in the same directoryas the source file.3.Runit on Windows or Linux:Windows:java HelloWorldProceduralLinux:cobjrun HelloWorldProceduralOn Linux platforms, you normally run COBOL programs (or Java programs thatcall COBOL) using the cobjrun command. This command sets up the COBOLrun-time environment before invoking Java to run the bytecode; it also ensuresUNIX signal handling will work correctly with the COBOL run-time. See theMicro Focus Visual COBOL documentation for more information about cobjrun.On Windows, opening a COBOL command prompt (or running createnv.bat inyour Visual COBOL installation directory) puts COBOL run-time files on theCLASSPATH—so you can run the .class file with the java command.00 COBOL2 AM.indb 64/19/21 5:08 PM

Creating COBOL JVM Projects in Eclipse   7Writing Hello World as a ClassIn the previous section, we wrote a Hello World program. It’s very short compared with theJava equivalent. However, our program was just procedural COBOL, and we could havecompiled it to native code and it would have executed the same.Visual COBOL is able to compile procedural COBOL code so that it can compileexisting legacy COBOL code. It does this by actually creating the bytecode for a class,so that to the JVM, it looks like a Java class, and running it creates a single instance ofthe synthesized class and then executes the program code. We’ll look at some of theimplications of this later in the book when we use COBOL RunUnits to run our code inenvironments such as application servers.That’s what the compiler does, but we can also choose to write “Hello World” as aclass with a static method (see Listing 2-2)—which is the way “Hello World” is usuallywritten in Java. The syntax looks different to Java, but there’s a class identifier, a methodidentifier, and the method is marked as static. The parameters to the main method are anarray of strings (the equivalent to String[] args in Java). However, “string” is a reservedword in Visual COBOL, but it is equivalent to declaring a java.lang.String in Java. Thereare a few classes that are represented as “native” types in Visual COBOL, which makesit much easier to write cross-platform code that runs on .NET or Java. See Chapter 14 inVisual COBOL—A Developer’s Guide for more information.Listing 2-2 Hello World written as a classclass-id HelloWorld.method-id main(args as string occurs any) static public.display “Hello World”end method.end class.You can compile and run this program the same way you did HelloWorldProcedural inthe previous section.Creating COBOL JVM Projects in EclipseWe are going to assume that you have some familiarity with Eclipse already, and justintroduce the plug-ins used for working with COBOL. As you will learn later in the book,Visual COBOL supports compilation to either native code or Java bytecode. You cancreate projects for either type of executable in Eclipse, but in this book, we are only reallyconcerned with compiling to JVM.00 COBOL2 AM.indb 74/19/21 5:08 PM

8Visual COBOL and EclipseUnderstanding the COBOL Perspective in EclipseOn Windows, you can start Eclipse from the Start menu. The Micro Focus menu groupfor Visual COBOL might be named Micro Focus Enterprise Developer, Micro Focus TeamDeveloper, or Micro Focus Visual COBOL depending on which product you have installed.The menu group will have an icon to start Eclipse.On Linux systems, there may be a Micro Focus COBOL icon on the desktop to startEclipse, or you can open a command prompt and use the cobsetenv command to set upa COBOL environment (see the “Hello World” section earlier in this chapter). Then, youcan enter the eclipse command to start Eclipse for Visual COBOL.Once Eclipse is running and you have selected or created a workspace, you can openthe COBOL Perspective. You can find it from the Eclipse menu: Window Perspective Open Perspective Other. Once you’ve opened the COBOL Perspective once, thereis also a toolbar icon (the blue-bordered “CBL” box) to switch back to it after you’ve beenusing a different perspective.The COBOL Perspective is very useful for working with COBOL projects. It opens theCOBOL Explorer window. This looks a little like the Project Explorer, but has a COBOLcentric perspective; it only shows COBOL projects.If you right-click on a COBOL project and select Properties, you’ll see a Micro Focusgroup on the left side of the Properties window (see Figure 2-1). This has all the settingsfor a COBOL project. You can see these properties from the COBOL Explorer or theProject Explorer, but you can’t see them from the Package Explorer.Figure 2-1 Micro Focus group in the Build Properties window00 COBOL2 AM.indb 84/19/21 5:08 PM

Creating COBOL JVM Projects in Eclipse   9Creating and Running JVM Hello World in EclipseTo create a COBOL JVM project for Eclipse:1.Open the COBOL Perspective as explained in the previous section.2.Click File New COBOL JVM Project. (If you didn’t select the COBOLPerspective, COBOL JVM Project doesn’t appear on the menu after you clickNew, but you can still find it by clicking Other and filtering the Wizards list byCOBOL.)3.Enter HelloWorld as the project name. By default, Eclipse will create yourproject under your workspace directory, but you have the option of deselectingUse default location and putting the project somewhere else.4.Click Finish.You now have an empty project. If you use the COBOL Explorer to look at it, you willsee a src directory as well as folders for the COBOL JVM Runtime System and the JRE.The project structure is similar to the structure of an Eclipse Java project.Next, to add some code to the project:1.Click File New COBOL JVM Class. This opens the New COBOL JVMClass dialog box. It looks very similar to the dialog box for creating a new Javaclass.2.Enter HelloWorld as the name and click Finish.3.Expand the src folder in the COBOL Explorer and you can see the defaultpackage and below it HelloWorld.cbl. The wizard has created some defaulttemplate code inside HelloWorld.cbl, but you can delete all of it and replace itwith the code in Listing 2-2, and then save your changes.The Eclipse default is to build projects automatically each time a source code changeis saved, so the console window should show (among other things) the message “BUILDSUCCESSFUL”.Finally, to run Hello World:1.Right-click on the HelloWorld project in the COBOL Explorer.2.Click Run As COBOL JVM Application.3.A Select COBOL JVM Application dialog box opens. Select HelloWorld from thelist and click OK.You should see Hello World in the Eclipse console. If you click Run Run Configurations,there is now an Eclipse run configuration for HelloWorld.00 COBOL2 AM.indb 94/19/21 5:08 PM

10 Visual COBOL and EclipseUsing Maven with Visual COBOLMaven has become a de facto standard for representing the dependencies of Java projects.Other popular build engines such as Gradle will import Maven POM files and will consume dependencies stored in Maven repositories. The easiest way to consume COBOLdependencies in any sizable Java project is to make its artifacts available through Maven.Visual COBOL doesn’t yet have native Maven support, but we will show you that it isrelatively easy to make a COBOL project consumable from a Java Maven project.A Quick Introduction to MavenThis section is a 30-second introduction for any readers who haven’t used Maven. A Mavenproject is defined by a file called pom.xml in the project’s root directory. This file is theProject Object Model (POM). The POM file defines the artifact to be built and providesan identifier and version number.The identifier consists of a group ID and an artifact ID. Group IDs are constructed ratherlike Java package names and are unique to an organization defining them. For example,many Apache libraries are defined under the group ID “org.apache.commons.” The groupID and artifact ID between them provide a global unique identifier for a library. The versionnumber enables a library dependency to be fixed to a particular version.The POM defines all the dependencies required to build the project using the groupand artifact IDs and,

Visual COBOL does not convert COBOL source to Java source; it compiles COBOL source directly to JVM bytecode, so that all the intellectual assets in your COBOL source . code base are retained. This is a unique feature of Visual COBOL for JVM—there are trans-lators that will convert your code from procedural COBOL to Java, but machine-translated

Related Documents:

environmental information of the product in the Ecophon family Focus. The values presented in this EPD are represented for the following products: Focus A, Focus B, Focus C, Focus Ds, Focus Dg, Focus D/A, Focus E, Focus Ez, Focus F, Focus Lp, Focus SQ, Focus Flexiform Supplemental product inf

studio re-mix and one last thing: don't worry, you can't go wrong won't let you! SoundBITE micro SoundBITE SoundBITE micro SoundBITE micro SoundBITE micro SoundBITE micro SoundBITE micro The automat

quality of micro holes produced by micro-EDM and investigated the influence of parameters on performance of micro-EDM of WC in obtaining high quality micro-holes, good surface finish and circularity [5]. M.S. Rasheed et al. analyzed the effect of micro-EDM parameters on MRR, TWR and Ra while machining Ni-Ti SMA (shape memory alloy)

Ecophon Focus Fixiform E A T24 1200x600x20 Focus E Ecophon Focus Flexiform A A T24 1200x600x30 1600x600x30, 2000x600x30, 2400x600x30 Focus A Ecophon Focus Frieze A T24 2400x600x20 Focus A, Focus Ds, Focus Dg, Focus E Ecophon Focus Wing A T24 1200x200x5

Micro Focus Service Desk for ITIL Management: A comprehensive service management solution that is fully compliant with Information Technology Infrastructure Library (ITIL) standards. Micro Focus Service Desk for ITIL M anagement supports eleven core ITIL processes . "Integrating ZENworks with Micro Focus Service Desk" on page 9

F FOCUS ON PHOTOGRAPHY: A CURRICULUM GUIDE Focus Lesson Plans and Actvities INDEX TO FOCUS LINKS Focus Links Lesson Plans Focus Link 1 LESSON 1: Introductory Polaroid Exercises Focus Link 2 LESSON 2: Camera as a Tool Focus Link 3 LESSON 3: Photographic Field Trip Focus Link 4 LESSON 4: Discussing Images/Developing a Project Theme Focus Link 5 LESSON 5: Creating Images/Point-of-View Activity

Micro plasma weldings (f.l.): membran, glow plug, magnetic valve, relay) Micro plasma welding of pressure cells Micro plasma welding torch PJB100superior Circular welding system for micro plasma welding with plasmaJET100SPS Micro plasma welding Welding currents from 0.1A W

être imposées à l'alimentation dans le cas d'un additif, pesticide, ou d'autres contenus qui sont interdites au Japon, alors que leurs niveaux dépassent les limites approuvées, ou lorsque la présence de mycotoxines, etc. est au-dessus des niveaux admissibles. Par conséquent, les aliments santé et des compléments alimentaires doit être vérifiée sur le site de production avant l .