alejanecz Absent Member.
Absent Member.
834 views

Is possible to make Visual Cobol code shorter similar to something like that ?

string ReturnValue = Expression == true ? TruePart : FalsePart;

Using this the code would be shorter by 4 lines.

Tags (1)
0 Likes
1 Solution

Accepted Solutions
RobertSales Absent Member.
Absent Member.

We don't have any direct equivalent for this in COBOL syntax.  Of course, it's possible to do this in two lines in COBOL:

declare ReturnValue as string

if Expression set ReturnValue to TruePart else set ReturnValue to FalsePart end-if

...but probably most people would split this and use normal indentation for the sake of readability.

I think the C# (and C) '?' syntax is probably most useful in contexts like parameter passing, and it's certainly possible we might want to add a construct like this to the language at some point.

0 Likes
3 Replies
RobertSales Absent Member.
Absent Member.

We don't have any direct equivalent for this in COBOL syntax.  Of course, it's possible to do this in two lines in COBOL:

declare ReturnValue as string

if Expression set ReturnValue to TruePart else set ReturnValue to FalsePart end-if

...but probably most people would split this and use normal indentation for the sake of readability.

I think the C# (and C) '?' syntax is probably most useful in contexts like parameter passing, and it's certainly possible we might want to add a construct like this to the language at some point.

0 Likes
alejanecz Absent Member.
Absent Member.

Ok, thank you.

It's certainly possible to do it in two lines and it occurred to my mind but that's not what I'm looking for. I just like my code being simple but readable. That's why I very agree with you as for readability of code. But sometimes there're very simple parts of code with IF statement like following

IF (l-anItem <> NULL)

    set x to 1

ELSE

    set x to 0

END-IF

and in those cases such a syntax would be useful. Something like

move IIF(l-anItem <> NULL, 1, 0) to x

compute x = IIF(l-anItem <> NULL, 1, 0)

0 Likes
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

What you can do is write a Integrated Pre-processor that would expand the IIF syntax into standard Cobol code. That would mean that you code and animate the IIF statement, but actually execute the expanded code.

For more information have a look at the Integrated Preprocessor Interface section of the documentation.

Adrian Bean
Support Engineer, EMEA SupportLine

Micro Focus

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.