COBOL Data type Justifications

COBOL Set Verb COBOL Usage Clause

Advertisements


Justification only applies to Numeric, Alphabetic and Alpha-numeric among the 5 data types.

Justification only comes to picture when the data is larger or smaller than the actual declaration.

Numeric data type is right justified if the data is larger or smaller than the actual declaration.

Alphabet & alphanumeric data types are left justified.


Numeric Justification:


Case 1) Input is larger than the output variable.

If the Input is larger than the actual declaration, then the data will be moved from the right most byte to left upto the length of actual declaration.

The remaining bytes data in input will be lost.


Case 2) Input is smaller than the output variable.

If the Input is smaller than the actual declaration, then the data will be moved from the right most byte to left upto the length of actual declaration.

The remaining bytes in target data item will be filled with LOW-VALUES or ZEROES.

Let’s take an example for the above two cases.


Practical Example - Numeric:



NUMERIC-J1 declared with of length 3 and NUMERIC-J2 declared with of length 9.

256128 value moved to both fields.

After moving, NUMERIC-J1 is smaller than the value passed. Because of right justification the value should move from right to left upto the length declared.

So NUMERIC-J1 had the value 128.

After moving, NUMERIC-J2 is larger than the value passed. Because of right justification the value should move from right to left upto the length declared.

So NUMERIC-J2 had the value ooo256128.


Output:



Alpha-Numeric/Alphabetic Justification:


Case 1) Input is larger than the Output variable

If the Input is larger than the actual declaration, then the data will be moved from the left most byte to right upto the length of actual declaration.

The remaining bytes data in input will be lost.


Case 2) Input is smaller than the output variable.

If the Input is smaller than the actual declaration, then the data will be moved from the left most byte to right upto the length of actual declaration.

The remaining bytes in target data item will be filled with LOW-VALUES or SPACES.


Let’s take an example for the above two cases.


Practical Example - Alphabetic:



ALPHA-J1 declared with of length 10 and NUMERIC-J2 declared with of length 20.

MAINFRAMESTECHHELP value moved to both fields.

After moving, ALPHA-J1 is smaller than the value passed. Because of right justification the value should move from left to right upto the length declared.

So ALPHA-J1 had the value MAINFRAMES.

After moving, ALPHA -J2 is larger than the value passed. Because of right justification the value should move from left to right upto the length declared.

So ALPHA -J2 had the value MAINFRAMESTECHHELP.


Output:



Practical Example - Alphanumeric:



ALPHA-J1 declared with of length 10 and NUMERIC-J2 declared with of length 20.

MAINFRAMESTECHHELP value moved to both fields.

After moving, ALPHA-J1 is smaller than the value passed. Because of right justification the value should move from left to right upto the length declared.

So ALPHA-J1 had the value MAINFRAMES.

After moving, ALPHA -J2 is larger than the value passed. Because of right justification the value should move from left to right upto the length declared.

So ALPHA -J2 had the value MAINFRAMESTECHHELP.

ALPHA-J3 declared with of length 10 and NUMERIC-J2 declared with of length 20.

256123 value moved to both fields.

After moving, ALPHA-J3 is smaller than the value passed. Because of right justification the value should move from left to right upto the length declared.

So ALPHA-J3 had the value 256.

After moving, ALPHA –J4 is larger than the value passed. Because of right justification the value should move from left to right upto the length declared.

So ALPHA –J4 had the value 256123.


Output:



COBOL Set Verb COBOL Usage Clause

Advertisements