IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to dipslay floating -$ in cobol?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Soundararajan

New User


Joined: 07 Jan 2007
Posts: 13
Location: INDIA

PostPosted: Wed Jan 02, 2008 7:54 pm
Reply with quote

Could anyone suggest how to display the below values in cobol:

-$123.00
-$123456.00
-$67.45

etc

Soundar.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jan 02, 2008 9:37 pm
Reply with quote

01 edit-mask pic -$$$$$$$$$9.99.
Back to top
View user's profile Send private message
Soundararajan

New User


Joined: 07 Jan 2007
Posts: 13
Location: INDIA

PostPosted: Wed Jan 02, 2008 9:49 pm
Reply with quote

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
View user's profile Send private message
raak

Active User


Joined: 23 May 2006
Posts: 166
Location: chennai

PostPosted: Thu Jan 03, 2008 3:02 pm
Reply with quote

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
View user's profile Send private message
Soundararajan

New User


Joined: 07 Jan 2007
Posts: 13
Location: INDIA

PostPosted: Thu Jan 03, 2008 3:23 pm
Reply with quote

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
View user's profile Send private message
seetharam_mf

New User


Joined: 24 Feb 2005
Posts: 1

PostPosted: Thu Jan 03, 2008 4:45 pm
Reply with quote

Hi Soundar,

have you tried of string & un string !!!!!!!! may be this will give you a solution.

Regards
Seetharam
Back to top
View user's profile Send private message
Gijz

New User


Joined: 27 Nov 2007
Posts: 9
Location: The Netherlands

PostPosted: Thu Jan 03, 2008 7:06 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jan 03, 2008 7:37 pm
Reply with quote

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
Code:

-    $99.99

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
View user's profile Send private message
Soundararajan

New User


Joined: 07 Jan 2007
Posts: 13
Location: INDIA

PostPosted: Thu Jan 03, 2008 8:05 pm
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Jan 04, 2008 2:49 am
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Fri Jan 04, 2008 3:27 am
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Fri Jan 04, 2008 3:37 am
Reply with quote

dbzTHEdinosauer wrote:
if you have
Code:
-    $99.99

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:
Code:
-$999999.99
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Jan 04, 2008 5:23 am
Reply with quote

Marso wrote:
dbzTHEdinosauer wrote:
if you have
Code:
-    $99.99

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:
Code:
-$999999.99


What is going to happen when the amount is positive?
Back to top
View user's profile Send private message
Max Payne

New User


Joined: 13 Dec 2007
Posts: 10
Location: Shanghai

PostPosted: Fri Jan 04, 2008 7:12 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL sorting, with input GDG base COBOL Programming 7
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 0
No new posts Replacing FILLER with FILLER<SeqNu... DFSORT/ICETOOL 2
No new posts Compile Sp Cobol base COBOL Programming 1
No new posts SQLCODE=-311 in Cobol SP-DB2. COBOL Programming 2
Search our Forums:

Back to Top