Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can negative values be shown as parenthesis? 3

Status
Not open for further replies.

sp1502

Programmer
Dec 15, 2000
15
US
wondering if in the pic clause there is something I can use to show parenthesis for a numeric value when negative:

for example -123 would be (123)


Thanks in advance
 
AFAIK, you can't in a PIC clause.
You may consider to play with STRING or INSPECT.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
There is no direct way to show parentheses, but consider something as follows:
Code:
01  src-number pic s9(10) value -123.
01  dest-number pic z(10)9-.
Then in the PROCEDURE DIVISION:
Code:
move src-number to dest-number.
if dest-number (12:1) = "-"
    move "(" to dest-number (1:1)
    move ")" to dest-number (12:1)
end-if

Tom Morrison
 
SP1502,

here's a slight variation on Tom's suggestion to avoid spaces between the leading paren and the digits:

Code:
WORKING-STORAGE SECTION.
01 src-number  pic s9(10) value -123.
01 dest-number pic -(10)9B.

PROCEDURE DIVISION.

move src-number to dest-number
if src-number < zero
   inspect dest-number
           replacing all "-" by "("
   move ")" to dest-number
               (length of dest-number:1)
end-if



&quot;Code what you mean,
and mean what you code!
But by all means post your code!&quot;

Razalas
 
Tom,

yes, I've had that request too! Seems no matter what you code they always wanted something slightly different (i.e. "it's exactly what I asked for, not what I wanted").

That's why I wanted to give an alternate solution.


&quot;Code what you mean,
and mean what you code!
But by all means post your code!&quot;

Razalas
 
Razalas,

> yes, I've had that request too! Seems no matter what you code they always wanted something slightly different (i.e. "it's exactly what I asked for, not what I wanted").

Ha! I'm going to print this in 120p on large paper, and hang it in my office for all the consultants to read.

Thanks for putting this in the right words for us [2thumbsup]

Thnx
TonHu
 
thanks all, the bean counter will be happy now!
 
TonHu,

glad you appreciated the thought, but please don't attribute the quote to me when you hang it on the wall (although I wish I could claim it), as I was just passing along a piece of "wisdom" that had been shared with me long ago. Unfortunately I do not recall the exact source. If I can locate the original source, I'll be sure and post it back here.

&quot;Code what you mean,
and mean what you code!
But by all means post your code!&quot;

Razalas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top