From: christian.posta on 4 Jun 2010 18:27 all, I am new to cobol, and i have a question about a field definition i came across. I see a field in one of the copybook documents at my day job that has a definition as the following: 000900 05 CONTROL-CNT PIC -9(03). Can someone help me understand why there is a minus sign ('-') before the nine? Aren't signed values represented with an 'S'? Thanks, Christian
From: Pete Dashwood on 4 Jun 2010 19:07 christian.posta wrote: > all, > > I am new to cobol, and i have a question about a field definition i > came across. > I see a field in one of the copybook documents at my day job that has > a definition as the following: > > 000900 05 CONTROL-CNT PIC -9(03). > > Can someone help me understand why there is a minus sign ('-') before > the nine? Aren't signed values represented with an 'S'? Yes, they are...INTERNALLY. This is an edited field, intended for displaying or printing. You can think of this as an edited field with a floating minus, except that the minus hasn't been floated (there is only one) :-) The effect is as follows: 1. move a value of +123 to the field; result = 123 2. move a value of -123 to the field; result = -123 3. move a value of +23 to the field; result = 023 4. move a value of -23 to the field; result = -023 The minus appears ONLY when the field is negative and it doesn't "float" if there are less than 3 digits in the result. (Instead, zeros are propagated, just as we might expect from a picture of 999. Note that, had the field been defined with a float, thus: ---9, the results from above would be: 1. move a value of +123 to the field; result = 123 2. move a value of -123 to the field; result = -123 3. move a value of +23 to the field; result = 23 4. move a value of -23 to the field; result = -23 The sign "floats" to be adjacent to the first digit in the result. Replacing the floating minus with a floating plus, thus: +++9 1. move a value of +123 to the field; result = +123 2. move a value of -123 to the field; result = -123 3. move a value of +23 to the field; result = +23 4. move a value of -23 to the field; result = -23 A sign will ALWAYS be produced. With minus, the sign is only produced if the field is negative. The huge diversity of editing provided by the COBOL PICTURE clause is worth a little investigation. Read the section in your docs about pictures. There are usually plenty of examples. HTH, Pete. -- "I used to write COBOL...now I can do anything."
From: HeyBub on 5 Jun 2010 14:12 christian.posta wrote: > all, > > I am new to cobol, and i have a question about a field definition i > came across. > I see a field in one of the copybook documents at my day job that has > a definition as the following: > > 000900 05 CONTROL-CNT PIC -9(03). > > Can someone help me understand why there is a minus sign ('-') before > the nine? Aren't signed values represented with an 'S'? > > Thanks, > Christian To expand on what Pete said: Numbers are represented internally in many different formats. As text-type number, as binary numbers, as floating point numbers, and so on, with varying levels of precision (usually up to 18 digits). The question becomes "How do I show these numbers so that a human can understand them?" Enter "edited" fields (PICs). Edited fields contain all sorts of visual cues for us limited humans: plus and minus signs, commas, currency symbols (like "$"), "CR/DB", protected fields ("****1.23"), and the like. What you have here is an edited field instructing the program to place a minus sign in a certain column if the datum is negative. If this doesn't blow your mind, be aware that some (limited) arithemetic operations can be performed on these edited fields! (i.e., "ADD 1 TO CONTROL-CNT"), depending on the compiler. You can even print unedited fields. Sometimes they make sense (i.e., "123") and sometimes they don't ("j23") - at least not to the novice.
From: Bill Klein on 5 Jun 2010 14:38 Another way to look at this is: "S" is to "-" (or "+") as "V" is to "." (or "," if "decimal point is comma" is specified) Understanding both the syntax and usage of numeric vs numeric-edited fields is very important in many (most?) COBOL business applications. "HeyBub" <heybub(a)NOSPAMgmail.com> wrote in message news:RbGdndle4ujjDpfRnZ2dnUVZ_s6dnZ2d(a)earthlink.com... > christian.posta wrote: >> all, >> >> I am new to cobol, and i have a question about a field definition i >> came across. >> I see a field in one of the copybook documents at my day job that has >> a definition as the following: >> >> 000900 05 CONTROL-CNT PIC -9(03). >> >> Can someone help me understand why there is a minus sign ('-') before >> the nine? Aren't signed values represented with an 'S'? >> >> Thanks, >> Christian > > To expand on what Pete said: > > Numbers are represented internally in many different formats. As text-type > number, as binary numbers, as floating point numbers, and so on, with > varying levels of precision (usually up to 18 digits). > > The question becomes "How do I show these numbers so that a human can > understand them?" > > Enter "edited" fields (PICs). > > Edited fields contain all sorts of visual cues for us limited humans: plus > and minus signs, commas, currency symbols (like "$"), "CR/DB", protected > fields ("****1.23"), and the like. > > What you have here is an edited field instructing the program to place a > minus sign in a certain column if the datum is negative. > > If this doesn't blow your mind, be aware that some (limited) arithemetic > operations can be performed on these edited fields! (i.e., "ADD 1 TO > CONTROL-CNT"), depending on the compiler. > > You can even print unedited fields. Sometimes they make sense (i.e., > "123") and sometimes they don't ("j23") - at least not to the novice. >
|
Pages: 1 Prev: I am back (I think) Next: Functional Programming book review |