Skip to main content

String Handling in Managed COBOL

  • June 21, 2012
  • 3 replies
  • 0 views

This week I’ve discovered the power of the string handling syntax that’s built into the Managed COBOL language. If you're not familiar with it, it’s well worth a look...

We'll start by looking at a code sample, then we'll discuss the syntax.

The program produces the output :

hello world
hello
 world
hello-world
23 is a number which I can concatenate
Length of a = 11
hello-world
Micro Focus Managed COBOL is amazingly good for working with strings!

 

Now let's take a closer look at the code...

Substrings

Substringing is built into the Managed COBOL syntax

To do this with C# or Java you would have to use a substring method on the string class.

 

String Length    

To get the length of a string use SIZE OF, for example

To do this with C# or Java you would have to use a length method on the string class.

 

String Concatenation

String concatenation is easy in COBOL using the & operator.

Notice in the example above that you can concatenate

  • string variables  eg a & b
  • substrings        eg a & b(1:3)
  • quoted string constants eg a & "-"
  • non-string types  eg 23 & " is a number"
  • return values from invokes  eg in the example above - type COBOLString::Split
  • and most impressively a combination of the above!

NB All the sample code above will compile to .NET or JVM. For an overview of .NET COBOL & JVM COBOL please see "Managed COBOL - An Overview".




#JVM
#development
#VisualCOBOL
#COBOL
#language
#.net
#Eclipse
#VisualStudio
#HowTo-BestPractice

3 replies

This week I’ve discovered the power of the string handling syntax that’s built into the Managed COBOL language. If you're not familiar with it, it’s well worth a look...

We'll start by looking at a code sample, then we'll discuss the syntax.

The program produces the output :

hello world
hello
 world
hello-world
23 is a number which I can concatenate
Length of a = 11
hello-world
Micro Focus Managed COBOL is amazingly good for working with strings!

 

Now let's take a closer look at the code...

Substrings

Substringing is built into the Managed COBOL syntax

To do this with C# or Java you would have to use a substring method on the string class.

 

String Length    

To get the length of a string use SIZE OF, for example

To do this with C# or Java you would have to use a length method on the string class.

 

String Concatenation

String concatenation is easy in COBOL using the & operator.

Notice in the example above that you can concatenate

  • string variables  eg a & b
  • substrings        eg a & b(1:3)
  • quoted string constants eg a & "-"
  • non-string types  eg 23 & " is a number"
  • return values from invokes  eg in the example above - type COBOLString::Split
  • and most impressively a combination of the above!

NB All the sample code above will compile to .NET or JVM. For an overview of .NET COBOL & JVM COBOL please see "Managed COBOL - An Overview".




#JVM
#development
#VisualCOBOL
#COBOL
#language
#.net
#Eclipse
#VisualStudio
#HowTo-BestPractice

I was looking all over the web for the syntax:

  set n to size of myString.

Thanks a lot.


  • April 9, 2021

This week I’ve discovered the power of the string handling syntax that’s built into the Managed COBOL language. If you're not familiar with it, it’s well worth a look...

We'll start by looking at a code sample, then we'll discuss the syntax.

The program produces the output :

hello world
hello
 world
hello-world
23 is a number which I can concatenate
Length of a = 11
hello-world
Micro Focus Managed COBOL is amazingly good for working with strings!

 

Now let's take a closer look at the code...

Substrings

Substringing is built into the Managed COBOL syntax

To do this with C# or Java you would have to use a substring method on the string class.

 

String Length    

To get the length of a string use SIZE OF, for example

To do this with C# or Java you would have to use a length method on the string class.

 

String Concatenation

String concatenation is easy in COBOL using the & operator.

Notice in the example above that you can concatenate

  • string variables  eg a & b
  • substrings        eg a & b(1:3)
  • quoted string constants eg a & "-"
  • non-string types  eg 23 & " is a number"
  • return values from invokes  eg in the example above - type COBOLString::Split
  • and most impressively a combination of the above!

NB All the sample code above will compile to .NET or JVM. For an overview of .NET COBOL & JVM COBOL please see "Managed COBOL - An Overview".




#JVM
#development
#VisualCOBOL
#COBOL
#language
#.net
#Eclipse
#VisualStudio
#HowTo-BestPractice

Excellent article.

If "Managed COBOL - An Overview" is supposed to be a link, it is broken.

Thanks.


  • April 9, 2021

This week I’ve discovered the power of the string handling syntax that’s built into the Managed COBOL language. If you're not familiar with it, it’s well worth a look...

We'll start by looking at a code sample, then we'll discuss the syntax.

The program produces the output :

hello world
hello
 world
hello-world
23 is a number which I can concatenate
Length of a = 11
hello-world
Micro Focus Managed COBOL is amazingly good for working with strings!

 

Now let's take a closer look at the code...

Substrings

Substringing is built into the Managed COBOL syntax

To do this with C# or Java you would have to use a substring method on the string class.

 

String Length    

To get the length of a string use SIZE OF, for example

To do this with C# or Java you would have to use a length method on the string class.

 

String Concatenation

String concatenation is easy in COBOL using the & operator.

Notice in the example above that you can concatenate

  • string variables  eg a & b
  • substrings        eg a & b(1:3)
  • quoted string constants eg a & "-"
  • non-string types  eg 23 & " is a number"
  • return values from invokes  eg in the example above - type COBOLString::Split
  • and most impressively a combination of the above!

NB All the sample code above will compile to .NET or JVM. For an overview of .NET COBOL & JVM COBOL please see "Managed COBOL - An Overview".




#JVM
#development
#VisualCOBOL
#COBOL
#language
#.net
#Eclipse
#VisualStudio
#HowTo-BestPractice

I can't find any definition or reference to this so called "COBOLString" type that you have in your examples.  Is this something very recently new?  My orientation is Windows/Visual Studio/.Net.  Where is this in the doc?  What wrong with just plain old String?  It's not mentioned here:   https://www.microfocus.com/documentation/visual-cobol/vc60/VS2017/HRLHLHCPRO01U948.html

I'm really confused.  Have I missed something?

NEVER MIND !!!  I now see that COBOLString is a class you defined in the example.  If there was a way to delete my whole comment here, I would delete this.