Module 5: Data Division
SIGN clause
- This section will be easy to understand if you first read section “Basics of Internal Representation of Data in Mainframe” <LINK> and “USAGE clause” <LINK>
- By default a numeric data item defined with ‘S’ in its PICTURE clause stores sign in the zone part of a byte (when the USAGE IS DISPLAY).
- However this may cause some difficulties while reading from the source. For example, a record description of one file contains following field:-
05 SIGNED-FIELD PIC S9(04).
- Now, if a value -1234 is to be read into SIGNED-FIELD, then the file must contain 124M (-4 in EBCDIC is equivalent to ‘M’). Thus, this will not be convenient.
- Similarly if you want to port your data to a different machine, you might want to code the sign as a separate position in storage
- To get rid all such difficulties, COBOL have SIGN clause.
- Using SIGN clause we can specify the position of sign character within the internal representation of data.
- SIGN clause allow us to store the sign separately for the signed numeric data items.
- This can be coded only for numeric data items that contains ‘S’ in PIC clause.
- Basic Syntax:-
SIGN IS {LEADING|TRAILING} [SEPARATE CHARACTER]
- In above syntax,
- SEPARATE phrase specifies that the sign is to be stored separately and not in the zone part.
- TRAILING phrase specifies that the sign is to be stored in trailing position either as separate character or in zone part depending on whether or not the SEPERATE phrase is coded.
- LEADING phrase specifies that the sign is to be stored in leading position as separate character or in zone part depending on whether or not the SEPERATE phrase is coded.
- Default is ‘SING IS TRAILING’ with no separate character, thus sign does not take any space. It is stored along with the last digit
- Let’s see how the data will be stored for all combination of phrases:-