Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 5: Data Division


PICTURE clause (and Data types in COBOL)

  • PICTURE clause is used to specify the characteristics of the Elementary Data-Item such as Data-type, Sign, Decimal point location, Size etc.
  • PICTURE clause can also be specified as PIC
  • PICTURE clause can be used only with elementary data-item
  • PICTURE clause cannot be used with group data item, 88 level number, USAGE IS COMP-1 & COMP-2
  • Below is explanation of characteristics that can be defined using PICTURE clause:-
  • Data Type: -
    • Any data-item can be of data-type: numeric, alphabetic, or alphanumeric.
    • The numeric data type can consists of only digits 0-9. This data type can be used for variables such as Price, Quantity, Total value
    • The alphabetic data type consist only of letters A-Z or a-z and the space(blank). This data type can be used for variables such as Name, Item Description etc.
    • The alphanumeric data type consist of digits, letters, space and special characters. This data type can be used for variables such as Address, Date etc.
    • These data type can be specified in PIC clause using code characters shown in table below:- here <LINK to code character table>
  • Sign :-
    • A numeric data item can be either signed or unsigned
    • If considered unsigned then during program execution these data items are treated as positive quantities
    • Code character ‘S’ is used at the leftmost end of PIC clause to describe that data item is signed data item
    • Sign does not occupy extra space as it is stored at the zone bits(first four bits of a byte) of rightmost digit of data item.
  • Decimal point location:-
    • Decimal point location can be specified for Numeric data item using code character ‘V’ PIC clause
    • If not specified numeric data item will be considered as integer
    • The position of decimal point is merely an assumed position and it is not explicitly included in data(i.e. it does not occupy space in storage)
  • Size:-
    • The number of characters or digits required to store data item is known as Size of data item
    • There is no special code character to represent the size of data-item. Size can be specified by the repeated occurrence of representing code characters or by specifying number in parentheses. Example: - ‘PIC XXX’ means three character alphanumeric string. Same declaration can also be specified as ‘PIC X(3)’
  • Below table describes the code characters that can be used to specify Data-type, Sign and Decimal point of Data-item

Code character Description
9 Used to specify Numeric data type. Can hold digits 0-9 only
A Used to specify Alphabetic data type. Can hold letters (A-Z), (a-z), space(blank)
X Used to specify Alpha-numeric data type. Can hold letters (A-Z), (a-z), space(blank), digits (0-9) and special characters
S Used with Numeric data type to indicate that the data item is signed
V Used with Numeric data type to indicate the position of implicitly assumed decimal point
P Used with Numeric data type to indicate the position of assumed decimal point when the point lies outside the data item
  • Important points need to remember while using PIC clause:-
    • As specified above, there is no special code character to represent the size of data-item. Size can be specified by the repeated occurrence of representing code characters or by specifying number in parentheses. Example: - ‘PIC XXX’ means three character alphanumeric string. Same declaration can also be specified as ‘PIC X(3)’
    • The picture clause is only to be specified for elementary items; it cannot be used for a group item.
    • The occurrence of ‘V’, ‘P’ and ‘S’ are not counted in determining the size of an 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.
    • When specifying Alphabetic data item: the PIC must contain only code character ‘A’
    • When specifying Numeric data item: the PIC must contain only code character ‘9’, ‘S’, ‘V’ and ‘P’. The code character ‘V’ and ‘S’ can be specified only once. When used ‘S’ it must be at the leftmost position of PIC clause. The occurrence of code character ‘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.
    • When specifying Alphanumeric data item :- the PIC may contain all Xs or a combination of 9, A and X(except all 9 or all A)
  • Examples:-
COBOL code Description
01  ITEM-CODE   PIC   XXX Data item ‘ITEM-CODE’ is alpha numeric, with size of a 3 bytes.
01  ITEM-CODE   PIC  X(3) Equivalent to PIC XXX thus meaning is same as above
01  NAME   PIC   AAAAAAA Data item ‘NAME’ is of alphabetic type, and can hold 7 characters. Same declaration can also be done using ‘PIC A(7).
01  TOT-AMOUNT PIC   S9999 Data item ‘TOT-AMOUNT’ is of signed (S) numeric data type and size of data item will be 4 bytes. You can store value like -1234, -327 etc. Same declaration can be also done using ‘PIC S9(4)’
01  TOT-AMOUNT PIC  S999V99 Data item ‘TOT-AMOUNT’ is of signed (S) numeric data type with assumed decimal point and size of data item will be 5 bytes. You can store values like -123.11, -324.12 etc. Same declaration can be also done using ‘PIC S9(3)V9(2)’
01  PRICE   PIC  PPP999 Data item ‘PRICE’ is of 3 character in size and there are six digits after decimal point. Thus if data in memory is ‘290’, the value will be considered as ‘.000290’. Same declaration can also be done using ‘PIC P(3)9(3).
01  PRICE    PIC  999PPP Data item ‘PRICE’ is of 3 character in size and there are six digits BEFORE decimal point. Thus if data in memory is ‘290’, the value will be considered as ‘000290.’ Same declaration can also be done using ‘PIC 9(3)P(3).

  • Apart from above mentioned Code Characters, there are few more Code chanracters which are mostly used while priniting/generating Reports. We will learn Editing Code chanracter and De-editing in next section






© copyright mainframebug.com
Privacy Policy