COBOL COMP/COMPUTATION

COBOL DISPLAY Computation COBOL COMP-1

Advertisements


COMP usage clause will be called as BINARY or COMPUTATION.

COMP usage clause applicable to Numeric data type only.

COMP usage is a binary representation of data.

The data in COMP variables stored memory in pure binary format.

The memory allocation for COMP USAGE is like below.


PictureNumber of Bytes
S9 to S9(4)2
S9(5) to S9(9)4
S9(9) to S9(18)8

Let’s take an example for displaying all data types which are passing through program and see how it is after writing to the program.


Practical Example:


Code:



The above example, writing the record from the working-storage record and see how it is displayed during the file browse.

In the program, all variables declared with COMP USAGE.

In COMP USAGE, the memory calculation was provided on the above table. So there should be change in the output when we displayed from file.

The program output writing to MTH.COMP.OUTPUT file.

The below output shows the output written by the program and it can’t be in user understandable format.

But hex-on output can be understandable based on the below calculations.

As everybody aware, the data storing in memory for the data will be in the format of bits.

Refer memory storage structure & memory format conversion topic here.


Jcl:



Output:



Hex-on Output:



Hex-on output always refers two layers. The data displays in each byte are a combination of both layers.

In the above hex-on output, 255 was displayed in two layers as


Diagram:



The calculations of the hex-on memory to its normal value like below.

For calculation, the lower left hand side byte will consider the first and next upper byte next move to 1 byte right and begins from lower and so on.

The below diagram can explain it very well about the positions of considerations.


Diagram:



Then it will apply the Hex-on to decimal calculation on the data showed in memory.


Diagram:



Hex on to decimal calculation for the above are



COMP-NM1 Decimal	
	= 163 * 0 + 162 * 0 + 161 * F + 160 * F
	= (4096 * 0) + (256 * 0) + (16 * F) + (1 * F)
	= 0 + 0 + (16 * F) + F
	= (16 * 15) + 15
	= 240 + 15
	= 255

COMP-NM2 Decimal	
	= 167*0 + 166*0 + 165*0 + 164*3 + 163*E + 162*4 + 161*9 + 160*8
	= (65536 * 3) + (4096 * E) + (256 * 4) + (16 * 9) + (1 * 8)
	= 196608 + 57344 + 1024 + 144 +8
	= 255128
	

Similarly the calculation would be same for COMP-NM3


COBOL DISPLAY Computation COBOL COMP-1

Advertisements