Highlighted
Contributor.
Contributor.
2862 views

How wide in bytes is PIC S9(12) -- 12 or 13 bytes ?

Jump to solution

My confusion over this could be causing my bug.  I'll be grately deepful for the correct answer.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: How wide in bytes is PIC S9(12) -- 12 or 13 bytes ?

Jump to solution

Yes, Moto - it's 12.

Cobol has a "length of" operator you can use to find the length of any field - see below. For group items, the Editor tooltips also include the length of the item - though unfortunately not for elementary items like pic s9(12).  

      working-storage section.

      01   a    pic s9(12).

      procedure division.

          display length a

View solution in original post

0 Likes
4 Replies
Highlighted
Absent Member.
Absent Member.

RE: How wide in bytes is PIC S9(12) -- 12 or 13 bytes ?

Jump to solution

It would be 12 as S takes up no data. Although when displayed, the + or - will be trailing. For example S9(3) would display 123- given that the value you declare is negative. Hope this helps. I myself am just learning COBOL myself. If someone could just double check me.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: How wide in bytes is PIC S9(12) -- 12 or 13 bytes ?

Jump to solution

Yes, Moto - it's 12.

Cobol has a "length of" operator you can use to find the length of any field - see below. For group items, the Editor tooltips also include the length of the item - though unfortunately not for elementary items like pic s9(12).  

      working-storage section.

      01   a    pic s9(12).

      procedure division.

          display length a

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: How wide in bytes is PIC S9(12) -- 12 or 13 bytes ?

Jump to solution

For more information as to how the sign character is actually stoired in numeric display type fields, please see the documentation in the COBOL Language Reference guide here:

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: How wide in bytes is PIC S9(12) -- 12 or 13 bytes ?

Jump to solution

Yes, as previously posted, the size is 12.  Another way to confirm this is with a datamap in the listing, that is, when the LIST() and DATAMAP directives are specified for the compilation.  Here's the results for some numbers without and with the separate option for the sign:

    8 working-storage section.

    9 01 mynumber-01a      pic s9(12).

   10 01 mynumber-01b      pic s9(12) trailing.

   11 01 mynumber-01c      pic s9(12) leading.

   12 01 mynumber-01d      pic s9(12) trailing separate.

   13 01 mynumber-01e      pic s9(12) leading separate.

   14

   15 procedure division.

   16 000-start.

   17

   18 end program mynumber01.

*

* Program-Id : MYNUMBER01

* Line   Data Name                       Address    Size      Attributes

* 000009 MYNUMBER-01A. . . . . . . . . . 0000000080 00000012  WS E    Display

* 000010 MYNUMBER-01B. . . . . . . . . . 0000000096 00000012  WS E    Display

* 000011 MYNUMBER-01C. . . . . . . . . . 0000000112 00000012  WS E    Display

* 000012 MYNUMBER-01D. . . . . . . . . . 0000000128 00000013  WS E    Display

* 000013 MYNUMBER-01E. . . . . . . . . . 0000000144 00000013  WS E    Display

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.