What is the equivalent of type Cobol 88 in other languages?

Now I am learning COBOL and really like variables like 88, and I want to know if there is something like them in other languages โ€‹โ€‹(most well-known languages โ€‹โ€‹also, for example, C, Objective-C), even using the library.

The only thing I can think of is to use

#define booleanResult (variableName==95) 

But it is impossible to set boolenResult to true and make variableName read the value 95.

+4
source share
4 answers
 05 nicely-named-data PIC X. 88 a-meangingful-condition VALUE "A". 88 another-meaingingful-condition VALUE "A" "B" "X" THRU "Z" SPACE ZERO. IF a-meaningful-condition IF another-meaningful-condition SET a-meaningful-condition TO TRUE SET another-meaningful-condition TO TRUE 

IFs check the value referenced by name-name (conditional variable) that 88 (condition name) is associated with for a single value or one of several values, which may include ranges (THRU) and figurative constants (ZERO, SPACE, LOW- VALUES etc.).

SET, which in this form is a later addition to COBOL from the 1985 Standard, will change the data-name value to the first value indicated at 88, so if you immediately refer to 88 in the test, the test will be true.

COBOL has no logical meanings in the sense of something allowing 0 or 1 or something else, false / true.

Any language that supports objects can be used to simulate behavior. You may have already done this without even realizing it.

As NealB notes in the comments, functions can be used (either a procedure or transferring control to another module), but the data and links to it will not be together and protected from accidental harm.

COBOL has great flexibility in defining data structures. The 88 level is a powerful tool for supporting and understanding programs, as well as writing them first.

I do not know another language that has a direct and natural element that is equivalent to this, but then there are many languages โ€‹โ€‹that I do not know.

Again, NealB makes an important point in the comments about using THRU / THROUGH to specify a range of values.

Care must be taken. Although the author might think that the data they want to select may be represented by the range โ€œ010โ€ THRU โ€œ090โ€, they may not understand that what the compiler does is to include every possible value in this range, generating code greater than or equal to "010" and less than or equal to "090".

If you use THRU, make sure your data cannot contain anything in the range that is not expected. If you mean "010" "020" "030" ... "090", it is normal if the data is checked at its entry point so that it never includes any intermediate values.

Classic example: "A" THRU "Z" on the mainframe. We all know what the author means, but the compiler takes it literally. You cannot use "A" THRU "Z" on your own for verification, because in EBCDIC there are "gaps" between three groups of letters, and using "A" THRU "Z" will consider these spaces as true for 88.

When level 88 in some COBOL compilers falls, it is in the absence of "FALSE".

For reuse from the above example:

  88 a-meaingingful-condition VALUE "A". 88 a-meaingingful-condition-NOT VALUE "N". 

To check the switch / flag, you use the first 88. To disable flag.switch, you must use the second. Not perfect. See One of the links below for an example of FALSE in definition 88.

In the old days, flags / switches and reset were set with MOVE statements. Once MOVE is activated, you have the same problems as when you try to use the functions. There is no related relationship between MOVE and VALUE level 88.

These days, SET can be used to change the value of a field, to turn on / off a flag / switch.

  05 FILLER PIC X. 88 a-meaingingful-condition VALUE "A". 88 a-meaingingful-condition-NOT VALUE "N". 

The test field does not even need a name (it can be FILLER or omitted (implied FILLER)).

Of course, as NealB notes in a comment on one of the links below, someone can still get the field using MOVE, using the modification link for the group element. So that...

 01 FILLER. 05 FILLER PIC X. 88 a-meaingingful-condition VALUE "A". 88 a-meaingingful-condition-NOT VALUE "N". 

Now they cannot use the standard link modification, since there is no name for the name. A field value can only be obtained from the VALUE clause in the definition or from a SET statement that sets one of 88s to TRUE.

At the stage, the value that the flag / switch has, its actual value, becomes irrelevant.

 01 FILLER. 05 FILLER PIC X(7). 88 a-meaingingful-condition VALUE "APPLE". 88 a-meaingingful-condition-NOT VALUE "BICYCLE". 

Since nothing can be used to check for literal / name-name, and the field cannot be the object of any verb other than SET, you no longer need to check that all fields that say they contain N or Y, or 0 or 1, do this, and they are not the wrong case, and no other values โ€‹โ€‹will be placed in these fields.

I do not suggest using APPLE and BICYCLE, just using them to illustrate the point.

88 can also have a value expressed in hexadecimal notation, like any alpha-numeric field:

  88 a-meaingingful-condition VALUE X"25". 

Sign 88 may also be indicated in a group element, usually with a figurative constant as the value:

 01 a-group-item. 88 no-more-data-for-matching VALUE HIGH-VALUES. 05 major-key PIC X(10). 05 minor-key PIC X(5). 

In the process of matching files, the keys can be set to high values โ€‹โ€‹at the end of the file, and using the keys will still lead to the correct processing of other files (the keys are lower than this file).

Here are links to a number of SO questions directly or related to important issues, up to 88 levels.

Level Data Type 88 COBOL

Group variable in cobol

In Cobol, we use "NOT = SPACE [AND / OR] LOW-VALUE") to check for "null or empty".? What is it?

Does the prefix "NO" have any special meaning in the COBOL variable?

Verifying COBOL data for an uppercase letter?

+10
source

My first programming language was Cobol, now I use C #, and here is my solution for the Cobol 88 level:

In Cobol:

 01 ws-valid-countries pic xx. 88 valid-country 'US', 'UK' 'HK'. move ws-country to ws-valid-countries if valid-country perform... 

in c #

 string[] ValidCountries = {"US","UK","HK"} ; if ( ValidCountries.Contains(newCountry.Trim().ToUpper()) ) { // do something 
+2
source

Think of it as a boolean getter (essentially the same as in your macro) and setter (causing the variable to be the corresponding value). Who said COBOL was not modern in 1965?

+1
source

As others have said, just programming objects. It is more powerful, but much less elegant. For instance:

 01 MY-DATASET. 05 MY-DEPARTEMENT PIC 9(2). 88 ILE-DE-FRANCE VALUES 75, 77, 78, 91 THRU 95. 

You can copy in the old VBA in a class named MyDataset:

 Public MyDepartement As Integer Property Get IleDeFrance() As Boolean Dim MyArray() As Variant MyArray = Array(75, 77, 78, 91, 92, 93, 94, 95) IleDeFrance = UBound(Filter(MyArray, MyDepartement, True)) > -1 End Property 

(just tested, it works on VBA-excel2013) And I made VBA as simple as possible, not a clean getter or setter for the department number, just public data. Since a class is a data warehouse and encoded actions against them, you can do more things than a simple 88-level one (this is probably why this function does not correspond to more modern languages). But at the price of complexity and readability.

Less elegant, because the array must be defined definitely, and it is also necessary to check the presence in it. Although this is inherent in a wonderful 88 level.

-1
source

Source: https://habr.com/ru/post/1216385/


All Articles