Highlighted
Super Contributor.
Super Contributor.
177 views

How can I initialize a Boolean value?

Jump to solution

I'm trying to initialize a Boolean value in a managed COBOL project, but I cannot find in the documentation on how to do this.

The last line in the following code excerpt results in an "COBCH0229 Incompatible qualifiers" error:

CLASS-ID X.Form1 IS PARTIAL INHERITS TYPE System.Windows.Forms.Form.
  WORKING-STORAGE SECTION.
    01 isItTrue PIC 1 USAGE IS CONDITION-VALUE VALUE TRUE.

 

How can I initialize a Boolean value in the WORKING-STORAGE SECTION?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Super Contributor.
Super Contributor.

Re: How can I initialize a Boolean value?

Jump to solution

I fiddled around a bit and spotted that USAGE CONDITION-VALUE doesn't require a PIC definition.

So, for anyone encountering the same issue (and supposed Google will find Q&A here), here's the correct line:

    01 isItTrue USAGE IS CONDITION-VALUE VALUE TRUE.

View solution in original post

0 Likes
8 Replies
Highlighted
Super Contributor.
Super Contributor.

Re: How can I initialize a Boolean value?

Jump to solution

I fiddled around a bit and spotted that USAGE CONDITION-VALUE doesn't require a PIC definition.

So, for anyone encountering the same issue (and supposed Google will find Q&A here), here's the correct line:

    01 isItTrue USAGE IS CONDITION-VALUE VALUE TRUE.

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: How can I initialize a Boolean value?

Jump to solution

You can also omit "usage is" entirely. `condition-value` is an alias for `System.Boolean`.

       working-storage section.
       01 isItTrue condition-value value true.
       01 isItTruf type System.Boolean value true.

 

You might also find the following help sources useful:

Cheat sheet comparison of C#, VB.NET, Java, COBOL:
https://www.microfocus.com/documentation/visual-cobol/vc50/ComparisonCBLManagedLangs.pdf

Convert C# to COBOL tool:
https://cs2cobol.microfocuscloud.com/

Highlighted
Super Contributor.
Super Contributor.

Re: How can I initialize a Boolean value?

Jump to solution

Wow, that's quite a great tool you're suggesting!! Very valuable! 👍👍

Yesterday, I already found the cheat sheet by googling, but it doesn't provide information for the WORKING-STORAGE SECTION, so I was uncertain. I'm still uncertain about when to declare a data item in the WORKING-STORAGE SECTION or in PROCEDURE DIVISION using declare.

From my point of view, the documentation pages lack examples. May I propose to add 1 - 2 short sample snippets to documentation pages explaining a language feature? It often sheds great light on a language feature.

May I ask: How do you provide code snippets here in the forum? I don't have the menu items available here in the forum to enter code snippets. It's available with this message as I'm replying to your answer, but usually I don't have these additional menu items available here. This feature doesn't seem to be granted for my account, so I have to manually format code snippets, which becomes rather tedious from time to time. (PS: I just noticed that the code snippet generator in this forum doesn't provide syntax highlighting for the COBOL language.)

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: How can I initialize a Boolean value?

Jump to solution

Yesterday, I already found the cheat sheet by googling, but it doesn't provide information for the WORKING-STORAGE SECTION, so I was uncertain. I'm still uncertain about when to declare a data item in the WORKING-STORAGE SECTION or in PROCEDURE DIVISION using declare.

It mostly comes down to personal preference. Traditional COBOL programmers might prefer the procedural style, declaring all the local variables under working-storage whilst programmers coming from languages such as C# or JAVA might prefer the declare syntax. Keep in mind that the declare syntax can not be used to declare COBOL like data such as PICTURE items or COBOL pointers, these can only be declared in the data division (either inside the class or inside the method).

From my point of view, the documentation pages lack examples. May I propose to add 1 - 2 short sample snippets to documentation pages explaining a language feature? It often sheds great light on a language feature.

Thank you for the suggestion. We do provide a set of samples with Visual COBOL, you can find these under Visual COBOL Samples in the start menu. There are several samples for different technology stacks such as WinForms, WPF, etc as well as interoping with native code, and using some of the .NET mechanics. We try to keep them up to date with the recommended syntax.

May I ask: How do you provide code snippets here in the forum? I don't have the menu items available here in the forum to enter code snippets. It's available with this message as I'm replying to your answer, but usually I don't have these additional menu items available here. This feature doesn't seem to be granted for my account, so I have to manually format code snippets, which becomes rather tedious from time to time. (PS: I just noticed that the code snippet generator in this forum doesn't provide syntax highlighting for the COBOL language.)

Hmm, you may need to click the "expand toolbar" button. I then click the "Insert/Edit code sample" button and type the code into the input box. There is also a HTML mode when you can just use <code> or <pre> tags. Personally I'd rather it allowed the use of markdown but I unfortunately don't have any knowledge or control over the configuration of the platform.

Highlighted
Super Contributor.
Super Contributor.

Re: How can I initialize a Boolean value?

Jump to solution

I don't seem to have that option available:

Forum editor options.png

 

Perhaps I should ask in the appropriate Micro Focus forum. They may be able to help me to that regard.

 

> We do provide a set of samples with Visual COBOL

I was rather thinking of a more context related approach. You know, for example, when I'm searching the index for a keyword and the website then redirects me to a page explaining that keyword, a set of simple, very scarce examples would be very helpful right at the bottom of that page.

For instance:

Add samples to documentation.gif

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: How can I initialize a Boolean value?

Jump to solution

@BlackKnight,

Re: the code snippets option not being visible -  are you looking at the site on a tablet by any chance ? Out of curiosity I just tried it on my iPad and the option is missing in both Chrome and Safari if I view the site in portrait mode but it is okay in landscape so it looks like the additional editor options are not displayed if the view is not wide enough.

Gael

Highlighted
Micro Focus Expert
Micro Focus Expert

Re: How can I initialize a Boolean value?

Jump to solution

On the subject of Booleans and condition-value, the term 'Boolean' in COBOL (ISO2002 standard and IBM dialects) is used to denote a PIC 1 data item, which can be either USAGE DISPLAY or USAGE BIT.  The PIC clause associated with it can have (only) 1 characters, e.g. PIC 1(8), and can be used for individual bit settings which can be tested using boolean operands b-and etc.  In my opinion, this is a somewhat flawed concept as its conversion to a binary integer is not fully specified in the standard, meaning there can be portability problems between big-endian and little-endian machines.

When implementing COBOL for .NET (and later for JVM), it seemed much more useful to define a simple data type corresponding to the C# bool (and Java boolean), mapping onto System.Boolean (or java.lang.Boolean).  To avoid confusion with the existing boolean data type, and because it seemed a more descriptive (and less computer sciency) term this was called condition-value.  In common with C# and Java, it is restricted to values true or false.

 

Tags (1)
Highlighted
Super Contributor.
Super Contributor.

Re: How can I initialize a Boolean value?

Jump to solution

@Gael Wilson: Splendid observation! Thanks for figuring out the issue I had!

You're absolutely right. When I decrease the zoom level in my browser, the triple-dot eclipse character with all the additional options therein appears.

Great! 😊

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.