Supported RPG Features

Type RPG Keyword JVM Mapping
Packed decimal P, PACKED PackedDecimal (BigDecimal wrapper)
Zoned decimal S, ZONED ZonedDecimal
Alpha (fixed) A RpgString
Alpha (varying) A + VARYING/VARCHAR java.lang.String
Integer I, INT int or long
Unsigned U, UNS int or long
Indicator N, IND boolean
Date D, DATE RpgDate
Time T, TIME RpgTime
Timestamp Z, TIMESTAMP RpgTimestamp
Float F, FLOAT float or double
Graphic (DBCS) G, GRAPH RpgString (2 bytes/char for %SIZE)
Graphic (varying) VARGRAPH java.lang.String (2 bytes/char plus the length prefix for %SIZE)
UCS-2 (fixed) C, UCS2 RpgString (2 bytes/char for %SIZE)
UCS-2 (varying) VARUCS2 java.lang.String (2 bytes/char plus the length prefix for %SIZE)

Length-prefix width. A varying type takes an optional second argument giving the width of its length prefix in bytes: VARCHAR(5 : 4), VARGRAPH(3 : 4), VARUCS2(3 : 4). Only 2 (the default) and 4 are meaningful; any other value is warned about and the effective width is 2. The CHAR(n) VARYING(4) keyword form is equivalent to VARCHAR(n : 4).

Graphic and UCS-2 share a storage model but convert differently: character data assigns to (and compares with) a UCS-2 field implicitly, while a graphic field participates in no implicit string conversion at all - mixing graphic with character or UCS-2 data, by assignment in either direction or by comparison, is rejected at compile time with TRN1534. Use %CHAR, %GRAPH, or %UCS2 to convert explicitly.

For an externally-described field (from a DDS physical/logical file or a Db2 for i table), the graphic-vs-UCS-2 kind follows the field's CCSID: a DDS G field or a DB2 GRAPHIC/VARGRAPHIC column whose CCSID is a UCS-2 CCSID (13488 or 1200) is a UCS-2 field - so it accepts implicit character conversion - while any other CCSID leaves it graphic (implicit mixes stay TRN1534).

For the decimal types PACKED, ZONED, and BINDEC, the decimal positions are optional. When omitted, the count defaults to zero, so ZONED(5) is equivalent to ZONED(5:0) and defines a whole-number field.

Assigning a value longer than an alpha field's declared length truncates the trailing characters, in both fixed- and free-format. For example, assigning the 8-character literal 'ABCDEFGH' to a 5A field stores ABCDE.