View previous topic :: View next topic
|
Author |
Message |
lanand_hps
New User
Joined: 05 Dec 2007 Posts: 82 Location: chennai
|
|
|
|
hi,
I have a variable declared as
01 WS-VAR1 PIC -$$$,$$$,$$9.99. (15 characters)
if i move 1.25 to this variable, it is dispayed as
-(9 spaces)$1.25
I want to remove the space between - and $ for all values.
I dont want to have - at the end.
Please comment. |
|
Back to top |
|
|
Harsh Saxena
New User
Joined: 10 Jul 2007 Posts: 2 Location: Pune
|
|
|
|
move the variable WS-VAR1 to a temp variable of same size
Eg : WS-VAR2 pic x(15)
Unstring WS-VAR2 delimited by all spaces into WS-TEMP1, WS-TEMP2.
Now WS-TEMP1 carries all the spaces and WS-TEMP2 carries the actual data.
Move WS-TEMP2 TO WS-FINAL(being WS-
FINAL a destination field). |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
In COBOL, the $ and the - can be floating insertion characters. However, they both cannot be floating insertion characters in the same PICTURE clause. Use PIC $$$$,$$$,$$9.99 and then use reference modification to insert the minus sign where you want it. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If you are willing to show the minus (-) on the right, this will do what you want:
Code: |
01 SOME-MONEY PIC $$,$$$,$$$.99-.
MOVE -1236.88 TO SOME-MONEY.
DISPLAY SOME-MONEY. |
Output:
|
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Dick's example is usually the preferred method of displaying a signed currency amount. Is it a business requirement to "not show the - at the end"? |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
For this you need bit of coding
Code: |
01 RECVAR2 PIC -$$$,$$$,$$9.99.
01 alnum redefines recvar2.
02 sgn pic x.
02 numbr pic x(14).
.
.
.
inspect numbr tallying cnt for leading spaces.
compute strcnt = cnt + 1.
compute strend = 14 - cnt.
display sgn numbr(strcnt:strend).
|
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Working-Storage
Code: |
05 EDIT-MASK PIC -$$$,$$$,$$9.99.
05 WS-SUB-1 PIC S9(4) COMP.
05 LEN-OF-EDIT-MASK PIC S9(4) COMP.
|
Procedure
Code: |
MOVE LENGTH OF EDIT-MASK TO LEN-OF-EDIT-MASK
MOVE -12.34 TO EDIT-MASK
PERFORM VARYING WS-SUB-1
FROM 2
BY 1
UNTIL WS-SUB-1 > LEN-OF-EDIT-MASK
OR EDIT-MASK(WS-SUB-1:1) > SPACE
END-PERFORM
DISPLAY ':' EDIT-MASK ':'
MOVE EDIT-MASK(1:1) TO EDIT-MASK(WS-SUB-1 - 1:1)
DISPLAY ':' EDIT-MASK ':'
MOVE SPACE TO EDIT-MASK(1:1)
DISPLAY ':' EDIT-MASK ':'
|
OUTPUT:
Code: |
:- $12.34:
:- -$12.34:
: -$12.34:
|
|
|
Back to top |
|
|
|