GRAPHIC

GRAPHIC explicitly converts character (or mixed character) data to GRAPHIC data. All other data first converts to character, and then to the GRAPHIC data type.

GRAPHIC returns the graphic value of x, with a length in graphic symbols specified by y.

The content of x is checked for validity during conversion, using the same rules as for checking graphic and mixed character constants.

Read syntax diagramSkip visual syntax diagram
>>-GRAPHIC(x-+----+-)------------------------------------------><
             '-,y-'     

x
Expression. When x is GRAPHIC, it is subject to a length change, with applicable padding or truncation. When x is nongraphic, it is converted to character, if necessary. SBCS characters are converted to equivalent DBCS characters.
y
Expression. If necessary, y is converted to a real fixed-point binary value. If y is omitted, the length is determined by the rules for type conversion.

y must not be negative.

If y = 0, the result is the null graphic string.

The following rules apply:
  • If y is greater than the length needed to contain the graphic string, the result is padded with graphic blanks.
  • If y is less than the length needed to contain the graphic string, the result is truncated.

Example 1

This example shows a conversion from CHARACTER to GRAPHIC. The target is long enough to contain the result.

  dcl X char (11) varying;
  dcl A graphic (11);
  A = graphic(X,8);
For X with values Intermediate result A is assigned
ABCDEFGHIJ
123
123A.B.C
  .A.B.C.D.E.F.G.H.I.J
.1.2.3
.1.2.3.A.B.C
.A.B.C.D.E.F.G.H.b.b.b
.1.2.3.b.b.b.b.b.b.b.b
.1.2.3.A.B.C.b.b.b.b.b

where .b is a DBCS blank.

Example 2

This example shows a conversion from CHARACTER to GRAPHIC. However, the target is too short to contain the result.

  dcl X char (10) varying;
  dcl A graphic (8);
  A = graphic(X);
For X with value Intermediate result A is assigned
ABCDEFGHIJ
.A.B.C.D.E.F.G.H.I.J
.A.B.C.D.E.F.G.H





Published: 23 December 2018