View previous topic :: View next topic
|
Author |
Message |
Soundararajan
New User
Joined: 07 Jan 2007 Posts: 13 Location: INDIA
|
|
|
|
Could anyone suggest how to display the below values in cobol:
-$123.00
-$123456.00
-$67.45
etc
Soundar. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
01 edit-mask pic -$$$$$$$$$9.99. |
|
Back to top |
|
|
Soundararajan
New User
Joined: 07 Jan 2007 Posts: 13 Location: INDIA
|
|
|
|
Hi Dick,
As per the below code
01 edit-mask pic -$$$$$$$$$9.99.
- (negative) is not flolating, $ only floating, say for example i am getting result as
- $12.00
- $1234.00
Is it possible to float both dollar and negative as below
-$12.00
-$1234.00
Thanks in advance,
Soundar. |
|
Back to top |
|
|
raak
Active User
Joined: 23 May 2006 Posts: 166 Location: chennai
|
|
|
|
Quote: |
say for example i am getting result as
- $12.00
- $1234.00
Is it possible to float both dollar and negative as below
-$12.00
-$1234.00 |
What is the difference b/w the two examples u have shown??
If u use the PIC clause as per Dick's suggestion and if u move a negative value to that variable, u definitely will get a negative+dollar in ur output display....
Isn't that what u r asking??? |
|
Back to top |
|
|
Soundararajan
New User
Joined: 07 Jan 2007 Posts: 13 Location: INDIA
|
|
|
|
Hi,
Sorry for the confusing, In that reply I placed spaces, but it wrongly aligned to left
Currently I am getting as follows
-bbbb$12.00
-bb$1234.00
but I need to get as follows
bbbb-$12.00
bb-$1234.00
b-blanks, my present report is showing spaces between - and $, i.e - is in fixed place but $ is floating. But both have to float, is it possible?
Soundar. |
|
Back to top |
|
|
seetharam_mf
New User
Joined: 24 Feb 2005 Posts: 1
|
|
|
|
Hi Soundar,
have you tried of string & un string !!!!!!!! may be this will give you a solution.
Regards
Seetharam |
|
Back to top |
|
|
Gijz
New User
Joined: 27 Nov 2007 Posts: 9 Location: The Netherlands
|
|
|
|
Hi Soundar,
I don't think it's possible solely with a picture string. I would use the following picture string:
01 edit-mask pic B$$$$$$$$$9.99.
And then code:
MOVE input-field TO edit-mask
IF input-field NEGATIVE
INSPECT edit-mask REPLACING FIRST ' $' BY '-$'
END-IF
With STRING it's also possible but i think you would probably need to REVERSE before and after also. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
I don't believe COBOL will provide you an edit mask that will float 2 values. I believe that this is a 'non-standard' way of representing financial amounts.
if you would leave a trailing sign it would work. otherwise, you need to play with the data.
if you have
you should use a variation of the suggestion by Seetharam to unstring and then restring.
Code: |
UNSTRING edit-mask
delimited by all spaces
into sign-field
amount-field
end-unstring
|
length of sign-field = 1
length of amount-field would be:
inspect tallying amount-field for spaces
length of amount-field - tally = number of non-space characters.
your final field would be edited-edit-mask pic x(20).
so, 20 - 1(for the sign) - number-non-space-char = number of spaces
Code: |
STRING field-full-of-spaces(1:number-of-spaces)
delimited by size
sign-field(1:1)
delimited by size
amount-field(1:num-non-space-char)
delimited by size
into edited-edit-mask
end-string
|
|
|
Back to top |
|
|
Soundararajan
New User
Joined: 07 Jan 2007 Posts: 13 Location: INDIA
|
|
|
|
Hi All,
Thanks a lot Dick Brenholtz, Seetharam, Gijz. Finally I got solution using String and Unstring, as per your suggestions.
Thanks and Regards,
Soundar. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
If you can settle for:
$123.45- and $123.45
You can use $$$$$$$$999.99-
Oops, the party's over!!! Hello, Hello!!!! |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Not sure the party is over.
With STRING and UNSTRING, you will get such poor performance that you may want to try something else...
If your CPU usage is too high, consider Gijz solution:
Gijz wrote: |
Hi Soundar,
I don't think it's possible solely with a picture string. I would use the following picture string:
01 edit-mask pic B$$$$$$$$$9.99.
And then code:
MOVE input-field TO edit-mask
IF input-field NEGATIVE
INSPECT edit-mask REPLACING FIRST ' $' BY '-$'
END-IF |
Also, if you're running under CICS, these commands (STRING and UNSTRING) are not recommended at all
(although I cannot remember the place where I saw this). |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
dbzTHEdinosauer wrote: |
if you have
you should use a variation of the suggestion by Seetharam to unstring and then restring.
Code: |
UNSTRING edit-mask
delimited by all spaces
into sign-field
amount-field
end-unstring
|
|
If you adopt this solution, you must prevent the minus sign to stick with the $ sign by adding an extra character.
Otherwise, the UNSTRING won't eat that:
|
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Marso wrote: |
dbzTHEdinosauer wrote: |
if you have
you should use a variation of the suggestion by Seetharam to unstring and then restring.
Code: |
UNSTRING edit-mask
delimited by all spaces
into sign-field
amount-field
end-unstring
|
|
If you adopt this solution, you must prevent the minus sign to stick with the $ sign by adding an extra character.
Otherwise, the UNSTRING won't eat that:
|
What is going to happen when the amount is positive? |
|
Back to top |
|
|
Max Payne
New User
Joined: 13 Dec 2007 Posts: 10 Location: Shanghai
|
|
|
|
Here is another solution:
Code: |
01 WS-AREA.
03 WS-TEST PIC -$$$$9,V99.
03 FILLER REDEFINES WS-TEST.
05 WS-TEST-R PIC X(9).
PROCEDURE DIVISION.
0000-MAIN SECTION.
INSPECT WS-TEST-R REPLACING ALL "," BY ".".
IF WS-TEST-R(1:1) = "-"
MOVE SPACE TO WS-TEST-R(1:1)
INSPECT WS-TEST-R TALLYING WS-IDX FOR LEADING SPACE
MOVE "-" TO WS-TEST-R(WS-IDX:1)
END-IF.
0000-EXIT.
EXIT. |
|
|
Back to top |
|
|
|