View previous topic :: View next topic
|
Author |
Message |
PSS Sankar
New User
Joined: 08 Oct 2008 Posts: 6 Location: Pune
|
|
|
|
Hi Friends,
I Have one variable in cobol declared as
01 var1 pic S9(15)V99 comp-3
I want to declare this variable as displyable with supressing zeros and with $ symbol.
How many Z's I need to give??? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
Back to top |
|
|
kalyan.v
New User
Joined: 04 Feb 2008 Posts: 65 Location: Hyd
|
|
|
|
Hi,
I have a doubt similar to this topic.
I have pic clause like below.
05 RPT-PAYMENT PIC -$$$,$$$,$$$.99.
Code: |
When i move -123.45 to above variable gives : - $123.45
|
I need the output should be like below.
Rpt-payment : -$123.45
What changes i have to do??
Thanks,
Kalyan. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Numeric values are justified to the decimal point, so given the PIC you cannot generate the desired output automatically. You will have to move your number to the variable, then scan the variable using reference modification moving characters to the output field one at a time as required. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
It would be a lot easier if the acceptable format resulted in $123.45- |
|
Back to top |
|
|
kalyan.v
New User
Joined: 04 Feb 2008 Posts: 65 Location: Hyd
|
|
|
|
Hi Terry and Robert.
I need the resulted format should be like -$123.45.
i am using it to generate a report.
Robert, i am not apply this logic one time.So your logic cann't be applicable here,i think.
Please let me know any alternate.
Thanks,
Kalyan |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Numeric editing aligns to the decimal point. If your data field is
Code: |
05 RPT-PAYMENT PIC -$$$,$$$,$$$.99. |
and you move -123.45 to that field, you're moving 7 characters into a 15-character field. You will have 8 spaces in that field, and they will be somewhere on the left of the number due to alignment. If you cannot use reference modification to change the output field, you must learn to live with the result you posted. There is no way in COBOL to dynamically left-justify a numeric edited field based on the size of the value you moved to it. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
As Dick suggested: Check the Language Reference Manual.
As Robert has stated: COBOL picture clause will not get you what you want.
If you insist on placing the negative sign to the left of the result, I'd use
Code: |
01 RPT-PAYMENT PIC $(16).99 |
then use either INSPECT and reference modification or loop through the result planting the sign to the left of the $. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I need the resulted format should be like -$123.45. |
This is not a standard "solution" for this requirement. Who is to receive this output? Who determined the format? The minus sign is most often presented on the right side of the amount as:
Code: |
$123.45
$99.00-
$98.00
$234.88- |
This format provides better overall readability as well as allows the negative amounts to "stand out".
All of the business users i have ever worked with insist on this format (even if some do not want the $ shown). |
|
Back to top |
|
|
|