picture clauses

CobolScript® Picture Clauses

The picture clause is a byte-by-byte definition of the format of a variable. It describes the general characteristics and editing requirements of an elementary data item, which can be either numeric or alphanumeric in CobolScript. For example, a picture clause of PIC X(1) represents a variable that has 1 byte of alphanumeric storage, while a picture clause of PIC 9(02) represents a variable that has 2 bytes of numeric storage (the zero in 9(02) is not required).

The general format of a variable definition is:

<level-number> <variable> PIC <picture-clause> [VALUE <value-literal>].

where level-number is the level number of the variable, variable is the variable name, picture-clause is the numeric or alphanumeric picture clause, and value-literal is an initial value for the variable, either an alphanumeric literal, such as `abc`, or a numeric literal, such as 157. Below are some example variable definitions:

1 variable_1 PIC X(10) VALUE `abcdefghij`.

1 variable_2 PIC Z,999 VALUE 123.

Following are definitions of the allowed components of CobolScript picture clauses.

Alphanumeric Picture Clauses

Alphanumeric picture clauses use an X to represent a single byte of storage; a single-byte alphanumeric variable will have a picture clause of PIC X, while a five-byte alphanumeric can be defined as PIC XXXXX, PIC X(5), or PIC X(05).

PIC X(n)

CobolScript also provides a special alphanumeric picture clause - PIC X(n). PIC X(n) can be used for FILLERs, or for any alphanumeric variables with initial values specified in VALUE clauses. PIC X(n), when specified, automatically calculates the length of the value specified in the VALUE clause, and allocates this number of bytes to the FILLER or variable. For example, the following FILLER definition:

5 FILLER PIC X(n) VALUE `testing`.

will allocate seven bytes of space to an alphanumeric FILLER variable as the variable is assigned the value testing. This can also be written in a shorthand as follows, eliminating the keywords from the definition:

5 `testing`.

The above form is called an implied filler variable, and can be used for any PIC X(n) FILLER variable that has a VALUE clause.

Numeric Picture Clauses

Basic numeric picture clauses use a 9 to represent a single byte of storage; a single-digit, single-byte numeric variable will have a picture clause of PIC 9, while a five-digit, five-byte numeric variable can be defined as PIC 99999, PIC 9(5), or PIC 9(05).

Signed Numeric Variables

Signed numeric variables use an S to represent the sign, followed by a normal numeric picture clause. The S indicates that a sign value will be maintained at the leftmost byte position. PIC S9(05) is an example of a signed numeric variable.

Implied Decimal Points

An implied decimal point in a numeric picture clause is represented by a V. The V indicates that an invisible decimal point will exist between the two digits on either side of the V. All calculations performed on this number will behave as if there is a normal decimal point in the location of the V. For example, a picture clause of PIC 999V99 represents a five-digit number with an implied decimal; three of the digits are left of the decimal point, and two are post-decimal digits.

Literal Decimal Points

An actual decimal point in a numeric picture clause is represented by a period. The period indicates the position of the literal decimal point; the decimal point will display when the variable is displayed, and all internal calculations will be based on this decimal position. For example, a picture clause of PIC 999.99 represents a five-digit number with two decimal places that requires six bytes of storage (an additional byte of storage is required for the period).

Numeric Edited Picture Clauses

Numeric edited picture clauses are numeric clauses in which certain symbols have been placed within the number, for purposes of clarity or legibility when the number is displayed. Like a literal decimal point, each edit symbol added to the picture clause requires an additional byte of storage.

Commas

Commas can be placed within a numeric picture clause to clarify number size, as in the numbers 1,000 and 2,345,678. The comma is placed between the digits of the picture clause where it should appear when the number is displayed. For instance,

PIC 99,999 VALUE 45678.

would display as 45,678.

Zero Suppression

Leading zeros can be suppressed in numbers by replacing the usual 9 with a Z wherever the suppression is desired. Suppression terminates at the first non-zero digit in the number, or at the first 9 in the picture clause, whichever comes first. For instance, if two variables have the following picture clauses:

PIC Z,Z99.99 VALUE 123.55.

PIC Z,Z99.99 VALUE 3.55.

the numbers will display as ` 123.55` and ` 03.55`, respectively.

Floating Dollar Sign

In addition to suppressing leading zeros like a Z, dollar signs in a numeric picture clause will force a $ to be displayed in place of the rightmost zero that is suppressed. For example, the picture clause:

PIC $,$$$.99 VALUE 123.55.

will display as ` $123.55`.

Asterisk Check Protection

The replacement of leading zeros in numeric character positions with asterisks is indicated by the use of the * symbol. For example, the picture clause:

PIC *,***.99 VALUE 123.55.

will display as `**123.55`.

Floating Plus Sign

In addition to suppressing leading zeros like a Z, plus signs in a numeric picture clause will force a + to be displayed in place of the rightmost zero that is suppressed if the number is positive, and a - if the number is negative. For instance, if two variables have the following picture clauses:

