cobol difference with Picture having a dash (-) and a having a X

夙愿已清 提交于 2019-12-31 03:20:09

问题


What are the differences between the 2 pictures below?

PIC X(15)

PIC ----,---,---.99.

Is the bottom just another way to represent the top?


回答1:


PIC X(15) Represents 15 characters of virtually any type of data, could be digits, letters or any other symbol (printable or not).

PIC ----,---,---.99 Represents a numeric edited data item capable of holding values in the range +999999999.99 through -999999999.99. This item will display a leading minus sign if the value placed into it is negative, otherwise it will display the number without a leading sign. The displayed number will have comma separators at the indicated positions provided there is at least 1 digit in front of it.

Here are a few samples of the way certain numbers will display:

999999999.99 displays as 999,999,999.99
1234.56      displays as       1,234.56
0            displays as            .00
-1234567.12  displays as  -1,234,567.12
-3           displays as          -3.00

Variables such as this are for display only. Don't even think about doing arithmetic with them! Given the following data declarations:

01 DISP-NBR   PIC ----,---,---.99.
01 NBR        PIC S9(9)V99.

The following MOVE operations are both valid

MOVE 1234.56 TO NBR
MOVE 1234.56 TO DISP-NBR

However,

ADD 1 TO NBR

is perfectly valid but...

ADD 1 TO DISP-NBR

Will give you a compile error. Even though DISP-NBR contains numeric data it is in a display only format. You need to do math using data items that are purely numeric and then MOVE them to display fields for 'pretty printing'.

This table describes all of the PICTURE elements that may be used in COBOL and what they are for.




回答2:


The first one can have any alpha-numeric caracters.

The second one is used to format number. The dash means that if you have a negative number, a dash will be shown beside (at the left) of the number. Only one dash will be displayed. If the number is positive, a space will shown for every dashes.



来源:https://stackoverflow.com/questions/7443524/cobol-difference-with-picture-having-a-dash-and-a-having-a-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!