Highlighted
Absent Member.
Absent Member.
1214 views

How to compare to values range

Jump to solution

Hi,

Is it possible to compare to a range of values in COBOL? I'm thinking of something like this:

if account-id between 1 and 7 then

perform debit-internal-account

else

debit-customer-account

end-if

Regards

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

RE: How to compare to values range

Jump to solution

Here's another technique, a little closer to your original request:

01 account-id                   pic 9.

    88 account-id-valid     values are 1 through 7.

if account-id-valid then

  perform debit-internal-account

else

  perform debit-customer-account

end-if

If you do it with 88's, then the semantics of the test is only one place in your code, rather than being spread through out the procedure division.  Then, when you decided to add 8 to the valid values, you only have to change one place.

Michael Schultz
Software System Developer - Senior Principal

View solution in original post

0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: How to compare to values range

Jump to solution

I figured it out, I used the following syntax

evaluate account-id

when 1 thru 7

perform debit-internal-account

when other

perform debit-customer-account

end-evaluate

 

ME ANSWERING MY SELF Stick out tongue So Crazy of Me!

Tags (1)
0 Likes
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

RE: How to compare to values range

Jump to solution

Here's another technique, a little closer to your original request:

01 account-id                   pic 9.

    88 account-id-valid     values are 1 through 7.

if account-id-valid then

  perform debit-internal-account

else

  perform debit-customer-account

end-if

If you do it with 88's, then the semantics of the test is only one place in your code, rather than being spread through out the procedure division.  Then, when you decided to add 8 to the valid values, you only have to change one place.

Michael Schultz
Software System Developer - Senior Principal

View solution in original post

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.