PIC +,+++.99 VALUE 123.55.

PIC +,+++.99 VALUE -123.55.

the numbers will display as ` +123.55` and ` -123.55`, respectively.

Floating Minus Sign

In addition to suppressing leading zeros like a Z, minus signs in a numeric picture clause will force a - to be displayed in place of the rightmost zero that is suppressed if the number is negative. For instance, if two have the following picture clauses:

PIC -,---.99 VALUE 123.55.

PIC -,---.99 VALUE -123.55.

the numbers will display as ` 123.55` and ` -123.55`, respectively.

Plus Sign Control

Numeric edited variables with plus sign control have a plus sign as the rightmost symbol in the picture clause. When the variable has a positive value, a + will be displayed as the rightmost symbol in the number; when the variable has a negative value, a - will be displayed as the rightmost symbol. For instance, if two variables have the following picture clauses:

PIC Z,999.99+ VALUE 123.55.

PIC Z,999.99+ VALUE -123.55.

the numbers will display as ` 123.55+` and ` 123.55-`, respectively.

Minus Sign Control

Numeric edited variables with minus sign control have a minus sign as the rightmost symbol in the picture clause. When the variable has a negative value, a - will be displayed as the rightmost symbol; when it has a positive value, the minus sign will be suppressed. For instance, if two variables have the following picture clauses:

PIC -,---.99 VALUE 123.55.

PIC -,---.99 VALUE -123.55.

the numbers will display as ` 123.55 ` and ` 123.55-`, respectively.

DB Control

Numeric edited variables with DB control have the letters DB in the rightmost position of the picture clause. When the variable has a positive value, DB will be displayed right of the number; when the variable has a negative value, CR will be displayed to the right of the number. For instance, if two variables have the following picture clauses:

PIC Z,999.99DB VALUE 123.55.

PIC Z,999.99DB VALUE -123.55.

the numbers will display as ` 123.55DB` and ` 123.55CR`, respectively.

CR Control

Numeric edited variables with CR control have the letters CR in the rightmost position of the picture clause. When the variable has a negative value, CR will be displayed to the right of the number; if the number is positive, display of the CR is suppressed. For instance, if two variables have the following picture clauses:

PIC Z,999.99CR VALUE 123.55.

PIC Z,999.99CR VALUE -123.55.

the numbers will display as ` 123.55 ` and ` 123.55CR`, respectively.

Replica and Occurs variables

Besides group item, alphanumeric elementary item, and numeric elementary item variables, two other variable forms are possible in CobolScript: REPLICA variables and OCCURS clause variables. For in-depth discussion of these two forms, refer to Chapter 3, CobolScript Language Constructs.

Picture Clause Examples

The following table contains examples that illustrate how literal values will display when moved to variables with certain CobolScript picture clauses. The Value of Sending Field and Displayed Result columns’ text is highlighted to accentuate any spaces that may or may not be displayed.

Picture Type

Value of Sending Field

Picture of Receiving Field

Displayed Result

Alphanumeric

12345678901234567890

X(20)

12345678901234567890

Alphanumeric

`Cbscript`

XXXXXXXXXX

Cbscript `

Numeric

12345

99999

12345

Signed Numeric

12345

S9(05)

+12345

Signed Numeric

-12345

S9(05)

-12345

Numeric with Implied Decimal

12345

9(05)V99

1234500

Numeric with Implied Decimal

12345

99999V99

1234500

Numeric with Literal Decimal

12345

99999.99

12345.00

Numeric Edited with Zero Suppression

12345

ZZZZZZZZ

` 12345

Numeric Edited with Zero Suppression And Comma

12345

ZZ,ZZZ,ZZZ.99

` 12,345.00

Numeric Edited with Floating Dollar Sign

12345

$$,$$$,$$$.99

` $12,345.00

Numeric Edited with Asterisk Check Protection

12345

**,***,***.99

****12,345.00

Numeric Edited with Floating Plus Sign

12345

++,+++,+++.99

` +12,345.00

Numeric Edited with Floating Plus Sign

-12345

++,+++,+++.99

` -12,345.00

Numeric Edited with Floating Minus Sign

12345

--,---,---.99

` 12,345.00

Numeric Edited with Floating Minus Sign

-12345

--,---,---.99

` -12,345.00

Numeric Edited with Plus Sign Control

12345

ZZZ,ZZZ.99+

`12,345.00+

Numeric Edited with Plus Sign Control

-12345

ZZZ,ZZZ.99+

`12,345.00-

Numeric Edited with Minus Sign Control

12345

ZZZZZZZ-

` 12345`

Numeric Edited with Minus Sign Control

-12345

ZZZZZZZ-

` 12345-

Numeric Edited with DB Control

12345

ZZZ,ZZZ.99DB

`12,345.00DB

Numeric Edited with DB Control

-12345

ZZZ,ZZZ.99DB

`12,345.00CR

Numeric Edited with CR Control

12345

ZZZCR

345 `

Numeric Edited with CR Control

-12345

ZZZCR

345CR