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

Editing Picture clause in Cobol


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

New User


Joined: 08 Oct 2008
Posts: 6
Location: Pune

PostPosted: Thu Oct 16, 2008 12:11 pm
Reply with quote

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

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Oct 16, 2008 1:23 pm
Reply with quote

Hello,

At the top of the page is a link to "IBM Manuals". Among the manuals is the Enterprise COBOL Language Reference. This is from that manual:
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/igy3lr10/5.3.11.9.1?

You will do yourself a very large favor if you become both familiar and comfortable with those manuals. . .
Back to top
View user's profile Send private message
kalyan.v

New User


Joined: 04 Feb 2008
Posts: 65
Location: Hyd

PostPosted: Wed Dec 31, 2008 12:52 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Dec 31, 2008 5:19 pm
Reply with quote

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

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Dec 31, 2008 9:00 pm
Reply with quote

It would be a lot easier if the acceptable format resulted in $123.45-
Back to top
View user's profile Send private message
kalyan.v

New User


Joined: 04 Feb 2008
Posts: 65
Location: Hyd

PostPosted: Fri Jan 02, 2009 11:27 am
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 02, 2009 4:13 pm
Reply with quote

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

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Jan 02, 2009 8:25 pm
Reply with quote

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

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Jan 03, 2009 9:35 am
Reply with quote

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
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 Replace each space in cobol string wi... COBOL Programming 2
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top