Justified Clause
Justified Clause Example
Scenario - Below example describes how the JUSTIFIED clause used in COBOL programming.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. RJUSTIFY.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR PIC X(15).
01 WS-SM-VAR PIC X(07).
01 WS-RJE-VAR PIC X(15) JUSTIFIED RIGHT.
01 WS-RJL-VAR PIC X(07) JUSTIFIED RIGHT.
PROCEDURE DIVISION.
MOVE "MAINFRAMES" TO WS-VAR
WS-SM-VAR
WS-RJE-VAR
WS-RJL-VAR.
DISPLAY "WS-VAR :" WS-VAR ":".
DISPLAY "WS-SM-VAR :" WS-SM-VAR ":".
DISPLAY "WS-RJE-VAR :" WS-RJE-VAR ":".
DISPLAY "WS-RJL-VAR :" WS-RJL-VAR ":".
STOP RUN.
Output -
WS-VAR :MAINFRAMES : WS-SM-VAR :MAINFRA: WS-RJE-VAR : MAINFRAMES: WS-RJL-VAR :NFRAMES:
Explaining Example -
In the above example:
- "MAINFRAMES" string moved to all the variables. However, WS-SM-VAR, WS-RJL-VAR are smaller than the string assigned. So, WS-SM-VAR having value "MAINFRA" due to the default left justification and the truncation happens right side.
- WS-RJL-VAR having "NFRAMES" due to the right justification and truncation happens at the left side.