Search code examples
cobol

COBOL PICTURE with V and Comma


I am learning some basics with open COBOL, and here is my question about PICTURE:

999V99 VALUE 12.4 displays "012.40"

I would also expect 99,999V99 VALUE 12.4 to produce some reasonable output, but the output is "00,01240" instead.

99,999V99 VALUE 1234.56 also displays "01,23456" and not "01,234.56" as I would expect.

What is wrong? What is the correct mask to obtain "01,234.56" from 1234.56?


Solution

  • The correct mask is 99,999.99. Have a look at the link Gilbert suggested in the comments

    Common mask characters 
    
        9 - 0 -> 9
        Z - 0 -> 9 + space for leading zero's
        V - Assumed decimal place not actually represented
        . - actual decimal place
        , - comma 
    
    So
        Cobol definition           Display value
        ----------------           -------------
        99,999V99 VALUE 1234.56    01,23456 
        99,999.99 VALUE 1234.56    01,234.56 
        ZZ,ZZ9.99 VALUE 1234.56     1,234.56
        --,--9.99 VALUE 1234.56     1,234.56
        --,--9.99 VALUE -1234.56   -1,234.56
        ++,++9.99 VALUE 1234.56    +1,234.56
    

    Once you use characters like Z , . - + / the field is and edited numeric field rather than a numeric field. Some compilers may let you use edited numeric in numeric calculations other will not. edited numeric are for displaying values.

    Numeric fields

    Numeric fields are defined like the following and can be used in numeric calculations

          03 num-1         pic s9(5)v99.
          03 num-2         pic s9(5)v99 comp.
          03 num-3         pic s9(5)v99 comp-3.