bopsbanks.blogg.se

Cobol file read
Cobol file read









cobol file read

Also note that the paragraph print only consists of this: print. , appears at the *end* of the control structure. if ((i + j) > k) and ((j + k) > i) and ((k + i) > j) then perform triangle perform print else If the input data is not valid, it moves “Not a triangle” to the string a-message, then performs the paragraph print. The if statement below checks to see if the sides input form a valid triangle, and if they do, it then calls the paragraph (like a subroutine) triangle, using the perform statement. That is one of the core benefits of Cobol – the ability to construct a record and read in the entire entity.Īlso in the paragraph computation is the initial processing of the data. Note that the three values in the file can be read using the record handle integer-triple, and don’t need to be input individually. The first portion of this paragraph opens the file, and begin reading from it. Here, the paragraph computation is invoked, followed by the file closing, and the program termination. Next we move onto the procedure division, where the work begins (this is sort of like main in C).

cobol file read

The variable a-message holds the value of the output string. If no sides are equal, the value of match will be 0, if two sides then match=1, else if all three are equal, match=3. In this case, another “record” is created, match, which holds the value being calculated. The working storage section of the Cobol program contains variables needed during the processing. Inside this record there are three variables, i, j, and k which will hold the three values of the lengths of the triangle sides.

cobol file read

After specifying the file descriptor ( fd) to expand upon we set up what is essentially a “record”, called integer-triple. Then in the data division portion of the program we can set up the data to handle reading from file in the file section. It assigns a handle, input-file to the file to open, which in this case is hard-coded, and specifies the organization of the file as line sequential. Files are set up in the environment division. This program reads input from the file triangle.txt, which contains the values “30 60 90”. If ((i + j) > k) and ((j + k) > i) and ((k + i) > j) then perform triangleĬobol programs more often than not will take input from a file. Select input-file assign to "triangle.txt" Here is the program to consider: identification division.Įnvironment division.

#Cobol file read how to

Anyways, the focus here is on showing how to read from a file (one of Cobol’s forte’s), and the if statement. I say complex, because likely the same program in C would be shorter. Here is a more “complex”program to calculate the type of a triangle given the lengths of the three sides:, i.e.











Cobol file read