sign in
 
   
 
 
 
   
  COBOL TUTORIAL FOR BCA STUDENTS OF M G UNIVERSITY  
  UNIT 3: INTRODUCTION TO COBOL . . .  
   
     
  PICTURE CLAUSE  
 

The picture clause describes the general characteristics of an elementary data item. These characteristics are described below:

 
  Class  
 

In COBOL a data item may be one of the three classes - numeric, alphabetic or alphanumeric. The numeric items consist only of digits 0 to 9. Alphabetic items consist only of the letters A to Z (a to z) and the space (blank) character. The alphanumeric items may consist of digits, alphabets as well as special characters.

 
 

Sign

 
 

A numeric data item can be signed or unsigned. If a numeric data is considered as unsigned then during execution such unsigned data items are treated as positive quantities. To describe a signed data item one should use the code character S at the leftmost end of the picture clause of the corresponding variable. It is important to note that internally, the operational sign (S) is not stored as a separate character. The operational sign is stored at the zone bits of the rightmost digit position of the data item. While preparing data for such an input-signed item, care should be taken to ensure that the data appears on the input medium in the same form.

 
  Point Location  
 

The position of the decimal point is another characteristic that can be specified in the case of numeric data items. If the said position is not specified, the item is considered to be an integer which means that the decimal point is positioned immediately after the rightmost digit. It may be noted that in COBOL the decimal point is not explicitly included in the data.

The position of the decimal point is merely an assumed position.

The compiler at the time of compilation only makes a note of this assumed decimal point. It generates the object code in such a way that the data items before taking part in the operations are aligned according to their assumed decimal points.

 
  Size  
 

The number of characters or digits required to store the data item in the memory in known as Size of the data item.

 
   
  PICTURE CLAUSE - Syntax  
 

All the four general characteristics described above can be specified through a PICTURE clause. The PICTURE clause is to be followed by a picture character string as shown below:

 
   
 


The character string can consist of 1 to 30 code characters that define the above mentioned attributes of the elementary item. The code characters and their meaning are given below:

 
   
 


There is no special code to indicate the size. The total number of occurrence of 9, X or A in the picture string indicates the size. The occurrence of V, P and S are not counted in determining the size of an item.

The allowable combinations are governed by the following rules:

In the case of an alphabetic item the picture may contain only the symbol A.

In the case of a numeric item the picture may contain only the symbols 9, V, P and S. These are called operational characters. It must contain at least one 9. The symbols V and S can appear only once and S, if it is included, must be the leftmost character of the picture string. The symbol P can be repeated on the right or on left (but not on the left of S) as many times as is required to indicate the position of the assumed decimal point.

In the case of an alphanumeric item, the picture may contain all Xs or a combination of 9, A and X (except all 9 or all A). In the latter case the item is considered as if the string consists of all Xs.

The picture clause is only to be specified for elementary items; it cannot be used for a group item. The size of a group item is equal to the total of the sizes of all subordinate elementary items. The class of a group item is alphanumeric.

The following examples illustrate the PICTURE specification.

Example 1:

PICTURE IS S999V99

- represents a signed data item with a size of 5 characters and the positions of the assumed point is before 2 places from the rightmost end. Note that S and V are not counted.

Example 2:

PIC IS PPP9999

- means that the numeric data is of 4 characters in size and there are 7 positions after the assumed decimal point. Thus if the data in the memory is 123, the value will be taken as .0000123. If, on the other hand, the picture were defined as 999PP, the value would have been 12300.

Example 3:

PIC XXXXXX

- represents the alphanumeric item with size of 6 characters.

Instead of repeating 9, X, A or P in the picture string, it is possible to write the number of occurrences of a character enclosed within parenthesis immediately after the said character.

Thus S9(3)V9(2) is equivalent to S999V99.

X(7) is equivalent to XXXXXX.

P(4)9(3) is equivalent to PPPP999.

 
     
  VALUE CLAUSE  
 

The value clause defines the initial value of the data item. Generally initialization will be done just before the first statement in the procedure division is executed.

The syntax is

VALUE is literal

The literal can be any numeric value, a nonnumeric string of characters included within
quote(“) or any figurative constant.

Examples :

01 a pic value is 100
01 compname pic x(15) value is “ABC Company”
01 n pic 9(2) value is ZERO
01 ans pic x value is space
01 result pic x(4) value spaces.

For Group Data value specification
01 test-entry value is “123456”.
02 t1 pic 9(2).
02 t2 pic 9(2).
02 t3 pic 9(2).

Here t1=12,t2=34 and t3=56.