Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to dipslay floating -$ in cobol?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to dipslay floating -$ in cobol?
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    Post subject:
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    Post subject:
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    Post subject: Reply to: How to dipslay floating -$ in cobol?
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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: 1224
Location: Israel

PostPosted: Fri Jan 04, 2008 3:27 am    Post subject:
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: 1224
Location: Israel

PostPosted: Fri Jan 04, 2008 3:37 am    Post subject:
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    Post subject:
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    Post subject: Another solution
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us