Maintaining COBOL code, especially apps of tens of thousands of lines or more, can sometimes feel like a chore. With Micro Focus’ COBOL development products Visual COBOL and Enterprise Developer however, this a relatively painless and productive experience thanks to rich editing tools that significantly speed up the job of fixing and developing new COBOL programs.
The capabilities I will focus on here can be found in both the Visual Studio and Eclipse variants of the product, and behave in a similar fashion to C# and Java apps. In this blog I will explain and illustrate some of the editing features available using Visual COBOL for Visual Studio.
For many customers, coding standards and consistency is an important aspect of the development activity. But when an application has over ten thousand lines, it is very likely that the code style will be inconsistent. A new editing capability we’ve designed recently and will be introducing in a forthcoming product release, is the ability to automatically format COBOL programs. Format Selection can re-indent a selection of lines making code much easier to read and thus quicker to find potential problems. Not only will it improve the readability, but it can make mistakes easier to spot as the indentation will now be correct. There are many preferences available for format selection so that the code is changed to the desired code style. Code is by default automatically formatted when pasting, typing a full stop, or inserting a snippet. It is possible to manually format a selection of code by pressing CTRL+K and then CTRL+F (as shown in the animation below) or the entire document by pressing CTRL+K and then CTRL+E. To format one or more included copybooks, Format Program can be used by pressing CTRL+K and then CTRL+P.
Extract to Section
Extract to Selection makes the task of refactoring code straightforward. Just select a block of code that should be isolated into a new section, click the light bulb and type the section name.
There is one area of development that really shows the value of this tool: unit testing Let’s say an application contains a crucial piece of logic, it would be important to ensure that it works without worrying about whether other parts of the code do. Extract to section can take this logic and stick it into a new section making it simple to call from a unit test, not too different from a C++ or Java method. The animation below shows several COBOL statements being extracted into a new section and given a meaningful section name that describes what the code statements are doing.
The names of data items play an important role in maintaining code. The more descriptive the name the easier it is for the maintainer to interpret. Unfortunately, this isn’t always the case with old code, but Visual COBOL can automatically find all occurrences of a single data item allowing it to be renamed seamlessly. This works across copybooks too! Rename can be invoked either by using the context menu (as shown in the animation below), pressing CTRL+R twice or using a light bulb suggestion that appears when you edit the name in any place.
Completion (often referred to as IntelliSense) is very useful for both experienced and new COBOL programmers. Not only does it provide and allow filtering of data items, but it is very useful for writing COBOL statements (of which some can get very complicated) as it will only present valid keywords depending on the verb being typed. When I was first learning to program in COBOL, this along with snippets saved me many hours that I would have otherwise spent scanning through language documentation. Completion will pop up automatically by default (as shown in the animation below), but can also be forced manually by pressing CTRL+SPACE or CTRL+J.
Visual COBOL (and Enterprise Developer) continues to revolutionize COBOL development and the capabilities I’ve described above are just a sample of what is available. The IDE provides a rich experience that developers would otherwise not get with an everyday text editor, which can vastly decrease the time necessary to complete key development tasks.
These features can be tried out today in our 30-day trial of Visual COBOL. Visit our product page for more information, follow Micro Focus AMC on Twitter and, if you’ve enjoyed this tech tip check out Paula’s blog on creating COBOL code snippets. We’ll be back soon with another one so bookmark and watch this space.